Mhzfrm Posted February 16, 2013 Share Posted February 16, 2013 help please. i want this program . when i press 7 num this program call sloop function. and when i press a .the program exit from sloop function and the main program still running. my problem is. i can't exit loop from sloop function. thanks #include <misc.au3> $dll = DllOpen("user32.dll") while 1 if _IsPressed(67) then ;numeric key 7 While _IsPressed("67", $dll) Sleep(10) WEnd sloop() EndIf WEnd Func sloop() while 1 Send("{1}") sleep(5000) send("{2}") sleep(5000) if _IsPressed(41) then ; press a and exit loop and back to main program ExitLoop EndIf WEnd EndFunc Link to comment Share on other sites More sharing options...
JohnOne Posted February 16, 2013 Share Posted February 16, 2013 Because you have to have key pressed at exact moment between sleeps try it, keep a pressed for at 10 secons max and will exit. use a hotkey. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 16, 2013 Moderators Share Posted February 16, 2013 Mhzfrm,You are only checking for the "a" key being pressed every 10 seconds because of the Sleep commands - that makes you think that it is never pressed. Try using a function that checks all the time like this: #include <Misc.au3> $dll = DllOpen("user32.dll") While 1 If _IsPressed("67", $dll) Then ;numeric key 7 While _IsPressed("67", $dll) Sleep(10) WEnd ConsoleWrite("sloop in" & @CRLF) sloop() ConsoleWrite("sloop out" & @CRLF) EndIf Sleep(10) WEnd Func sloop() While 1 ; Send If _Sleep_Ex(5000) Then ExitLoop ; Send If _Sleep_Ex(5000) Then ExitLoop WEnd EndFunc ;==>sloop Func _Sleep_Ex($iDelay) $iBegin = TimerInit() Do If _IsPressed("41", $dll) Then ; press a and exit loop and back to main program Return True EndIf Sleep(10) Until TimerDiff($iBegin) > $iDelay Return False EndFuncPlease ask if anything is unclear. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Mhzfrm Posted February 16, 2013 Author Share Posted February 16, 2013 yes yes yes. thanks you so much melba23 and johnone. problem solved .thanks thanks 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