Advertisement
zxvf

KeybounceFilter KeybounceFilter.ahk copy

Jan 18th, 2014
1,848
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; Keyboard Debouncer -- by debouncer
  2. ; (Note: I made a few modifications, marked with ; MODIFY)
  3. ; http://www.autohotkey.com
  4. ; This script addresses a problem in some laptops where the keyboard
  5. ; "bounces", resulting in doubled keystrokes (sometimes tripled in
  6. ; really bad cases). Because the keystrike repeat is usually very
  7. ; fast, it can be detected and filtered out. The filter window is
  8. ; set by the first command-line argument, in milliseconds. (If left
  9. ; blank, it defaults to 40 msec.) Set it longer for better filtering
  10. ; of bounces, but just shorter than your desired auto-repeat rate.
  11. ;
  12. ; All primary keys are bounce-filtered with their shifts, but not their
  13. ; Alt, Ctrl, or Win variants (feel free to add them if you really need
  14. ; to have them). The num-keypad keys are also not filtered.  All
  15. ; movement keys (including Enter, BS, Del, Esc) are filtered with no
  16. ; variants. Shift, Ctrl, Alt and Win are not filtered. Keys that are
  17. ; not filtered are passed through (i.e. no hotkeys are assigned to
  18. ; them).
  19. ; Credit goes to Jon for his KeyboardOnScreen script, where I learned
  20. ; the handy trick of assigning hotkeys from the ASCII table in a loop.
  21.  
  22. ;SteelSeries, any double-sending or triple-sending, bouncing keyboards where inherent debouncing is failing.
  23. ;Download autohotkey, save this file as KeybounceFilter.ahk, and then run KeybounceFilter.ahk to use this debouncer.
  24.  
  25.  
  26. ; ---- setups
  27. #UseHook On
  28. ;Capslock::LShift
  29.  
  30.  
  31. ; ---- initialize parameters
  32. if (%0% > 0)
  33.     k_TimeThreshold = %1%
  34. else
  35.     k_TimeThreshold = 50
  36. ;k_TimeThreshold = 1000  ; for debugging
  37.  
  38.  
  39. ; ---- initialize variables
  40. k_LastHotkey = 0
  41. k_LastTick := A_TickCount
  42.  
  43.  
  44. ; ---- Set all keys as hotkeys. See www.asciitable.com
  45. k_ASCII = 33
  46. Loop
  47. {
  48.     Transform, k_char, Chr, %k_ASCII%
  49.  
  50.     Hotkey, %k_char%, k_KeyPress
  51.  
  52.         if ((k_char Not In +,^)  AND  (k_ASCII != 123  AND k_ASCII != 125))
  53.     {
  54.         Hotkey, +%k_char%, k_KeyPress       ; shift
  55.         ; Hotkey, ^%k_char%, k_KeyPress     ; control
  56.         ; Hotkey, !%k_char%, k_KeyPress     ; alt
  57.         ; Hotkey, #%k_char%, k_KeyPress     ; win
  58.     }
  59.  
  60.     if k_ASCII = 64
  61.         k_ASCII = 91
  62.     else if k_ASCII = 126
  63.         break
  64.     else
  65.         k_ASCII++
  66. }
  67. return
  68.  
  69. ; ---- End of auto-execute section.
  70.  
  71.  
  72. ; ---- When a key is pressed by the user, send it forward only if it's not a "bounce"
  73. ; ---- A "bounce" is defined as: "key is same as last"  AND  "time since last key is very short"
  74. Enter::
  75. Space::
  76. Tab::
  77. Esc::
  78. BS::
  79. Del::
  80. Ins::
  81. Home::
  82. End::
  83. PgUp::
  84. PgDn::
  85. Up::
  86. Down::
  87. Left::
  88. Right::
  89. k_KeyPress:
  90. {
  91.     k_ThisHotkey := A_ThisHotkey        ; grab the current hotkey
  92.     k_ThisTick := A_TickCount       ; grab the current tick
  93.     ElapsedTime := k_ThisTick - k_LastTick  ; time since last hotkey (ticks)
  94.    
  95.     k_TimeThresholdM := k_TimeThreshold ; MODIFY
  96.     if (k_ThisHotkey = "U")
  97.     {
  98.         k_TimeThresholdM := 150
  99.     }
  100.  
  101.     if (ElapsedTime > k_TimeThresholdM  ||  k_ThisHotkey <> k_LastHotkey) ; MODIFY
  102.     {
  103.         if k_ThisHotkey In !,#,^,+,{,},Enter,Space,Tab,Esc,BS,Del,Ins,Home,End,PgUp,PgDn,Up,Down,Left,Right
  104.             SendInput {%k_ThisHotkey%}
  105.         else
  106.             SendInput %k_ThisHotkey%
  107.         ;SendInput %ElapsedTime%  ; for debugging
  108.     }
  109.  
  110.     k_LastHotkey := k_ThisHotkey    ; store the current hotkey for next time
  111.     k_LastTick := k_ThisTick    ; store the current tick for next time
  112.  
  113.     k_TimeThresholdM := k_TimeThreshold ; MODIFY
  114. }
  115. return
  116.  
  117. ; ---- other keys that could be filtered (but caused issues on some keyboards)
  118. ;LWin::
  119. ;RWin::
  120. ;LAlt::
  121. ;RAlt::
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement