Grantson Posted February 1, 2011 Share Posted February 1, 2011 Hi Guys I have done a search but have come up blank so my appologies if this has been asked before I have a script with a gui and various buttons, one of the buttons installs a printer driver. The script uses a series of winwaitactive statements and controlsend/control click lines to step through the add printer driver wizard. I am having a poblem that if the printer driver is already installed the printer properties are displayed and my script sticks. Im looking for a method to exit the case statement (ideally via a hotkey) so that the application does not need to be terminated and relaunched Thanks Grant Link to comment Share on other sites More sharing options...
JohnOne Posted February 1, 2011 Share Posted February 1, 2011 Without code to look at its a shot in the dark. I imagine the prperty dialogue appears after clicking a certain button, or performing a certain action. At that point, its a good Idea to check if the dialogue exists before trying to continue. Something like... Func _myFunc() ClickButton() If WinExists("Property Dialogue") Then WinClose("Property Dialogue") Return Else ;continue your code EndIf EndFunc 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...
Mat Posted February 1, 2011 Share Posted February 1, 2011 I think what he means is that he wants a hotkey that will manually terminate the script. I would recommend reading through this tutorial as it seems to be exactly what you are looking for, and I know that the tutorial (like all by Melba23) is very good to learn from. AutoIt Project Listing Link to comment Share on other sites More sharing options...
jvanegmond Posted February 1, 2011 Share Posted February 1, 2011 Regarding "Exiting a case statement". Here is one I learned from Valik. 8) Switch 1 Case 1 Do ConsoleWrite("1") Sleep(10) Sleep(10) Sleep(10) Sleep(10) Sleep(10) Sleep(10) Sleep(10) Sleep(10) Sleep(10) Sleep(10) If True Then ; here we decide we want to Exit ExitLoop EndIf ConsoleWrite("2") Sleep(10) Sleep(10) Sleep(10) Sleep(10) Sleep(10) Sleep(10) Until 0 Case 2 EndSwitch ConsoleWrite("3" & @CRLF) Structured goto. And it's not bad. github.com/jvanegmond Link to comment Share on other sites More sharing options...
JohnOne Posted February 1, 2011 Share Posted February 1, 2011 (edited) My guess is something like this is being used Switch $var Case 1 ControlClick() MouseClick() Controlsend() ControlClick() If $this Then $that = $the_other Endif Case 2 ;Blah yada ding dong Case Else ;Whatevr EndSwitch as opposed to Switch $var Case 1 _myfunc() Case 2 ;Blah yada ding dong Case Else ;Whatevr EndSwitch Func _myfunc() ControlClick( MouseClick() ontrolsend() ControlClick() If $this Then $that = $the_other Endif EndFunc EDIT: Did not know you could exit a Switch case with exitloop. I imagine it works with Select also ? Edited February 1, 2011 by JohnOne 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...
Tvern Posted February 1, 2011 Share Posted February 1, 2011 While we're shooting in the dark:It sounds to me like the script gets stuck on a blocking function like WinWaitActive. If this is the case you could set a timeout for that function, or write a function that is functionally identical, but allows to a hotkey to be set like this: (untested)#include <Misc.au3> _WinWaitActiveEx( "SomeTitle", "", 30*1000, "23") ;This would wait for a windows with a title starting with "SomeTitle" to become active for a maximum of 30 seconds, or untill the "End" key is pressed by the user. ;Uses the combined parameters of WinWaitActive and _IsPressed. ;The helpfile for these functions applies. Func _WinWaitActiveEx($vTitle, $sText = "", $iTimeOut = 0, $sHexKey = "", $vDLL = "user32.dll") Local $hWnd, $iTimer = TimerInit() While 1 $hWnd = WinActive($vTitle, $sText) ;WinActive is the non-blocking version of WinWaitActive. If $hWnd Then Return $hWnd ;if the window was active, the handle is returned like WinWaitActive would do. If $iTimeOut And TimerDiff($iTimer) >= $iTimeOut Then Return SetError(1,0,0) ;if the function times out: 0 is returned like WinWaitActive would do and @error is set to 1. If $sHexKey And _IsPressed($sHexKey, $vDLL) Then ;check for interrupting keypress While _IsPressed($sHexKey, $vDLL) ;wait for the key to be released, before exiting. This way you won't interrupt the next _WinWaitEx by mistake Sleep(10) WEnd Return SetError(2,0,0) ;Return 0 and set @error to 2. EndIf Sleep(10) WEnd EndFuncOther WinWait...() functions can easily be replaced using this function as a template. (You just have to replace WinActive with, for instance, WinExists to replace WinWait.) Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 1, 2011 Moderators Share Posted February 1, 2011 JohnOne,Did not know you could exit a Switch case with exitloopYou cannot. Look carefully at the code and you will see that it exits a Do...Until loop within the Case structure. It is still a clever trick and is now in my Snippets folder. 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...
jvanegmond Posted February 1, 2011 Share Posted February 1, 2011 (edited) Did not know you could exit a Switch case with exitloop.I imagine it works with Select also ?You can't. I put a Do Until around it which only executes once. If you want to exit early, you exit from the loop with exitloop and the program ends at the end of the case. As I said, it's structured goto.Edit: Melba beat me. I cannot delete posts. Edited February 1, 2011 by Manadar github.com/jvanegmond Link to comment Share on other sites More sharing options...
JohnOne Posted February 1, 2011 Share Posted February 1, 2011 Cheers guys. Screen blindness again. 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...
AdmiralAlkex Posted February 1, 2011 Share Posted February 1, 2011 Good idea Manlik! .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface 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