512

How do I make Caps Lock work like Esc in Mac OS X?

chicks
  • 2,393
  • 3
  • 24
  • 40
indentation
  • 9,895
  • 6
  • 21
  • 14
  • 43
    This seems like a standard task for a programmer who uses vim; hence my vote to re-open – Jeromy Anglim Sep 09 '13 at 03:03
  • 4
    An alternative is to map Caps Lock to Control (System Preferences > Keyboard > Modifier Keys) and execute the escape sequence `Ctrl + [` for `esc`. Useful for Vim. – myconode Jul 27 '15 at 17:51
  • 2
    Native solution that works in macOS Sierra: http://stackoverflow.com/a/41004544/1940276 – Kevin Roth Dec 06 '16 at 20:51
  • 1
    Native solution that works in macOS Sierra is the second best answer here (from @rkusa) – Marián Černý May 15 '17 at 09:53
  • Related question on Ask Different: [How can I remap Caps lock to both Escape and Control?](https://apple.stackexchange.com/questions/132564/how-can-i-remap-caps-lock-to-both-escape-and-control) – joeytwiddle Sep 05 '17 at 01:54
  • I don't quite understand this. If you map esc to caps lock, then how do you enable/disable caps lock if you actually want to type in something all uppercase? And if you're using caps lock for esc, is the caps lock light on until you hit escape a second time? This seems rather kludgy. – Jim Jul 13 '18 at 02:06
  • @Jim In almost 40 years I have never used Caps Lock other than by mistake, and only rarely needed long sequences of uppercase for other purposes than obnoxious humor. The light on the Caps Lock key does not light up if you remap it. – tripleee Feb 20 '19 at 08:32

15 Answers15

416

Edit: As described in this answer, newer versions of MacOS now have native support for rebinding Caps Lock to Escape. Thus it is no longer necessary to install third-party software to achieve this.


Here's my attempt at a comprehensive, visual walk-through answer (with links) of how to achieve this using Seil (formerly known as PCKeyboardHack).

  1. First, go into the System Preferences, choose Keyboard, then the Keyboard Tab (first tab), and click Modifier Keys:

Step 1

In the popup dialog set Caps Lock Key to No Action:

choose no action

2) Now, click here to download Seil and install it:

3) After the installation you will have a new Application installed ( Mountain Lion and newer ) and if you are on an older OS you may have to check for a new System Preferences pane:

open seil or the preference pane

4) Check the box that says "Change Caps Lock" and enter "53" as the code for the escape key:

set the keyboard code

And you're done! If it doesn't work immediately, you may need to restart your machine.

Impressed? Want More Control?

You may also want to check out KeyRemap4MacBook which is actually the flagship keyboard remapping tool from pqrs.org - it's also free.

If you like these tools you can make a donation. I have no affiliation with them but I've been using these tools for a long time and have to say the guys over there have been doing an excellent job maintaining these, adding features and fixing bugs.

Here's a screenshot to show a few of the (hundreds of) pre-selectable options:

Picture 1.png

PQRS also has a great utility called NoEjectDelay that you can use in combination with KeyRemap4MacBook for reprogramming the Eject key. After a little tweaking I have mine set to toggle the AirPort Wifi.

These utilities offer unlimited flexibility when remapping the Mac keyboard. Have fun!

Cam Jackson
  • 11,860
  • 8
  • 45
  • 78
