Don't exit full screen when pressing escape in apps like Safari on Lion

48

8

In OS X Lion, pressing the ESC key exits full screen mode. Unfortunately, and especially when using Safari, ESC is used for other functions, such as in Javascript keystroke event handling. I don't want Lion to exit full screen mode when pressing escape, but I can't find a place to disable that functionality.

I already know the keyboard shortcut to Enter/exit full screen mode (Cmd-Ctrl-F). I want to disable the ESC shortcut. I've been Googling, but cannot find any answers.

Fadi

Posted 2011-07-27T20:40:23.700

Reputation: 581

I found ctrl+esc works gmail's hangouts windows close. It may work for other websites too. – Aykut Aras – 2014-10-20T18:21:24.177

2Pressing Esc where it has a different effect (e.g. aborting page loading) does not exit full screen. – Daniel Beck – 2011-08-02T15:55:40.800

@Daniel: But that doesn't necessarily apply to any other functions. Is this actually a wide spread OS X Lion problem? Why are there so few people that are actually experiencing this? – Tamara Wijsman – 2011-08-29T15:00:23.660

@Tom Please explain; what other functions? – Daniel Beck – 2011-08-29T15:00:55.033

@DanielBeck: It's listed in the question: ESC is used for other functions as well. – Tamara Wijsman – 2011-08-29T15:01:18.963

1@Tom Such as? The user doesn't say, and neither do you. I could imagine all those functions overriding the full screen mode shortcut when used by e.g. consuming the event, but without more examples, I can't say for sure. – Daniel Beck – 2011-08-29T15:24:23.110

@DanielBeck: The users says "other functions", and that's enough. – Tamara Wijsman – 2011-08-29T15:25:55.463

I, too, am curious what other functions are being trampled on here. And I will say that Full Screen is a new feature, and as with any new feature, there are going to be usability issues. You should file this as a bug with Apple (http://bugreport.apple.com), as I'm not sure its the intended behavior.

– peelman – 2011-09-07T19:04:38.117

The user so far failed to provide any example where Esc would produce any other effect and exits full screen anyway. The "examples" in @AJACs' answer don't work either, instead showing a sensible behavior in all cases. Down-voting. – Daniel Beck – 2011-09-18T14:50:34.130

@TomWijsman Interesting. All examples brought forth so far does not work. Even though there are already two non-answers with "examples" where Escape behavior are alleged to be broken, none of them actually behave as described. There's a reason I asked for concrete examples right from the start: There just aren't any. – Daniel Beck – 2011-09-18T14:55:00.367

10

Accidentally hit enter There are many web pages where ESC is used to close a modal window, for example: http://www.ericmmartin.com/projects/simplemodal-demos/ Click Demo on the page to display a modal window. Press ESC to close the modal. Safari is aware that there is a modal window, and doesn't exit full screen. Press ESC again and Safari exits full-screen mode.

Often I press ESC several times to ensure something gets closed. I don't want Safari to exit full-screen mode when that happens. There is already a key command to exit full-screen. ESC shouldn't be used.

– Fadi – 2011-09-26T21:44:51.133

@Daniel Beck: You're ignoring the scenario where pressing escape causes windows to leave full screen mode if you tap it accidentally. There's no reason for that. Why are you so violently opposed to this question and a request for a solution? – dpk – 2011-11-03T14:56:29.657

Scenario: A web page uses Javascript to monitor the escape key, used to close divs and the like. Tapping escape leads to Javascript processing the event AND Lion's misbehavior. Is that sufficient? It is a UI mistake to trigger leaving full screen mode on escape. – dpk – 2011-11-03T14:58:35.443

1@dpk Link to a demo web page, please. Since none of the examples mentioned so far have this issue when I tested them, I don't believe that without steps to reproduce the issue. In fact, Fadi's example above contradicts your comment. – Daniel Beck – 2011-11-03T16:00:21.233

@Daniel Beck: Here ya go: http://dpk.net/demonstration-of-escape-problem-in-lion.html . Full screen Safari and then go to that page, click the button, and hit escape to clear the fake dialog. Sorry for the 'tude earlier, bad day.

– dpk – 2011-11-05T01:10:02.737

@dpk Hmmm... OK. You could use .keydown() and return false;, then it'd be no issue. But this is finally a working example that doesn't play well with fullscreen Esc, at least. – Daniel Beck – 2011-11-05T07:08:21.580

I've edited the post to add this example. Hopefully we'll/someone'll find a way to work around Apple's error here. – dpk – 2011-11-05T16:16:04.280

@dpk I guess I just admitted defeat :-)

