SebastianGalecki Posted August 2, 2014 Share Posted August 2, 2014 Hello, I'm attempting to write a script that has a couple of buttons (start, stop) and when the user clicks the start button it starts a loop which randomly presses given keyboard key until stop or close button is pressed. The problem is, when I press start loop gets stuck and i must to kill the program to turn it off. Could anyone help me out with this? Here is my code: #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("AutoKeyPress", 325, 213, 238, 182) $Button1 = GUICtrlCreateButton("Start", 8, 152, 145, 49) $Button2 = GUICtrlCreateButton("Stop", 168, 152, 145, 49) $Group1 = GUICtrlCreateGroup("auto e key press ", 8, 8, 305, 137) $Label1 = GUICtrlCreateLabel("press delay 1.5 - 3sec, random", 24, 40, 268, 81) GUICtrlCreateGroup("", -99, -99, 1, 1) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### $key = 'e' $pressdelay = Random(1500, 3000) Do $msg = GUIGetMsg() Select Case $msg = $Button1 While 1 $msg = GUIGetMsg() Send($key) Sleep($pressdelay) If $msg = $Button2 Then ExitLoop EndIf WEnd EndSelect Until $msg = $GUI_EVENT_CLOSE Link to comment Share on other sites More sharing options...
Danp2 Posted August 3, 2014 Share Posted August 3, 2014 Try something like this: $key = 'e' $pressdelay = Random(1500, 3000) $lFlag = False Do $msg = GUIGetMsg() Select Case $msg = $Button1 $lFlag = True Case $msg = $Button2 $lFlag = False EndSelect If $lFlag Then Send($key) Sleep($pressdelay) EndIf Until $msg = $GUI_EVENT_CLOSE You could also use AdlibRegister to fire a function at a given interval. Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
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