cwd
  • 53,018
  • 53
  • 161
  • 198
  • 3
    I'd like to clarify that I've been using PCKeyboardHack alone _without_ KeyRemap4Macbook for almost 2 years to do exactly this. – rossipedia Dec 09 '11 at 04:31
  • 14
    Note that if you use an external keyboard, you should repeat step one (i.e., caps lock = no action) for each keyboard. I failed to do this step for my external keyboard, and as a result caps lock did not respond to very quick key presses due to accidental caps lock protection. http://superuser.com/questions/317900/eliminate-macbook-capslock-delay – Jeromy Anglim Oct 23 '12 at 02:11
  • 1
    good point @JeromyAnglim. Previously a PC user, I was at first surprised by this behavior, but then delighted. it is quite nice that one is able to remap different keyboards of the same machine differently! wow! :) – cwd Oct 23 '12 at 04:12
  • @cwd I believe Unix architecture was better designed to be interacted with by multiple users from the start, especially compared to old incarnations of Windows. – Kache Mar 12 '13 at 23:29
  • 12
    Great tutorial. I mapped Caps Lock to Esc for about a year. It was wildly efficient. One day, however, I was pairing with a senior developer. I told him I used Vim as my primary editor. Me too, he said. He opened his machine and we started working. When my turn came to edit the code, I fumbled and tripped all over because his Caps Lock wasn't mapped. I kept trying to go all the way up to Esc, but I'd hit Caps every once and a while and then my normal commands would change. He taught me that Ctrl-c will also drop you back into Visual mode. **Do yourself a favor and start using Ctrl-c.** – campeterson Sep 10 '13 at 16:17
  • 8
    (Learning more every day) `CTRL-[` is actually the proper equivalent to ESC. http://stackoverflow.com/questions/5030164/whats-the-difference-between-ctrlc-and-ctrl/5036294#5036294 – campeterson Sep 10 '13 at 16:31
  • 2
    **PCKeyboardHack has been renamed Seil:** https://pqrs.org/macosx/keyremap4macbook/seil.html.en – Aupajo Jun 19 '14 at 23:31
  • 1
    @CoryKlein - if it is an issue with the Seil the author has always been very quick about releasing updates that work with the latest versions of OS X - actually on the [website](https://pqrs.org/osx/karabiner/seil.html.en) it mentions that it supports 10.10 already – cwd Jul 30 '14 at 21:39
  • 1
    @cwd I have filed an issue on the Seil github repo for this issue. I'm sure it will be resolved soon. – Cory Klein Jul 31 '14 at 19:53
  • 2
    How do I _swap_ the keys? That is, make Esc work as the Capslock? – thameera Oct 25 '14 at 15:03
  • @campeterson So mapping CL to ESC is only viable for those who work in VIM? Are there any other benefits for such remapping for other uses? – ruslaniv Sep 20 '15 at 09:27
  • 1
    Is it possible to keep Caps-Lock working by using a key modifier ? For example Cmd-CapsLock toggles the CapsLock status. – mperrin Jun 21 '16 at 11:27
  • @campeterson CTRL-C defeats the purpose. You have to reach for the corner of your keyboard and put your fingers in an awkward position. – user2609980 Aug 16 '16 at 18:45
  • 1
    @ErwinRooijakkers that's a fair opinion, but CTRL + (some key) is so common in the many applications I use (tmux, emacs, bash) that I've just become used to it. My goal is to be as comfortable on a server (via ssh), or another person's keyboard as I am on my own. – campeterson Nov 14 '16 at 22:40
  • 6
    Would be great if you could also edit and mention at the top that this is now a native feature in macOS 10.12.1 per @rkusa's answer so that new users don't have to go download third party software – edhurtig Apr 11 '17 at 19:38
  • 2
    to those confused by the links not working, seil has been deprecated for karabiner elements and the link is here https://pqrs.org/osx/karabiner/ – swyx Feb 15 '18 at 16:57
364

Since macOS 10.12.1 it is possible to remap Caps Lock to Esc natively (Apple > System Settings… > Keyboard > Keyboard Shortcuts > Modifier Keys in macOS 13, or, before, System Preferences -> Keyboard -> Modifier Keys).

enter image description here

Eric O. Lebigot
  • 91,433
  • 48
  • 218
  • 260
rkusa
  • 4,792
  • 1
  • 22
  • 28
  • 11
    Awesome! I found this after hearing the new MBP wouldn't have an escape key. Looks like Apple anticipated some backlash. – Andy E Oct 26 '16 at 08:05
  • 1
    Running El Capitan 10.11.6 and this setting is already available. – zool Nov 01 '16 at 13:30
  • 1
    Thank god for this; after Sierra broke Seil/Karabiner I thought I was doomed. – Philip Nov 16 '16 at 15:02
  • 4
    Oddly, i'm on 10.11.6 and don't have this option. I'm only allowed to remap esc to caps, ctrl, opt, or command. This is true for my WASD keyboards v2. – Benny Powers Dec 12 '16 at 11:49
  • 2
    Is there any way to do this via the commandline? Perhaps in a method similar to these? https://github.com/herrbischoff/awesome-osx-command-line#keyboard – Jordan Eldredge Jan 03 '17 at 04:14
  • This works in most cases, but not e.g. when trying to escape from editing a Facebook comment. There only the original Esc key works. – neu242 Jan 22 '17 at 19:12
  • 1
    the thing that sucks about this is not having caps lock anymore. – Andy Mar 28 '17 at 16:14
  • 1
    also, i really wish they allowed left/right modifier keys to be remapped independently. – Andy Mar 28 '17 at 16:14
  • Now i know why Apple can confidentially make the touch bar for the new macbook and remove the Esc button. Goddamn it those smart a$$ !!!! – Thai Tran Jul 20 '17 at 03:59
  • 1
    If I enable this is there anyway to turn on caps lock after the fact? – user838494 Feb 05 '18 at 22:32
  • Note that you will have to set this separately for each external/internal keyboard you are using. – patrick Jan 19 '22 at 20:10
71

I wasn't happy with any of the answers here, and went looking for a command-line solution.

In macOS Sierra 10.12, Apple introduced a new way for users to remap keys.

  • No need to fiddle around with system GUIs
  • No special privileges are required
  • Completely customisable
  • No need to install any 3rd-party crap like PCKeyboardHack / Seil / Karabiner / KeyRemap4MacBook / DoubleCommand / NoEjectDelay

If that sounds good to you, take a look at hidutil.

For example, to remap caps-lock to escape, refer to the key table and find that caps-lock has usage code 0x39 and escape has usage code 0x29. Put these codes or'd with the hex value 0x700000000 in the source and dest like this:

hidutil property --set '{"UserKeyMapping":[{"HIDKeyboardModifierMappingSrc":0x700000039,"HIDKeyboardModifierMappingDst":0x700000029}]}'

You may add other mappings in the same command. Personally, I like to remap caps-lock to backspace, and remap backspace to delete:

hidutil property --set '{"UserKeyMapping":[{"HIDKeyboardModifierMappingSrc":0x700000039,"HIDKeyboardModifierMappingDst":0x70000002A}, {"HIDKeyboardModifierMappingSrc":0x70000002A,"HIDKeyboardModifierMappingDst":0x70000004C}]}'

To see the current mapping:

hidutil property --get "UserKeyMapping"

Your changes will be lost at system reboot. If you want them to persist, configure them in a launch agent. Here's mine:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<!-- Place in ~/Library/LaunchAgents/ -->
<!-- launchctl load com.ldaws.CapslockBackspace.plist -->
<plist version="1.0">
  <dict>
    <key>Label</key>
    <string>com.ldaws.CapslockEsc</string>
    <key>ProgramArguments</key>
    <array>
      <string>/usr/bin/hidutil</string>
      <string>property</string>
      <string>--set</string>
      <string>{"UserKeyMapping":[{"HIDKeyboardModifierMappingSrc":0x700000039,"HIDKeyboardModifierMappingDst":0x70000002A},{"HIDKeyboardModifierMappingSrc":0x70000002A,"HIDKeyboardModifierMappingDst":0x70000004C}]}</string>
    </array>
    <key>RunAtLoad</key>
    <true/>
  </dict>
</plist>

I've placed this content into a file located at ~/Library/LaunchAgents/com.ldaws.CapslockBackspace.plist and then executed:

launchctl load com.ldaws.CapslockBackspace.plist
wim
  • 338,267
  • 99
  • 616
  • 750
  • 11
    +! this is the modern and right way to remap keys on macOS – Fanckush Jan 26 '18 at 19:58
  • 3
    Karabiner's [issue with repeating keys](https://github.com/tekezo/Karabiner-Elements/issues/545) caused me to look for a native solution for key remapping. This post and [another in apple.stackexchange.com](https://apple.stackexchange.com/questions/283252/how-do-i-remap-a-key-in-macos-sierra-e-g-right-alt-to-right-control) helped a great deal. – chb Aug 31 '18 at 19:49
  • Thanks for this, +1! I added some tangential notes to the [Apple post](https://apple.stackexchange.com/a/349440/15940) which hopefully adds some value to us poor people who don't want an Esc key but not on Caps Lock. – tripleee Jan 23 '19 at 11:35
  • Great method for MacBooks that have problems with the built-in keyboard. Mine was causing issues with Keyboard Settings so I could not remap any keys there. – Igor Jan 26 '19 at 00:04
  • I was unable to make this work properly with the `LoginHook` method -- I guess maybe something after it executes selects my local keyboard settings for a Scandinavian keyboard? Anyhow, https://stackoverflow.com/a/22872222/874188 notes that `LoginHook` is deprecated, and advocates using `launchd` instead. – tripleee Feb 27 '19 at 06:31
  • Per @tripleee's point about LoginHook being outdated, here's a gist to perform the remapping using launchd on user login: https://gist.github.com/liamdawson/8dba17715c452dad996932291193c353 – Liam Dawson Dec 29 '19 at 22:19
  • The linked Ask Different post above has a similar hook and some additional notes on how to find a suitable key if you don't want Caps Lock. (I too regret that I have taught my muscle memory to reach for Caps Lock on colleagues' keyboards.) – tripleee Dec 30 '19 at 08:35
  • 1
    This is also the only way I've found so far to map the Escape Key to toggle Caps Lock. Definitely the best solution. – Praxder Mar 09 '22 at 15:22
39

The only thing I know how to do is to map Caps Lock to Control, or Option, or Command. This can be done via the Keyboard & Mouse pane of System Preferences. Click on "Modifier Keys" on the bottom left and you'll be able to remap Caps Lock, Control, Option, and Command, to any of those.

@Craig: This suggests that Caps Lock can be used as a normal -- that is, non-toggle -- key. On my MacBook, since I have re-mapped Caps Lock to Control, the Caps Lock light never lights up. It simply acts like the Control key.

enter image description here

jwpfox
  • 5,124
  • 11
  • 45
  • 42
EfForEffort
  • 55,816
  • 4
  • 36
  • 41
38

It is now much easier to map the Caps Lock key to Esc with macOS Sierra.

  1. Open System Preferences → Keyboard.

  2. Click the Modifier Keys button in the bottom right-hand corner.

  3. Click the drop down box next to the hardware key that you’d like to remap, and select Escape.

  4. Click OK and close System Preferences.

enter image description here

https://9to5mac.com/2016/10/25/remap-escape-key-action-macbook-pro-macos-sierra-10-12-1-modifier-keys/

Tomasz Jakub Rup
  • 10,502
  • 7
  • 48
  • 49
neurosnap
  • 5,658
  • 4
  • 26
  • 30
34

It's possible.

Solution 1

From an arcticle on TrueAffection.net.

  • Download PCKeyboardHack and install it.
  • Go to PCKeyboardHack in System Preferences.
  • Enable ‘Change Caps Lock’ and set the keycode to 53.

Solution 2

This solution doesn't involve patching the keyboard driver, but gives you a Vim specific solution.

OS X supports mapping the Caps Lock key to a whole bunch of keys, but you have to do it 'by hand', editting .plist files. The process is described in this article. As addendum to that hint I suggest you first set Caps-Lock to None in the System Preferences, then you only need to change one value in the .plist file. Also, you can of course use the Property List Editor instead of going through the XML conversion steps.

The trick is to map the Caps Lock key to the Help key (code 6), which isn't on most keyboards. But if it is, it will be treated as the insert key, which you probably don't use anyway, since you ask about remapping your Caps Lock to prevent stretching your hands ;)

