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

fullscreenkeyboard shortcutsosx lion

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 (CmdCtrlF). I want to disable the ESC shortcut. I've been Googling, but cannot find any answers.

Best Answer

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.
Related Question