qwert Posted March 4, 2009 Share Posted March 4, 2009 I have a simple script that defines a HotKey and then waits (sometimes a long time) for the user to either press it -- or press Esc to exit this key monitoring script. The script is compiled and is essentially this:HotKetSet("[ESC]", "Terminate") While 1 Sleep(10000) WEnd Func Terminate() MsgBox(4, "Escape was pressed", "Exiting", 2) Exit EndFuncWhen the user presses Esc, the script gives the message and, indeed, exits. It will no longer respond to the Esc key. The problem is that Windows Task Manager continues to show Script.exe running.How do I get the Script.exe to actually terminate as part of the Esc/Exit?Thanks for any assistance. Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted March 4, 2009 Moderators Share Posted March 4, 2009 click the message box button Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
qwert Posted March 4, 2009 Author Share Posted March 4, 2009 click the message box button OK, that worked .... but where does that leave me?Do I prompt the user to press that key after they've already pressed Esc?Or do I try some type of Send ... like starting another script just to send a key back to this one?And is this due to the Sleep(10000)? If so, is there a better way to "idle" waiting for a hot key?Thanks for your help. Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted March 4, 2009 Moderators Share Posted March 4, 2009 OK, that worked .... but where does that leave me?Do I prompt the user to press that key after they've already pressed Esc?Or do I try some type of Send ... like starting another script just to send a key back to this one?And is this due to the Sleep(10000)? If so, is there a better way to "idle" waiting for a hot key?Thanks for your help.The last parameter is a timeout for the MsgBox() function. If you are going to use a message box, and they aren't going to use it, and you want it to dissipate after a period of time, then give it a timeout. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
readmedottxt Posted March 4, 2009 Share Posted March 4, 2009 The last parameter is a timeout for the MsgBox() function. If you are going to use a message box, and they aren't going to use it, and you want it to dissipate after a period of time, then give it a timeout.Isn't there a 2 second timeout in there already? Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted March 4, 2009 Moderators Share Posted March 4, 2009 (edited) Isn't there a 2 second timeout in there already?You're absolutely correct, and if it were compiled with SciTe you might even see the issues.HotKeySet("{ESC}", "Terminate") While 1 Sleep(10000) WEnd Func Terminate() MsgBox(4, "Escape was pressed", "Exiting", 2) Exit EndFuncCompare the two. Edit: Just an example of not paying attention to spelling and or how to use functions (you used square brackets when it should have been curly for ESC) and misspelled HotKeySet Edited March 4, 2009 by SmOke_N Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
qwert Posted March 4, 2009 Author Share Posted March 4, 2009 (edited) Isn't there a 2 second timeout in there already?I think I misunderstood that first response. The button I pressed was the one the user would have pressed to make the script perform its main function. It obviously caused the Script.exe to break out of the Sleep(10000) and shutdown completely since the Exit had already take place.So my questions still stand. How am I supposed to "off" the Script.exe?P.S. My apology for the slopping script code example in my post. The script was on another machine so I couldn't cut and paste like I usually do -- and it was late. Sorry for the confusion. Edited March 4, 2009 by qwert Link to comment Share on other sites More sharing options...
readmedottxt Posted March 4, 2009 Share Posted March 4, 2009 You're absolutely correct, and if it were compiled with SciTe you might even see the issues.HotKeySet("{ESC}", "Terminate") While 1 Sleep(10000) WEnd Func Terminate() MsgBox(4, "Escape was pressed", "Exiting", 2) Exit EndFuncCompare the two. Edit: Just an example of not paying attention to spelling and or how to use functions (you used square brackets when it should have been curly for ESC) and misspelled HotKeySet Spotted now, cheers Link to comment Share on other sites More sharing options...
MrMitchell Posted March 4, 2009 Share Posted March 4, 2009 Not sure exactly what the purpose is, but I had something similar. Here's how I did it: Set $flag to 1 then when you hit {ESC} it will call Terminate and do whatever needs to be done, if anything, after the While loop. HotKeySet("{ESC}", "Terminate") Dim $flag=1 While $flag WEnd ;Do whatever MsgBox("0", "Info", "User hit ESC key") Exit Func Terminate() $flag=0 EndFunc I'm still learning.... Good luck! Link to comment Share on other sites More sharing options...
qwert Posted March 4, 2009 Author Share Posted March 4, 2009 Set $flag to 1 then when you hit {ESC} it will call Terminate and do whatever needs to be done, if anything, after the While loop.Thanks. I think I see how that will work. I'll try it.BTW, I've reread the help sections on "GUI Reference - OnEvent Mode" and associated topics. I don't see anything that addresses this phenomena of "lingering script executables". Is it normal? If not, can someone explain what my script is doing to cause it? Link to comment Share on other sites More sharing options...
qwert Posted March 19, 2009 Author Share Posted March 19, 2009 ... phenomena of "lingering script executables". Is it normal? If not, can someone explain what my script is doing to cause it?For anyone who finds this thread:Apparently, it IS "normal" for a script to linger on in a sort of zombie state -- it won't respond, but it's still an active windows task -- if you don't disable the hotkeys that you defined before exiting.For example, if you use the Escape button, disabling it with with HotKeySet("{ESC}") solves the problem. The task disappears from the windows task monitor immediately upon Exit.If someone has a better solution, I'd like to hear it -- but, otherwise, I'm considering this solved. Link to comment Share on other sites More sharing options...
Richard Robertson Posted March 19, 2009 Share Posted March 19, 2009 I can not confirm this behavior. I just ran a script with a wait loop and a hotkey that called exit. The script ended correctly. Link to comment Share on other sites More sharing options...
qwert Posted March 19, 2009 Author Share Posted March 19, 2009 I can not confirm this behavior. I just ran a script with a wait loop and a hotkey that called exit. The script ended correctly.Just to clarify: what I'm seeing is that on Windows Task Manager >> Processes the script still shows up as an active task. This is after I've applied the $flag technique mentioned earlier.I'm running XP SP3 and AutoIt v3.3.0.0 Link to comment Share on other sites More sharing options...
Richard Robertson Posted March 19, 2009 Share Posted March 19, 2009 (edited) Yes. I looked at the task manager and my script ended immediately. I only ever have the processes tab open since trying to close "applications" doesn't work when programs are locked up. Edited March 19, 2009 by Richard Robertson Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted March 19, 2009 Moderators Share Posted March 19, 2009 qwert,I can confirm Richard Robertson's result on my machine. Pressing ESC while the compiled script was running resulted in the process ending in TaskManager immediately the MsgBox was clicked or timed out.Autoit 3.3.0.0 and Vista x32.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...
qwert Posted March 19, 2009 Author Share Posted March 19, 2009 I can confirm Richard Robertson's result on my machine.Thanks to you both. Although the change I made (turning off the hotkeys) solved my immediate problem, based on your results, I'm going to take another look to see if I can't isolate some other problem. My runtime script monitors two different keys and for one of them, tests whether a particular task is running. I've observed the condition I reported on four different PCs, including on running Vista. I'll continue to look and will post any new result. 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