Search the Community
Showing results for tags 'same key'.
-
Hi everyone, I would like to share a simple snippet where I use for my hotkey script. I was searching for a solution whereby pressing a same key, I could have different outcome according to the way the key is being pressed. 1) Double tap/press fast (like double click the mouse) - outcome A 2) Long press or HOLD for awhile (2-4 sec) - outcome B #Include <Timers.au3> Global $interval_timer, $counter HotKeySet("{F10}", "_terminate") While 1 Sleep(10) WEnd Func _terminate() Local $itv_timer $itv_timer = _Timer_Diff($interval_timer) $interval_timer = _Timer_Init() ;ConsoleWrite($itv_timer & @CRLF) ;to review the timer difference so I can decide the range to capture double tap sequence If $itv_timer > 100 And $itv_timer < 250 Then $counter = 0 $interval_timer = _Timer_Init() MsgBox("","","double tap detected") Elseif $counter >= 25 Then $counter = 0 $interval_timer = _Timer_Init() MsgBox("","","long press detected") ElseIf $itv_timer < 50 Then $counter = $counter + 1 ConsoleWrite($counter & @CRLF) Else $counter = 0 EndIf EndFunc The trick here is to collect and use the frequency of the hotkey is called, and the time difference between each time the hotkey is being called. My coding style is not efficient and can be such a mess most of the time, any suggestion or better coding are welcome. I hope you find this one helpful.
- 8 replies
-
- long press detection
- double tap fast
-
(and 2 more)
Tagged with: