
Uncap - Map Caps Lock to Escape on Windows, Linux, and macOS - susam
https://github.com/susam/uncap
======
EdSchouten
Easter egg in the source code:
[https://github.com/susam/uncap/blob/78f52d7b2e03fc51885c8072...](https://github.com/susam/uncap/blob/78f52d7b2e03fc51885c8072d53ff5d41fbe3ffc/uncap.c#L469-L506)

Output:

    
    
      ...............................................................
      ...............................................................
      .................. @@@@@@@ ......... @@@@@@@ ..................
      ............... @@@@     @@@@ ... @@@@     @@@@ ...............
      ............. @@@           @@@ @@@           @@@ .............
      ............ @@@               @               @@@ ............
      ............ @@@    Cutie Pai,                 @@@ ............
      ............ @@@                               @@@ ............
      ............. @@@         I love you!         @@@ .............
      ............... @@@@                       @@@@ ...............
      .................. @@@@     -- Susam    @@@@ ..................
      ..................... @@@@           @@@@ .....................
      ........................ @@@@     @@@@ ........................
      ........................... @@@ @@@ ...........................
      .............................. @ ..............................
      ...............................................................
      ...............................................................

------
nickjj
I just use AutoHotKey because I'm already using AHK for so many things.

On Windows, I think most people who would want to remap these keys are already
using AutoHotKey to set up custom global hotkeys or do other tweaks.

The entire AHK script is a 2 liner that you can put into an existing script,
such as:

    
    
        CapsLock::Esc
        Esc::CapsLock
    

Only including that here because the OP's alternative AHK example in the
readme remaps CapsLock to Escape, but it doesn't include remapping Esc to
CapsLock (both are necessary to swap the keys).

His current example would leave your Esc key unchanged, meaning you would have
2 escape keys and 0 CapsLock keys.

~~~
karmakaze
I suspect it was intentional as I too would want 0 keys mapped to CapsLock.

Is there a way with AHK to map CapsLock tapped by itself to Esc and held with
other keys as Ctrl?

~~~
nickjj
I've never tried that behavior and I'm also not an AHK wizard (I use it for a
few global hotkeys, remapping escape and some small tweaks).

But Google came up with this:
[https://autohotkey.com/board/topic/104173-capslock-to-
contro...](https://autohotkey.com/board/topic/104173-capslock-to-control-and-
escape/)

The last reply's code sample looks like it would do what you want in a non-
buggy way. If not, there were about 20 other Google results for combo mapping
CapsLock to CTRL and / or Escape depending on how it was pressed.

------
timidiceball
Why does one need this on macOS (which has had a dedicated toggle for this in
System Preferences for a few versions now)?

~~~
rzwitserloot
For the casual reader who does not know:

* Start app 'System Preferences'

* Pick 'Keyboard'

* Click button 'Modifier Keys...'

* Per keyboard you can now configure what the caps lock key does. One of the options is 'escape'. Which is what it should be :)

------
goerz
The tool itself is actually Windows-only, it seems.

Also, a more interesting question would be how to map caps lock to ctrl (or
something else) on hold, and esc on tap, across platforms.

~~~
dguo
After doing this (ctrl on hold and escape on tap) on every system I use, I
wrote a blog post with instructions: [https://www.dannyguo.com/blog/remap-
caps-lock-to-escape-and-...](https://www.dannyguo.com/blog/remap-caps-lock-to-
escape-and-control/)

~~~
danieldk
Oh, that's nice! I had capslock mapped to control, but I wanted to have escape
on tap as well. But I never bothered to figure it out on Wayland.

Turns out you can enable _caps2esc_ , which is mentioned in the blog post, on
NixOS with a single line:

    
    
        services.interception-tools.enable = true;

------
petepete
I solved this problem many years ago by switching to a keyboard with a better
layout.

I'd thoroughly recommend a HHKB to any programmer.

~~~
AnthonBerg
I fully respect your choice :)

