Last active
August 7, 2022 05:48
-
-
Save riotrah/069c82891491a9a0829a6b5e0f67fe18 to your computer and use it in GitHub Desktop.
Windows AutoHotKey (AHK) Script to make a hyper key out of CapsLock. Supports arbitrary modifiers! Defaults to vim-ish nav controls + others.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; #Warn ; Enable warnings to assist with detecting common errors. | |
#NoEnv ; recommended for performance and compatibility with future autohotkey releases. | |
#UseHook | |
#InstallKeybdHook | |
#SingleInstance force | |
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory. | |
SendMode Input | |
;; If the script is not elevated, relaunch as administrator and kill current instance | |
;; This allows us to use the hyper key in admin applications. | |
full_command_line := DllCall("GetCommandLine", "str") | |
if not (A_IsAdmin or RegExMatch(full_command_line, " /restart(?!\S)")) | |
{ | |
try ; leads to having the script re-launching itself as administrator | |
{ | |
if A_IsCompiled | |
Run *RunAs "%A_ScriptFullPath%" /restart | |
else | |
Run *RunAs "%A_AhkPath%" /restart "%A_ScriptFullPath%" | |
} | |
ExitApp | |
} | |
;; Unrelated convenience to reload this particular script if its name is within active window title | |
#If WinActive(A_ScriptName) | |
~^s:: | |
Reload | |
Return | |
#If | |
;; | |
;; This is where it starts | |
;; | |
;; Capslock used by itself presses "Esc" key | |
*CapsLock:: | |
KeyWait, CapsLock | |
If (A_PriorKey="CapsLock") | |
Send {Esc} | |
Return | |
;; Start the CapsLock + key block | |
#If, GetKeyState("CapsLock", "P") ;CapsLock hotkeys go below | |
;; Defensively deactivate capslock feature completely | |
SetCapsLockState, Off | |
SetCapslockState, AlwaysOff | |
SetStoreCapslockMode, Off | |
;; Traditional vim home row nav keys (or at least some of them) | |
;; Use of *<key> and {Bind} allows arbitrary modifier keys, creating a "true" hyper key | |
;; That means arbitrary combos of Ctrl Alt Win Shift + CapsLock + <key> work as expected | |
*h::Send {Blind}{Left} | |
*j::Send {Blind}{Down} | |
*k::Send {Blind}{Up} | |
*l::Send {Blind}{Right} | |
;; Easy page up and page down | |
*p::Send {Blind}{PgUp} | |
*n::Send {Blind}{PgDn} | |
;; Personal rebinds | |
*Space::Send {Blind}{Enter} | |
;; stupid windows ctrl-backspace/delete workarounds | |
;; in some older windows ui toolkit based apps, ctrl+backspace/delete just insert a strange character | |
*Backspace:: | |
Send {Ctrl DownTemp}{Shift DownTemp}{Left} | |
Send {Ctrl Up}{Shift Up} | |
Send {Backspace} | |
return | |
*Del:: Send ^+{Right}{Del} | |
;; Attempt to override capslock + Win + L = Win + L + Lock System | |
;; It should result instead in Capslock + Win + L = Win + Right | |
;; TODO: This doesn't work yet, which is annoying :( | |
#*l::send {Blind}{vkFF} | |
#If | |
;; number row -> function row | |
;; Debating whether I want these | |
; ~Capslock & 1:: Send {F1} | |
; ~Capslock & 2:: Send {F2} | |
; ~Capslock & 3:: Send {F3} | |
; ~Capslock & 4:: Send {F4} | |
; ~Capslock & 5:: Send {F5} | |
; ~Capslock & 6:: Send {F6} | |
; ~Capslock & 7:: Send {F7} | |
; ~Capslock & 8:: Send {F8} | |
; ~Capslock & 9:: Send {F9} | |
; ~Capslock & 0:: Send {F10} | |
; ~Capslock & -:: Send {F11} | |
; ~Capslock & =:: Send {F12} | |
;; | |
;; End of what you're looking for | |
;; | |
;; Stupid new windows MS Office hotkey deactivation | |
^!+LWin::send {Blind}{vkFF} | |
#^!+W:: | |
Send ^!+W | |
return | |
#^!+T:: | |
Send ^!+T | |
return | |
#^!+Y:: | |
Send ^!+Y | |
return | |
#^!+O:: | |
Send ^!+O | |
return | |
#^!+P:: | |
Send ^!+P | |
return | |
#^!+D:: | |
Send ^!+D | |
return | |
#^!+L:: | |
Send ^!+L | |
return | |
#^!+J:: | |
Send ^!+J | |
return | |
#^!+X:: | |
Send ^!+X | |
return | |
#^!+N:: | |
Send ^!+N | |
return | |
#^!+Space:: | |
Send ^!+Space | |
return | |
;; win q / w from macOS | |
;; Another random preference of mine | |
;; Win + Q = Close/Quit App | |
;; TODO: Doesn't really work yet | |
#~q:: | |
Send {LAlt Down}{F4 Up}{LAlt Up} | |
return | |
;; Win + W = Minimize App | |
#~w:: | |
WinMinimize, A | |
return |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment