Recently decided to make use of the CAPS LOCK key to avoid having to move my hands to the arrow keys when I needed arrow key stuff. After a bunch of googling came across https://www.autohotkey.com/
My goal here was to have CAPS LOCK function normally if you press and release it, but if you press and hold, it should act as a modifier. I didn't see this as a pre-canned example, and after much questionable AI, decided to just code it from scratch. OK, AI helped a bit, but was really bad at hallucinations.
I decided on using ijkl for the navigation but I'm thinking now that maybe vim navigation is better. I'm having to stretch to get the end key while editing so that's probably a good thing to do as well. Home and end. And maybe that makes more sense with H being home, and ; being end since they are around the navigation. A work in progress I guess.
Here's what I ended up with:
#Requires AutoHotkey v2.0
#Include "C:\Users\nik\Documents\AutoHotkey\TapHoldManager\AHK v2\Lib\TapHoldManager.ahk"
#SingleInstance
capsHeld := false
;
; We got a Caps Lock
; If holding it, just set global flag
; If tapping it, send CapsLock on or off which toggles it
;
CapsLockHandler(isHold, taps, state) {
Global capsHeld
if isHold {
if (capsHeld = true) {
capsHeld := false
} else {
capsHeld := true
}
} else {
Send("{Blind}{CapsLock}")
}
}
thm := TapHoldManager()
thm.Add("CapsLock", CapsLockHandler)
;
; Handle keypress
;
*j:: {
if capsHeld {
Send("{Left}")
} else {
Send("{Blind}j")
}
}
*k:: {
if capsHeld {
Send("{Down}")
} else {
Send("{Blind}k")
}
}
*l:: {
if capsHeld {
Send("{Right}")
} else {
Send("{Blind}l")
}
}
*i:: {
if capsHeld {
Send("{Up}")
} else {
Send("{Blind}i")
}
}
; removeTooltip() {
; ToolTip
; }
; ToolTip("CapsLock released")
; SetTimer(removeTooltip, -1000)
The ToolTip things being me adding in debugging messages.
No comments:
Post a Comment