68

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.

21
  • 2
    Pressing Esc where it has a different effect (e.g. aborting page loading) does not exit full screen.
    – Daniel Beck
    Aug 2, 2011 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? Aug 29, 2011 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, 2011 at 15:24
  • 13
    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, 2011 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, 2011 at 16:00

13 Answers 13

12

Try OptionEsc, which worked for me.

4
  • 1
    It doesn't trigger actions associated with the Escape key either, e.g. aborting Safari web page loading.
    – Daniel Beck
    Jan 3, 2013 at 15:20
  • Awesome, this works well in Safari 13. Thanks for sharing! Dec 30, 2019 at 11:26
  • This is kinda hard to get the hang of but seems like the only solution that works well in all situations
    – TimNode
    Mar 5, 2021 at 17:12
  • @DanielBeck There're usually other key bindings for those actions, e.g. aborting the loading of a page can be done by pressing cmd + . and the tab key can be used to deactivate the address bar.
    – Xavier
    Feb 26, 2023 at 12:44
11

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"
8

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.
5
  • for convenience's sake, I uploaded this to userscripts: userscripts.org/scripts/review/178642
    – coffeejunk
    Sep 26, 2013 at 12:18
  • Any experience installing this on Safari for Mavericks?
    – Holene
    Jun 10, 2014 at 9:12
  • 2
    Yeah 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...
    – user78017
    Oct 8, 2014 at 7:29
  • @foregon I'd expect page event handling to have absolutely no effect while you're in the address bar.
    – Daniel Beck
    Oct 8, 2014 at 12:18
  • works with tampermonkey, edited the script/response to support https:// as well.
    – Toni
    Jul 2, 2018 at 16:47
4

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.

2
  • Of course, you could completely ignore all Escape keypresses like this, but that'll lose a good bit of functionality...
    – Daniel Beck
    Nov 23, 2011 at 11:34
  • ⌘ + . exits full screen mode for me in Opera, so this is a no go :(
    – Andy E
    Mar 1, 2017 at 10:22
3

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

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.

4
  • 3
    #1 I can get behind. #2 is almost tongue-in-cheek to the point of laughter.
    – peelman
    Sep 7, 2011 at 19:05
  • Well, your mileage may vary. Sep 7, 2011 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, 2011 at 14:50
  • #4 File a bug with Apple, because the applications were here first, and Apple re-purposed the key without cause. Nov 5, 2011 at 16:12
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.

5
  • 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, 2011 at 19:02
  • And again, pressing Escape to cancel dialogs does not exit full screen.
    – Daniel Beck
    Sep 18, 2011 at 14:38
  • Pressing Escape in Terminal does not exit full screen.
    – Daniel Beck
    Sep 18, 2011 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, 2011 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, 2011 at 14:42
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    
    }

});
1
1

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!
0
1

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

1

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.

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

0

Use the combination ⌘+esc (cmd+esc) (⌥+esc (opt+esc) also works)

This allows the webpage to "esc" whatever is selected (ie: the editing of cells in Google Sheets) without affecting the browser.

Works on Ventura 13.2 with Safari 16.3.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .