Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.

Here is a simple demonstration of the problem, using a simple jQuery Javascript one might find in the wild:

http://dpk.net/demonstration-of-escape-problem-in-lion.html

share|improve this question
2  
Pressing Esc where it has a different effect (e.g. aborting page loading) does not exit full screen. –  Daniel Beck Aug 2 '11 at 15:55
    
@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? –  Tom Wijsman Aug 29 '11 at 15:00
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 Aug 29 '11 at 15:24
3  
Accidentally hit enter There are many web pages where ESC is used to close a modal window, for example: 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 Sep 26 '11 at 21:44
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 Nov 3 '11 at 16:00
show 14 more comments

6 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.
share|improve this answer
    
for convenience's sake, I uploaded this to userscripts: userscripts.org/scripts/review/178642 –  coffeejunk Sep 26 '13 at 12:18
    
Any experience installing this on Safari for Mavericks? –  Holene Jun 10 at 9:12
add comment

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.

share|improve this answer
1  
#1 I can get behind. #2 is almost tongue-in-cheek to the point of laughter. –  peelman Sep 7 '11 at 19:05
    
Well, your mileage may vary. –  Tom Wijsman Sep 7 '11 at 23:30
    
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 Sep 18 '11 at 14:50
    
#4 File a bug with Apple, because the applications were here first, and Apple re-purposed the key without cause. –  dpk Nov 5 '11 at 16:12
add comment

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.

share|improve this answer
1  
In 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 Sep 7 '11 at 19:02
    
And again, pressing Escape to cancel dialogs does not exit full screen. –  Daniel Beck Sep 18 '11 at 14:38
    
Pressing Escape in Terminal does not exit full screen. –  Daniel Beck Sep 18 '11 at 14:39
    
Using Escape to cancel a drag does not exit full screen. Have you even tried it before posting these claims? –  Daniel Beck Sep 18 '11 at 14:39
    
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 Sep 18 '11 at 14:42
add comment

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    
    }

});
share|improve this answer
    
Related request on MSO, works without jQuery. –  Daniel Beck Jan 23 '12 at 20:18
add comment

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.

share|improve this answer
    
Of course, you could completely ignore all Escape keypresses like this, but that'll lose a good bit of functionality... –  Daniel Beck Nov 23 '11 at 11:34
add comment

Try OptionEsc, which worked for me.

share|improve this answer
1  
It doesn't trigger actions associated with the Escape key either, e.g. aborting Safari web page loading. –  Daniel Beck Jan 3 '13 at 15:20
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.