– Daniel Beck – 2011-11-17T19:23:05.810

Major problem for terminal emulators. It is very common to use the escape key in a terminal session to go back to the previous host screen or exit what you are doing. Apple needs to provide a way to disable escape so other programs can use it. – None – 2011-09-18T14:12:46.867

@Rich As is obvious from Terminal's behavior, programs can disable Escape for leaving full screen. iTerm2 also does not close full screen with Escape. What, in detail, are you referring to? – Daniel Beck – 2011-09-18T14:53:10.850

Answers

6

For web browsers, and specifically for use of sites with behavior that enables or requires use of the Escape key while not preventing closing of full screen (like Stack Exchange sites), you can use the following user script:

// ==UserScript==
// @name           Keep Full Screen
// @namespace     http://superuser.com/q/315949
// @description    Prevents Escape key from leaving full screen.
// @include      http://*
// ==/UserScript==
document.onkeydown = function (evt) {
    if (evt.keyCode == 27) evt.preventDefault();
}

To run this in browsers, use any user script engine for your browser.

  • For Safari 5, you can use the Safari extension NinjaKit (on GitHub). This is what I use.
  • For Chrome, you can use its NinjaKit variant.
  • For any other Safari on OS X, you can use the SIMBL plug-in GreaseKit. Not sure how up to date it is though.

Daniel Beck

Posted 2011-07-27T20:40:23.700

Reputation: 98 421

2Yeah this doesn't work for me, I'm in Yosemite Beta 5 with Safari 8.0 (10600.1.25) at the time of writing, and using NinjaKit in Safari as the userscripts engine. Escape key keeps on breaking full screen and for me it's happening when I'm in address bar and press Esc while in it. (it has a few useful functions when editing text in it...) I'm assuming GreaseKit no longer works given it's dated to 2009 and a quick google seems to indicate it doesn't work anymore. Any ideas? So frustrating, no wonder Chrome is the go-to primary browser, even on Apple's own operating system... – None – 2014-10-08T07:29:25.713

@foregon I'd expect page event handling to have absolutely no effect while you're in the address bar. – Daniel Beck – 2014-10-08T12:18:12.537

works with tampermonkey, edited the script/response to support https:// as well. – Toni – 2018-07-02T16:47:17.263

for convenience's sake, I uploaded this to userscripts: http://userscripts.org/scripts/review/178642

– coffeejunk – 2013-09-26T12:18:44.873

Any experience installing this on Safari for Mavericks? – Holene – 2014-06-10T09:12:14.940

3

Most situations native to OS X accept both Escape and Cmd-. to abort, e.g. file dialogs, Safari loading, dragging elements around, etc.

Notably absent from that list is, of course, leaving full screen mode.


So you could just learn to press Cmd-. instead of Escape to avoid this situation altogether. Or you can teach your computer to do it for you: An at least somewhat sane solution is to use e.g. Butler's Keystrokes item to map Escape to Cmd-.:

  • Open Butler's configuration page
  • Select any container, e.g. Hidden, click + » Smart Item » Keystrokes
  • On the Keys tab, press Cmd-. to use this as the resulting keystroke when activating this item
  • On the Triggers tab, select the Hot Key input field and press Escape. Ignore the warning that basically states you're insane.
  • Remember to add e.g. Terminal to the exceptions list — it totally ignores Escape for leaving full screen, but pressing Ctrl-. translates to Ctrl-C!

