PatternHotKey allows you to map multiple pattern combination of short or long press of a hotkey to any combination of keys, labels or functions. I needed to map multiple long key press from my Boxee Remote because it has so few buttons, something like RapidHotkey, but that detected long key press. And frankly, I was not thrilled by the parameter hell of RapidHotkey (no offense intended), so... voilà!
Download:
[*:2qu8sump] PatternHotKey.ahk
Last updated: May 13th, 2011
[*:2qu8sump] PatternHotKey Test.ahk
Last updated: May 13th, 2011
Example (contents of the test file):
#Include PatternHotKey.ahk
; Simple hotkey: Make capslock toggle only on double press
; '.' (short press) eats the Capslock key (sends no keys)
; '..' (double short press) toggles capslock (GoSub ToggleCapsLock)
Capslock::PatternHotKey(".:","..->ToggleCapsLock")
ToggleCapsLock:
if ( GetKeyState("Capslock", "T") )
SetCapsLockState, Off
else
SetCapsLockState, On
return
; Test slow patterns (up to 10 presses)
F9::MsgBox % KeyPressPattern(10, 0.5)
; Test default patterns (up to 10 presses)
F10::MsgBox % KeyPressPattern(10)
; Test fast patterns (up to 10 presses)
F11::MsgBox % KeyPressPattern(10, 0.1)
; Test pattern hotkey
;
; ':' separator means Send
; '->' separator means GoSub or function call
; Note: Functions always receive everything as one
; parameter: there is no parameter parsing.
F12::PatternHotKey(".:single-click" ; single-"click" (equivalent to '0')
,"..:double-click" ; double-"click" (equivalent to '00')
,"...:triple-click" ; triple-"click" (equivalent to '000')
,"007:Bond, James Bond" ; double short then a '7' long press
; i.e. at 0.2 period, between 1.4 and
; 1.6 seconds; it is hard to trigger.
,"._->mylabel" ; short then long
,"__->myfunction()" ; double long
,"_.->myfunction(12345)" ; long then short
,"~^[1-5]$->myfunction(long press, mate)" ; long press between '1' and '5'
,"~^[6-9A-Z]$->myfunction(very long press)" ; long press between '6' and 'Z'
,3 ; length (because it is integer)
,0.2) ; delay (because it is float)
mylabel:
MsgBox % "gosub mylabel called"
return
myfunction(myparameter)
{
MsgBox % "myfunction(" . myparameter . ") called"
}Acknowledgements:
[*:2qu8sump]Laszlo for the lovely idea that is Morse()
[*:2qu8sump]HotKeyIt for RapidHotkey and messing with Morse
[*:2qu8sump]TheGood for his post design, hope it's not copyrighted
Thank you all for sharing!
As always, comments and suggestions are welcome.
Enjoy!
Changelog
May 13th, 2011
- First version




