I have an issue with my keyboard where I am experiencing pretty bad keyboard chatter on certain keys. I managed to find an autohotkey script that helps to filter key presses on the keyboard, however what it actually does is send the same key repeatedly if it is held down, which presents a problem for me when I use applications that require the key to be held down for certain shortcuts (Maya, XSI etc.)
I tried modifying the SendInput command with the {blind} flag and adding the 'down' modifier to %k_ThisHotkey%, but I could never get it to work properly.
(I added a 'down' for the first sendinput, and did a GetKeyState in order to check if the key was being held down, then did a condition where if the key was released, a SendInput up would execute. However, this did not work as intended, and I am out of ideas.)
Would anyone be willing to give some pointers as to how I could have a proper debouncer script working, while allowing for keys to be held down as well?
Thanks!
; ---- setups
#UseHook On
;Capslock::LShift
; ---- initialize parameters
if (%0% > 0)
k_TimeThreshold = %1%
else
k_TimeThreshold = 40
;k_TimeThreshold = 1000 ; for debugging
; ---- initialize variables
k_LastHotkey = 0
k_LastTick := A_TickCount
; ---- Set all keys as hotkeys. See www.asciitable.com
k_ASCII = 33
Loop
{
Transform, k_char, Chr, %k_ASCII%
Hotkey, %k_char%, k_KeyPress
if ((k_char Not In +,^) AND (k_ASCII != 123 AND k_ASCII != 125))
{
Hotkey, +%k_char%, k_KeyPress ; shift
; Hotkey, ^%k_char%, k_KeyPress ; control
; Hotkey, !%k_char%, k_KeyPress ; alt
; Hotkey, #%k_char%, k_KeyPress ; win
}
if k_ASCII = 64
k_ASCII = 91
else if k_ASCII = 126
break
else
k_ASCII++
}
return
; ---- End of auto-execute section.
; ---- When a key is pressed by the user, send it forward only if it's not a "bounce"
; ---- A "bounce" is defined as: "key is same as last" AND "time since last key is very short"
Enter::
Space::
Tab::
Esc::
BS::
Del::
Ins::
Home::
End::
PgUp::
PgDn::
Up::
Down::
Left::
Right::
k_KeyPress:
{
k_ThisHotkey := A_ThisHotkey ; grab the current hotkey
k_ThisTick := A_TickCount ; grab the current tick
ElapsedTime := k_ThisTick - k_LastTick ; time since last hotkey (ticks)
if (ElapsedTime > k_TimeThreshold || k_ThisHotkey <> k_LastHotkey)
{
if k_ThisHotkey In !,#,^,+,{,},Enter,Space,Tab,Esc,BS,Del,Ins,Home,End,PgUp,PgDn,Up,Down,Left,Right
SendInput {%k_ThisHotkey%}
else
SendInput %k_ThisHotkey%
;SendInput %ElapsedTime% ; for debugging
}
k_LastHotkey := k_ThisHotkey ; store the current hotkey for next time
k_LastTick := k_ThisTick ; store the current tick for next time
}
return
; ---- other keys that could be filtered (but caused issues on some keyboards)
;LWin::
;RWin::
;LAlt::
;RAlt::