Skip to content

Instantly share code, notes, and snippets.

@eduuh
Forked from tanyuan/smart-caps-lock.md
Last active May 3, 2022 16:56
Show Gist options
  • Save eduuh/223042b0f0f824638f42e2b032b1289f to your computer and use it in GitHub Desktop.
Save eduuh/223042b0f0f824638f42e2b032b1289f to your computer and use it in GitHub Desktop.
Smart Caps Lock: Remap Caps Lock to Control AND Escape

Smart Caps Lock: Remap to Control AND Escape (Linux, Mac, Windows)

  • Send Escape if you tap Caps Lock alone.
  • Send Control if you press Caps Lock with another key.
  • send caps lock if you press both shift keys together

For vim , emacs and normal day typing

GNU/Linux

Step 1. Install XCAPE

Install XCAPE (xcape). (Linux utility to configure modifier keys to act as other keys when pressed and released on their own.)

Ubuntu:

sudo apt-get install xcape

Step 2. Run the command

# make CapsLock behave like Ctrl:
setxkbmap -option ctrl:nocaps

# make short-pressed Ctrl behave like Escape:
xcape -e 'Control_L=Escape'

The effect should apply immediately.

Step 3. Autostart

Append code from Step 2 to file ~/.xprofile to run the command when X starts.

macOS

  1. Download and install Karabiner-Elements, a powerful and stable keyboard customizer.
  2. Open Karabiner-Elements, select Complex Modifications tab, and click Add rule at the bottom.
  3. Find Post escape if caps is pressed alone, left_ctrl otherwise and click on enable.

The effect should apply immediately.

Windows

Option 1:

  1. Download and install AutoHotKey.
  2. Use the script CapsLockCtrlEscape.ahk.

This was made possible with a third party software called AutoHotkey Usually the Altimate automation script for windows systems. I choose to use these program since i plan to do some automations with in window with it.

I admit i did not write the script for this program myself by i sourced out from github.

This script came with something additional that i loved. I did not lose the caps lock fuctionality as in my linux distro. Pressing the two shift keys together activates thes caps lock.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment