Guest Posted September 28, 2012 Posted September 28, 2012 (edited) I wrote code that if you hold the middle mouse button for more than 3 seconds, will appear msgbox for a one second. * If you continue to hold the middle button after the msgbox, then nothing will happen (this is the part I was working on) Only if you stop holding the middle button and then repeat the action again, then it will happen. The question is - Did I do it right? I mean - good for CPU. Because there might be a way to make it better ... the code: #include <Misc.au3> $dif = 0 $Stimer = True $Pressed = False $dll = DllOpen("user32.dll") While 1 Sleep (100) If _IsPressed("04", $dll) Then ToolTip("Pressed") If $Stimer = True Then $Stimer = False $begin = TimerInit() EndIf $dif = TimerDiff($begin) If $dif > 3000 And $Pressed = False Then $Pressed = True MsgBox(0,"","Action",1) $begin = TimerInit() EndIf Else ToolTip("Not Pressed") If $Pressed = True Then $Pressed = False $begin = TimerInit() Sleep(500) EndIf WEnd Thanks for helpers. Edited September 28, 2012 by Guest
caleb41610 Posted September 29, 2012 Posted September 29, 2012 #include $user32 = DllOpen( "user32.dll" ) While 1 Select Case _IsPressed( "04", $user32 ) Check( ) EndSelect WEnd Func Check( ) $timer = TimerInit( ) While 1 Sleep( 10 ) If TimerDiff( $timer ) >= 3000 AND _IsPressed( "04", $user32 ) Then MsgBox( 0, "", "Action", 1 ) $timer = TimerInit( ) ExitLoop Else ContinueLoop EndIf WEnd EndFunc That's how I would do it. Much less code and it will keep checking even if you hold it down forever. Multi-Connection TCP Server
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now