Programming
07/04/2024
programming, autohotkey
The Caps Lock key takes up prime keyboard real estate despite it's low usage so I've rebinded two frequently used keys in its place, Escape and Control. To achieve this I used AutoHotKey, a free open source scripting language that enables custom hotkeys and rebinds.
#NoEnv SendMode Input SetWorkingDir %A_ScriptDir% #InstallKeybdHook SetCapsLockState, alwaysoff *Caps Lock:: Send {LControl Down} KeyWait, Caps Lock Send {LControl Up} if ( A_PriorKey = "Caps Lock" ) { Send {Esc} } return
When Caps Lock is pressed on its own it acts as escape, a key that's used fairly often in vim. However when Caps Lock is pressed in conjunction with another key it acts as Left Control. Despite being used in pretty much every shortcut, the control key is awkwardly situated at the edge of the keyboard so it's way more ergonomic to use Capslock instead. The script also works with shortcuts that use multiple keys like Caps Lock + Shift + T
by by using the asterisk in *Cap Lock::
.
One side effect this introduces is that you have to swap fingers when using shortcuts that involve both Caps Lock and Shift. I.e. I use my pinky to press Capslock for Caps Lock + F
but have to swap to my ring finger for Caps Lock + Shift + F
. To get around this, I thought of using Space instead of Shift so that the new shortcut becomes Caps Lock + Space + F
, ergonomic.
The script logic is to simply press Left Shift when Caps Lock and Space are held, and raise it when Space is released.
; Rebind Space to Left Shift only while CapsLock is held down ~Capslock & Space:: Send {LShift Down} KeyWait, Space Send {LShift Up} return
Lastly I wanted to use hjkl
in place of arrow keys because moving my hand to the bottom right whenever I wanted to navigate menus or do single character navigation was kinda awkward. Since Caps Lock was now taken I decided to use Control as the modifier instead.
LControl & h::Send {Left} LControl & j::Send {Down} LControl & k::Send {Up} LControl & l::Send {Right}