Omga4000 Posted August 15, 2011 Posted August 15, 2011 So I've created this script that teminates the script when you press ESC (same script as before) HotKeySet ("{ESC}", "Terminate") Func Terminate() Exit EndFunc Now I tried to add a box that will tell the user that ESC stops the script, However the script doesn't keep on going when the MsgBox is on (until I press OK). There's any way to continue the script whitouth me having to press "OK" in the MsgBox? I've tried the Timeout but it just closes and the window, and that is something I don't want to happen. Here's the little code I did: MsgBox (0, "How To Exit", "Press ESC to Terminate The Script") HotKeySet ("{ESC}", "Terminate") Func Terminate() Exit EndFunc Thank you
pieeater Posted August 15, 2011 Posted August 15, 2011 (edited) try putting "HotKeySet("{ESC}", "Terminate")" above the msgbox Edited August 15, 2011 by pieeater [spoiler]My UDFs: Login UDF[/spoiler]
Omga4000 Posted August 15, 2011 Author Posted August 15, 2011 Hey pieeater, What happens is that now I have to press ESC for the message to appear. After that the script terminates. But I want the message to appear WHILE the script is running, so that people will know how to stop the script.
BrewManNH Posted August 15, 2011 Posted August 15, 2011 MsgBox is a blocking function, which means that it won't continue until it's closed. Use the timeout parameter to have it close automatically after however many seconds that you want it to close. MsgBox ( flag, "title", "text" [, timeout [, hwnd]] ). If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator
Omga4000 Posted August 15, 2011 Author Posted August 15, 2011 Hey BrewManNH, As I've said before: "I've tried the Timeout but it just closes and the window, and that is something I don't want to happen." Alright so I get the problem. It's a blocking function. Is there an alternative function to popup a message box?
hannes08 Posted August 15, 2011 Posted August 15, 2011 You could run a second script that will do nothing than show your MsgBox(es). Not a nice way to do it, but it will work. Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler]
Omga4000 Posted August 15, 2011 Author Posted August 15, 2011 (edited) Hey Hannes123, A smart way I guess, though it's not the nicest one indeed The problem is It's blocking my way. I can't a spot I can place the second script without it getting in my way of the first script. Edited August 15, 2011 by Omga4000
BrewManNH Posted August 15, 2011 Posted August 15, 2011 Hey BrewManNH,As I've said before:"I've tried the Timeout but it just closes and the window, and that is something I don't want to happen."Alright so I get the problem. It's a blocking function.Is there an alternative function to popup a message box?If the code you posted in the first post is all the code you have, it will do exactly that, close after the msgbox is closed. You'll need to post an example of your code that you want to run, that isn't running correctly, otherwise there's no way to fix whatever might be happening. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator
hannes08 Posted August 15, 2011 Posted August 15, 2011 Hey Hannes123,A smart way I guess, though it's not the nicest one indeed Just to do some cosmetics you could do a FileInstall() so you don't need to ship two files. Or you could use a VB function. Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler]
ZacUSNYR Posted August 15, 2011 Posted August 15, 2011 Sounds like you don't need a MsgBox but your own GUI. Something like this? #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Opt("GUIOnEventMode", 1) $hGUI = GUICreate("My Script", 300, 55, -1, -1, $WS_POPUPWINDOW) GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit") HotKeySet ("{ESC}", "_Exit") GUICtrlCreateLabel("Pressing ESCAPE will terminate the script.", 5, 20, 290, 25) GUISetState(@SW_SHOW, $hGUI) While 1 Sleep(10) WEnd Func _Exit() Exit EndFunc
Omga4000 Posted August 15, 2011 Author Posted August 15, 2011 (edited) Hey BrewManNH,Sorry for being unclear. My Fault Let's say for example that I want this script to run in a loop:$cursor = MouseGetCursor () Select Case $cursor = 15 Sleep (10000) MouseClick("left",976,643,1) Sleep (500) Case $cursor = 2 MouseClick("left",976,643,1) Sleep (500) EndSelectWHILE this script is running I want a message box to appear, saying:"Press ESC to terminate the script"I don't want that message box to disappear until the script it terminated.EDIT: ZacUSNYR, seems like you have done it! Now the next problem is I want it to remain on top of everything.I don't want folders or other files to go on top of that.Is it possible? Edited August 15, 2011 by Omga4000
BrewManNH Posted August 15, 2011 Posted August 15, 2011 (edited) I see now, I would use ZacUSNYR's suggestion and make your own GUI instead, and put your code inside the While...Wend loop. Your Terminate() function would be outside of that loop though. This will keep a box up as long as the script is running, and still allow the script to run in the background. EDIT: Use the $WS_EX_TOPMOST extended style setting to keep it on top of other windows. Edited August 15, 2011 by BrewManNH If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator
Omga4000 Posted August 15, 2011 Author Posted August 15, 2011 Now the next problem is I want it to remain on top of everything. I don't want folders or other windows to go on top of the GUI window. Is it possible?
ZacUSNYR Posted August 15, 2011 Posted August 15, 2011 EDIT: Use the $WS_EX_TOPMOST extended style setting to keep it on top of other windows. Now the next problem is I want it to remain on top of everything. I don't want folders or other windows to go on top of the GUI window. Is it possible? You'll want to add that to the GUICreate Example: $hGUI = GUICreate("My Script", 300, 55, -1, -1, $WS_POPUPWINDOW, $WS_EX_TOPMOST)
Omga4000 Posted August 15, 2011 Author Posted August 15, 2011 (edited) This -> Or this -> Melba23s's solutions are just way too smart for me The sedond one you gave me was a pretty nice solution, tough I still need to mess with it a little so it will work for me. For some reason it doesn't accept "$code=0" or "$title = ""," or actually any other statment that he gave in there. Got any idea how to solve that? You'll want to add that to the GUICreate Example: $hGUI = GUICreate("My Script", 300, 55, -1, -1, $WS_POPUPWINDOW, $WS_EX_TOPMOST) TopMost.. Stupid me Thank you!! Edited August 15, 2011 by Omga4000
jvanegmond Posted August 15, 2011 Posted August 15, 2011 For some reason it doesn't accept "$code=0" or "$title = ""," or actually any other statment that he gave in there. Got any idea how to solve that? In this case you must double escape the string. _NoHaltMsgBox(0, "Hi", "Test """"test"""" test") Func _NoHaltMsgBox($code=0, $title = "",$text = "" ,$timeout = 0) Run(@AutoItExe & ' /AutoIt3ExecuteLine "MsgBox(' & $code & ', '''& $title & ''', '''& $text &''',' & $timeout & ')"') EndFunc github.com/jvanegmond
Omga4000 Posted August 15, 2011 Author Posted August 15, 2011 Manadar, May I ask why do I need to double it here?
jvanegmond Posted August 15, 2011 Posted August 15, 2011 (edited) Manadar, May I ask why do I need to double it here? Of course. _NoHaltMsgBox(0, "Hi", "Test """"test"""" test") Makes the string: Test ""test"" test Run(@AutoItExe & ' /AutoIt3ExecuteLine "MsgBox(' & $code & ', '''& $title & ''', '''& $text &''',' & $timeout & ')"') Makes the string: AutoIt.exe /AutoIt3ExecuteLine "MsgBox(0, 'Hi', 'Test ""test"" test', 0)" AutoIt basically turns that in its own memory into a script that works like: Execute("MsgBox(0, 'Hi', 'Test ""test"" test', 0)") So the end result is a string that says: MsgBox(0, 'Hi', 'Test "test" test', 0) It all depends on what the line was started with (a " or a ') and then double escaping is sometimes necessary. Edited August 15, 2011 by Manadar github.com/jvanegmond
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