As a hopefully interesting comparison, for me the right choice is a logical
layout that is decoupled from the physical layout. And a Russian physical
layout keyboard from Apple. And an US software layout.

(I'm Icelandic and don't speak or write Russian. Not yet at least.)

The Russian keyboard has all the programming symbols in the right places, a
two-story enter key, and has the key between left-shift and Z. And gorgeous
Cyrillic symbols on each key, _in addition_ to the English-layout keys. Then
my fingers sit on something beautiful that they know.

Russian layout: [https://store.storeimages.cdn-apple.com/4982/as-
images.apple...](https://store.storeimages.cdn-apple.com/4982/as-
images.apple.com/is/MRMH2RS?wid=1144&hei=1144&fmt=jpeg&qlt=95&op_usm=0.5,0.5&.v=1520717644293)

US layout: [https://store.storeimages.cdn-apple.com/4982/as-
images.apple...](https://store.storeimages.cdn-apple.com/4982/as-
images.apple.com/is/MRMH2?wid=1144&hei=1144&fmt=jpeg&qlt=95&op_usm=0.5%2C0.5&.v=1520629359080)

And I love the crisp action that Apple's keyboards have today. – I appreciate
that some don't like the feel. That's why we need a rainbow of variety!

Then I remap things in software. I personally remap Caps Lock to Ctrl and keep
Esc where it is.

~~~
tauchunfall
That's interesting. When you order from the Apple website from German region,
you can choose e.g. English (US) and English (International). But US region
does not allow to choose English (International).

\- English (International) layout: [https://store.storeimages.cdn-
apple.com/4668/as-images.apple...](https://store.storeimages.cdn-
apple.com/4668/as-
images.apple.com/is/MLA22Z?wid=1144&hei=1144&fmt=jpeg&qlt=80&op_usm=0.5,0.5&.v=1498602296120)

\- English (US) layout: [https://store.storeimages.cdn-apple.com/4668/as-
images.apple...](https://store.storeimages.cdn-apple.com/4668/as-
images.apple.com/is/MLA22LL?wid=1144&hei=1144&fmt=jpeg&qlt=95&op_usm=0.5,0.5&.v=1496944005839)

\- Russian layout: [https://store.storeimages.cdn-apple.com/4982/as-
images.apple...](https://store.storeimages.cdn-apple.com/4982/as-
images.apple.com/is/MLA22RS?wid=1144&hei=1144&fmt=jpeg&qlt=95&op_usm=0.5,0.5&.v=1496943898748)

~~~
Symbiote
English International is a good option on a Mac.

For Windows/Linux, an easily available European keyboard with the double-
height enter, extra key next to Z, and most of the "programming" keys in the
same place as the American layout is the British/Irish layout.

