I'm really new to all this and have spent a good chunk of time already reading posts that have asked this same question to see what the replies have said. Unfortunately given how new I am a lot of it goes way over my head.
Basically I'm trying to press Caps Lock twice in a row which will trigger Alt+F12
Double press = Hotkey
Re: Double press = Hotkey
I've been meaning to write a script like this to prove a point to someone.
You don't need to fully understand it, this script abuses an AHK feature in an unusual way.
You don't need to fully understand it, this script abuses an AHK feature in an unusual way.
Code: Select all
; When CapsLock is pressed, call PressedCaps(). Still toggles CapsLock
; because PressedCaps() returns 0, meaning the actual hotkey itself
; (the return) will not run and the original key passes through.
#HotIf PressedCaps()
CapsLock::return
#HotIf
; If this function was called twice within 200 milliseconds, send Alt-F12.
PressedCaps()
{
static lastPress := 0
if A_TickCount < lastPress + 200
{
lastPress := 0
; We can't actually Send "!{F12}" here because sending another key
; in a HotIf expression causes horrible jank. Instead, schedule the
; Alt-F12 to be sent as soon as possible, but not immediately.
SetTimer SendX, -1
} else {
lastPress := A_TickCount
}
; Prevent the hotkey from running.
return 0
; Change that 0 to 1 to make the hotkey run. In this case, the hotkey
; is return, so pressing CapsLock will do nothing else (return without
; doing anything)
}
SendX()
{
; This is AutoHotkey's key sending syntax at work. ! stands for "send
; the next key while pressing Alt" and {} is needed around the F12
; because the key's name is not just one character.
Send "!{F12}"
}
Re: Double press = Hotkey
This less advanced code might work well in this case because pressing twice keeps the previous CapsLock toggle state (uppercase/lowercase).
Code: Select all
~CapsLock::
{
if (A_PriorHotkey = A_ThisHotkey) && (A_TimeSincePriorHotkey < 500)
Send("!{F12}")
}