You can then map the Help and the Insert key to Esc in vim.

map  <Help> <Esc>
map! <Help> <Esc>
map  <Insert> <Esc>
map! <Insert> <Esc>

This will work for gvim (Vim.app). I didn't get it to work with vim in the Terminal and I haven't tested it with MacVim.

So, it's rather a complicated, half-baked solution or installing a third-party piece of hackery. Your pick ;)

Edit: Just noticed solution 3, if you're using MacVim you can use Ctrl, Option and Command as Esc. With the System Preferences it's trivial to map Caps Lock to one of those keys.

kdbanman
  • 10,161
  • 10
  • 46
  • 78
eelco
  • 1,597
  • 12
  • 8
14

Seil isn't yet available on macOS Sierra (10.12 beta). As such, I've been using Keyboard Maestro with these settings: enter image description here

Credit to this github comment: https://github.com/tekezo/Seil/issues/68#issuecomment-230131664

Michael Glass
  • 1,011
  • 8
  • 6
  • 2
    I'm using https://github.com/tekezo/Karabiner-Elements (which works on Sierra). Working great so far, although I wish it did "Control_L to Control_L (+ when you type Control_L only, send Escape)" – atomkirk Sep 21 '16 at 02:40
  • 1
    @atomkirk Would you mind sharing the Karabiner JSON config you used? – LandonSchropp Oct 02 '16 at 06:36
  • 1
    { "profiles": [ { "name": "Default profile", "selected": true, "simple_modifications": { "caps_lock": "escape" } } ] } – atomkirk Oct 03 '16 at 13:14
  • Lots of examples here: https://github.com/tekezo/Karabiner-Elements/blob/master/usage/README.md#typical-configuration-files – atomkirk Oct 03 '16 at 13:14
  • Karabiner did the trick for me with atomkirk's JSON. Despite the screenshot above, the Keyboard Maestro UI is a shambles and I couldn't configure it. – Paul Oct 09 '16 at 16:56
  • For anyone looking to map multiple keystroke to single key on sierra, here's one way: http://superuser.com/questions/1142577/bind-caps-lock-key-to-tmux-prefix-on-macos-sierra/1142578#1142578 – Patrick Berkeley Nov 04 '16 at 22:37