In some situations, things will misbehave. Remapping the key to what's usually an equivalent keyboard shortcut is a sledgehammer solution. Quick Look, for example, doesn't handle Cmd-. (and therefore the remapped Escape for closing file previews); renaming files in Finder cannot be aborted anymore using Escape, nor selections e.g. in Finder be cleared.

In limited testing, I found no situation where pressing Cmd-. actually leads to undesirable actions being performed, but be aware that these probably also exist.

Daniel Beck

Posted 2011-07-27T20:40:23.700

Reputation: 98 421

⌘ + . exits full screen mode for me in Opera, so this is a no go :( – Andy E – 2017-03-01T10:22:21.447

Of course, you could completely ignore all Escape keypresses like this, but that'll lose a good bit of functionality... – Daniel Beck – 2011-11-23T11:34:56.927

2

I didn't find an answer for macOs Sierra and higher. So that's how i solved this issue.

As it has been already suggested i've remapped ESC to ⌥ + ESC. It does the job and even some other functions assigned to the key works. You will be able to exit fullscreen videos on some sites, but it will not abort page loading.

First you need to install Karabiner-elements to be able to remap keys

  1. Install brew /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
  2. Install cask brew tap caskroom/cask
  3. Install karabiner-elements brew cask install karabiner-elements

I've created custom "Complex modification" specifically for this problem. To install this modification you have to:

  1. Open karabiner-elements and go to "Complex modifications" tab
  2. Click "Add rule" button, then "Import more rules from the Internet"
  3. Import modification "Don't exit fullscreen when pressing ESC in Safari"

S3RK

Posted 2011-07-27T20:40:23.700

Reputation: 21

2

Your possible options include:

  1. Set alternative shortcuts for the other functions, because ESC is reserved by the OS and Browser.

  2. Adjust the source / assembler machine code to rebind the ESC key of the OS and Browser.

  3. File the bug/feature request against application developer (i.e. Google spreadsheets) to consume ESC event instead of letting it through.

  4. File a bug with Apple, because the applications were here first, and Apple re-purposed the key without cause.

Tamara Wijsman

Posted 2011-07-27T20:40:23.700

Reputation: 54 163

3#1 I can get behind. #2 is almost tongue-in-cheek to the point of laughter. – peelman – 2011-09-07T19:05:50.127

Well, your mileage may vary. – Tamara Wijsman – 2011-09-07T23:30:31.910

Functions using Escape are not usually available from the menu bar, and Escape does not trigger menu items as is obvious from the missing "flash" highlighting the menu bar item containing the triggered item. – Daniel Beck – 2011-09-18T14:50:00.450

#4 File a bug with Apple, because the applications were here first, and Apple re-purposed the key without cause. – dpk – 2011-11-05T16:12:36.453

2

Try OptionEsc, which worked for me.

Michael

Posted 2011-07-27T20:40:23.700

Reputation: 21

Awesome, this works well in Safari 13. Thanks for sharing! – LinusGeffarth – 2019-12-30T11:26:30.963

1It doesn't trigger actions associated with the Escape key either, e.g. aborting Safari web page loading. – Daniel Beck – 2013-01-03T15:20:09.817

1

This is the same as the @aditya-srinivasan answer targeting Opera

<?xml version="1.0"?>
<root>
    <item>
  <!-- ============================================================ -->
  <appdef>
    <appname>OPERA</appname>
    <equal>com.operasoftware.Opera</equal>
  </appdef>

    <name>Escape to Option + Escape on Opera</name>
    <identifier>private.Opera_escape</identifier> 
    <only>OPERA</only>
    <autogen>__KeyToKey__ KeyCode::ESCAPE, KeyCode::ESCAPE, ModifierFlag::OPTION_L</autogen>
  </item>
  <!-- ============================================================ -->
</root>

See @aditya-srinivasan answers on the downloading https://pqrs.org/osx/karabiner/index.html.en

ctrl-alt-dileep

Posted 2011-07-27T20:40:23.700

Reputation: 111

1

Just to flesh out the description a bit more.

ESC is used to cancel a drag, esc is used to cancel a dialog box, esc is used during a drag to cancel a move/copy, esc is used in terminal in VI to cancel an editing command

So, there are numerous uses. It is a weird oddity that Apple has this cancel full screen mode when that is possible by ctrl-cmd-F and the upper right icon.

This seems to be on an app by app basis Mail and Safari and other iLife items will exit full screen. iTunes stays full screen.

Reeder ignores the esc for the purpose of Full window control, and does other appropriate things for the program. Evernote does not even have a cmd-F or ctrl-cmd-F for window control, its the icon and the esc key.

You can't seem to map esc by itself to some non-harmful nonsense action in the keyboard control panel.

AJACs

Posted 2011-07-27T20:40:23.700

Reputation: 11

1In Safari, mapping the Escape key to a benign function doesn't seem to be a solution. Regardless of the action, it will still drop out of Full Screen. – peelman – 2011-09-07T19:02:58.710

And again, pressing Escape to cancel dialogs does not exit full screen. – Daniel Beck – 2011-09-18T14:38:37.080

Pressing Escape in Terminal does not exit full screen. – Daniel Beck – 2011-09-18T14:39:11.617

Using Escape to cancel a drag does not exit full screen. Have you even tried it before posting these claims? – Daniel Beck – 2011-09-18T14:39:55.423

Using Escape in Reeder to e.g. return from an article web page to the RSS item does not exit full screen. If Escape is not used for such an action, it exits full screen. *As in ALL OTHER PROGRAMS.* – Daniel Beck – 2011-09-18T14:42:28.930

1

It looks like you're using JQuery. In that case:

Listen for keydown events (keypress and keyup won't work) on the document with keyCode 27, and when the event fires call e.preventDefault().

$(document).bind('keydown', function(e) {

    if (e.keyCode === 27) { // Escape key
        e.preventDefault();
        // Other code goes here    
    }

});

Evan Sharp

Posted 2011-07-27T20:40:23.700

Reputation: 111

Related request on MSO, works without jQuery. – Daniel Beck – 2012-01-23T20:18:14.930

0

EASY, found it! KeyboardMaestro with 2 actions

When pressing "ESC" Simulate pressing (instead): - "CMD+." - THEN also "ALT+ESC"

You need both, because some app react only to one order or the other (sometimes to none, then nothing possible) -- >this way most apps will do like an "ESC" in their context, but you will never get exited from the full screen mode

user2755736

Posted 2011-07-27T20:40:23.700

Reputation: 1

0

I decided to have esc routed to alt/option + esc. For the most part, this lets me get out of YouTube vids, and if you have a Squarespace account, it lets you login without getting out of full screen.

  • Download and install Karabiner.
  • Go to the right most "Misc & Uninstall" tab.
  • Click on the button that says "Open private.xml".
  • Download the private.xml file from here
  • Replace the original "private.xml" file in Finder with the downloaded file. Voila!

Aditya Srinivasan

Posted 2011-07-27T20:40:23.700

Reputation: 3

0

Use BetterTouchTool or KeyboardMaestro or something similar to remap Esc to ⌥ + Esc.

user2664470

Posted 2011-07-27T20:40:23.700

Reputation: 101

0

After some desperate search for the solution, I consign Safari to a separate virtual desktop with Mission control. This mitigates the ESC problem and is by far the best approximation to a fullscreen Safari window.

Bonus space if you hide the Dock.

Fish Monitor

Posted 2011-07-27T20:40:23.700

Reputation: 355