Jump to content

detect long key press


Recommended Posts

here you go....  :bye:

#include<Misc.au3>
#include <Timers.au3>

Global $o_ClickCnt = 0

__ExampleA()
Func __ExampleA()
    HotKeySet("a", "__ButtonClick")
    HotKeySet("{ESC}", "__Quit")
    MsgBox(0, "", "Start clicking button 'A'" & @CRLF & _
                  "and Esc to exit")

    Local $iIdleTime
    Local $Xflag = False
    Local $o_ClickTime = 160        ;<<<<<<<< speed adjust

    While 1
        If ($o_ClickCnt = 1) Then
            $iIdleTime = _Timer_GetIdleTime()
            $Xflag = True
        Endif

        If ($Xflag) And ($iIdleTime > $o_ClickTime) Then
            ConsoleWrite("+  Single Key Press ......" & @CRLF)
            $o_ClickCnt = 0
            $Xflag = False
        Endif

        Sleep(10)
    WEnd
EndFunc

Func __ButtonClick()
    Local Static $o_Flag = False
    If $o_Flag Then Return
    $o_Flag = True

    Local Static $o_DClickTimer
    Local $o_ClickTime = 160        ;<<<<<<<< speed adjust
    Local $o_GetTime
    Local $o_GetDCTime
    Local $o_Timer = TimerInit()

    $o_GetDCTime = int(TimerDiff($o_DClickTimer))
    While _IsPressed('41')
        Sleep(10)
    WEnd

    $o_GetTime = int(TimerDiff($o_Timer))
    If ($o_GetTime > $o_ClickTime) And ($o_ClickCnt = 0) Then
        ConsoleWrite("-  Long Key Press......" & @CRLF)
        $o_Flag = False
        Return
    EndIf

    If ($o_GetDCTime <= $o_ClickTime) And ($o_ClickCnt > 0) Then
        ConsoleWrite(">  Double Key Press ......" & @CRLF)
        $o_ClickCnt = 0
        $o_Flag = False
        Return
    EndIf

    $o_ClickCnt += 1
    $o_DClickTimer = TimerInit()
    $o_Flag = False
EndFunc

Func __Quit()
    Exit
EndFunc

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...