10

In case you don't want to install a third-party app and you really only care about vim inside iTerm, the following works:

Remap CapsLock to Help as described here.

Short version: use plutil or similar to edit ~/Library/Preferences/ByHost/.GlobalPreferences*.plist, it should look similar to this:

<key>HIDKeyboardModifierMappingDst</key>
<integer>6</integer>
<key>HIDKeyboardModifierMappingSrc</key>
<integer>0</integer>

Restart! A simple log-out and log-in did not work for me.

In iTerm, add a new key mapping for Help: send hex code 0x1b, which corresponds to Escape.

I know this is not exactly what was asked for, but I assume the intent of many people looking for a solution like this is actually this more specialized variant.

user2581875
  • 129
  • 1
  • 5
10

Having tried several of these solutions, I have some notes:

DoubleCommand will not allow you to swap esc and caps-lock.

PCKeyboardHack will allow you to map capslock to escape, but does not have the capability to map escape to capslock. Recent versions will allow you to perform a complete swap by editing both keys.

This may or may not be sufficient for your needs (I know it is for mine).

Zxaos
  • 7,791
  • 12
  • 47
  • 61
  • 1
    PCKeyboardHack does not let you map escape to capslock, but the companion app [KeyRemap4MacBook](http://pqrs.org/macosx/keyremap4macbook/index.html.en) does. It lets you map “Escape to CapsLock” and “Shift+Escape to CapsLock”. – Rory O'Kane Jan 20 '13 at 22:26
4

Open up Keyboard preferences and click modifier keys... you can change the caps lock key to control, option, escape, or command.

enter image description here

jwpfox
  • 5,124
  • 11
  • 45
  • 42
Nayan Jain
  • 188
  • 9
4

In order to actually swap the escape key with the caps lock key (not just map one to the other) using both PCKeyboardHack and KeyRemap4MacBook, you have to follow the instructions in this thread, mapping the caps lock key to a keycode not used by the keyboard but accounted for by KeyRemap4MacBook (eg. 110). Then, in PCKeyboardHack, select the appropriate option that maps that keycode to escape (in the case of 110, it's "Application Key to Escape"). Here's what your KeyRemap4MacBook preferences should look like (provided you've selected the "show enabled only" checkbox).

enter image description here

I originally attempted to post this information as an edit to cwd's excellent answer, but it was rejected. I encourage anyone who wants to go the route that I describe to first read his/her response.

Community
  • 1
  • 1
chb
  • 1,727
  • 7
  • 25
  • 47
3

With the latest Ventura update, System Settings changed.

You will find it on

System Settings > Keyboard > Keyboard Shortcuts > Modifier Keys

Mac OS Ventura Modifier Keys Menu

Erdem İnanç
  • 101
  • 2
  • 6
2

Seil doesn't work on macOS Sierra yet, so I'm using Karabiner Elements, download from https://pqrs.org/latest/karabiner-elements-latest.dmg.

Either use the GUI or put the following into ~/.karabiner.d/configuration/karabiner.json:

{
  "profiles" : [
    {
      "name" : "Default profile",
      "selected" : true,
      "simple_modifications" : {
        "caps_lock" : "escape"
      }
    }
  ]
}
mb21
  • 34,845
  • 8
  • 116
  • 142
1

You can also use DoubleCommand to remap this, and other keys.

IIRC, it will map Caps Lock to Esc.

Matthew Schinckel
  • 35,041
  • 6
  • 86
  • 121
  • 1
    Actually, I had to write a patch to do this. It was for an older version, but I am still using it now: http://sourceforge.net/tracker/?group_id=65339&atid=510607 – Matthew Schinckel Jul 29 '09 at 02:13
0

Karabiner-Elements A powerful and stable keyboard customizer for macOS. (freeware)

https://pqrs.org/osx/karabiner/index.html

Worked for me for Mojave to change caps-lock to backspace

Quang Van
  • 11,475
  • 12
  • 57
  • 61