(The main difference is " and @ are swapped. Shift-3 becomes £, but that
pushes # to the extra, unshifted key, which is a plus. I have never used ¬.)

------
zaat
On Linux you can either set it in gnome or, if you are using a wm, just run
setxkmbap -option caps:escape.

------
Fnoord
On Linux I use GNOME Tweaks to rebind it to escape (though you can also use
xmodmap directly). It doesn't work on console, and I don't think it works in
Wayland either (!!).

on Mac I use Karabiner Elements to rebind it to escape (though you can also
use System Preferences).

On Windows -which I try to avoid- I use a registry edit to _disable caps lock_
which one can find via a search engine (do verify the contents). This has the
advantage that you can still bind it e.g. in games (such as for push-to-talk).

For those who search a AutoHotKey (AHK) alternative on Linux, consider AutoKey
[1] which has Python scripting support.

[1] [https://github.com/autokey/autokey/](https://github.com/autokey/autokey/)

------
domenukk
PSA: In VIM ctrl-c does the same as ESC. No need to remap of you relearn.

~~~
chrismorgan
This is not entirely true, and the differences between them sometimes matter.
If you want an equivalent, go for CTRL-[, which is _actually_ equivalent.

If you’re interested in some of the differences, start in `:help ins-special-
keys`.

------
jesperhh
EDIT: This is actually already mentioned in the README

This seems like the wrong approach to remap keys on Windows. This tool is
using a keyboard hook, so it needs to run always for the remapping to work.

Windows already has a way of remapping keys through the registry that will
persist over reboots, without re-running the tool. There are many GUI tools
for modifying the key-mapping in registry, I use SharpKeys
([https://archive.codeplex.com/?p=sharpkeys](https://archive.codeplex.com/?p=sharpkeys))

------
envoked
For anyone looking for a new keyboard with custom key maps, I’d really
recommend the Kinesis advantage. I switched to it 8 years ago to fend off
carpal tunnel after my old keyboard was bothering my wrists. It was easy to
get used to and now whenever I’m on my Macbook’s keyboard, it feels archaic.
It’s strange that by default (probably a relic from typewriters) we use our
most important digits solely for bashing on the space bar.

It also has built-in key remapping so you don’t need to mess with anything on
the OS level.

------
Tharkun
I only use keyboards with QMK firmware these days. It's much easier to flash a
new layout to my keyboard than it is to keep messing around with OS settings
for keyboards.

~~~
yannikyeo
+1. I too use a custom keyboard with QMK firmware. In addition to mapping Caps
Lock to Esc, I also map holding down of Caps Lock to Ctrl.

------
bollockitis
See also: SharpKeys
([https://github.com/randyrants/sharpkeys](https://github.com/randyrants/sharpkeys))

------
oneplane
Is this just for VIM users or is there another reason why someone would want
to specifically remap the Escape key and ditch the Caps Lock?

~~~
pfortuny
I as emacs user prefer ESC-x to ALT-x with ESC at CAPS because it is simpler
to me.

~~~
oneplane
But why not real ALT-x to CAPS-x instead?

------
josteink
On Windows I just use remapkey.exe.

Let’s you remap _anything_ with a nice GUI editor to boot.

My non-official download here:
[https://stuff.kjonigsen.net/remapkey.exe](https://stuff.kjonigsen.net/remapkey.exe)

As for random EXEs on the Internet, you’ll have to trust me or find alternate
sources.

It’s a good tool. Does one thing and does it well.

------
MiddleEndian
I use win compose on Windows and whatever built in tools on KDE in Linux to
treat caps lock as the compose key.

This allows me to type special characters in an intuitive way, such as
producing © with compose o c, or π with compose p i, along with definable
custom shortcuts.

------
maxerickson
Also see [https://docs.microsoft.com/en-
us/sysinternals/downloads/ctrl...](https://docs.microsoft.com/en-
us/sysinternals/downloads/ctrl2cap)

------
Hendrikto
I bind it to Scroll Lock, which I absolutely never use. That way I have a
conveniently reachable key to use for whatever I need atm.

------
m000
Can someone explain what's the purpose of this remapping?

Is this for MacBook Pro models with a Touch Bar, or is it something else
altogether? In the former case, a better title would be "Map Escape to Caps
Lock".

~~~
rodorgas
I use vim, so esc is one of the most important keys. But I use esc in most
apps very frequently. I don’t use Caps Lock at all.

~~~
_rrnv
I still don't get it. We have a keyboard with an Esc key and a Caps Lock key.
Why would I remove Caps Lock and use it as another Esc key?

~~~
paulhilbert
Try pressing esc every few seconds for 8-12hrs a day like a vim developer does
and you'll know.

~~~
wruza
(Single datapoint ahead.)

I edit my sources and remote configs exclusively in vim-likes since ~2004
(full time sw dev) and never experienced such issues. From my experience,
typing or clicking speed requirement rarely exceeds that of thinking on your
program. I hit esc often, but not too often, and it is not too far.

I’m not against caps->esc mapping in general, but for me this would have
little to no value plus non-standard layout, which is minus, since I’m not
office-only guy.

