XTensionX Posted June 26, 2010 Share Posted June 26, 2010 hi everyone, i am having some problem with my GUI i have 2 buttons on it and when i press 1 of them the GUI froze and nothing will work, but the script for that button i press continues could any help me solve this problem please here is my code: #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> Global $Form1_1 = GUICreate("EXE", 314, 160) Global $Button1 = GUICtrlCreateButton("button1", 176, 32, 113, 33, $WS_GROUP) Global $Button2 = GUICtrlCreateButton("button2", 176, 80, 113, 33, $WS_GROUP) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 while 1 ControlSend("[CLASS:Notepad]", "", "Edit1", "This is a line of text") sleep(2000) WEnd Case $Button2 while 1 ControlSend("[CLASS:Notepad]", "", "Edit1", "TESTTT") Sleep (32000) WEnd EndSwitch WEnd thanks Link to comment Share on other sites More sharing options...
BrettF Posted June 26, 2010 Share Posted June 26, 2010 Keep in mind that AutoIt is single threaded. That means realistically only one thing will be happening at any given moment. Armed with that knowledge, what line would stop everything after pressing the button? Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version! Link to comment Share on other sites More sharing options...
XTensionX Posted June 26, 2010 Author Share Posted June 26, 2010 (edited) Keep in mind that AutoIt is single threaded. That means realistically only one thing will be happening at any given moment. Armed with that knowledge, what line would stop everything after pressing the button?the wend? Edited June 27, 2010 by XTensionX Link to comment Share on other sites More sharing options...
BrettF Posted June 27, 2010 Share Posted June 27, 2010 Well that does make it endless... That and the sleep for 32 seconds... Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version! Link to comment Share on other sites More sharing options...
martin Posted June 27, 2010 Share Posted June 27, 2010 the wend? Yes..ish. When you press a button your script goes into the while/wend loop and stays there going round and round. In the loops the only thing the script is doing is what you tell it to do, ie send a string to NotePad and wait for 2 seconds or 32 seconds. To respond to anything it needs to be looking out for other things. If someone presses a button then the script will only find out by seeing what the result of GuiGetMsg is, so you you could make your loop change from while 1 send... sleep... Wend to while GuiGetMsg <> -3 ;while the close button is not clicked send... sleep.. wend Then it would respond to the window being closed, except that there would be a big delay sometimes because the script is sleeping so much, and it still doesn't respond the clicks on other things. This means that you need a different approach for your send bits. One method that helps in this situation is the way of responding to events like a click on a button by using a mode of operation for the script called GuiEventMode. Since I assume you are just starting with all this then I suggest you keep that in mind but leave it for the moment and understand ways using the GuiGetMsg approach which you are already using. So what's needed is something like this While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 ;set up something which sends a line of text every 2 seconds ;but lets the script carry on and do other things Case $Button2 ;set up something which sends a line of text every 32 seconds ;but lets the script carry on and do other things EndSwitch WEnd There is a way of dealing with that sort of thing built into AutoIt. Look up AdlibRegister. You can also use timers (look up _Timer_setTimer) but AdlibRegister is the best way to start I think. If you get stuck then, as you see, there are willing helpers here. Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
Zedna Posted June 27, 2010 Share Posted June 27, 2010 (edited) Also in these situations there is good approach to replace Sleep() command by TimerInit()/TimerDiff()to be possible to cancel desired waiting cycles. Edited June 27, 2010 by Zedna Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
XTensionX Posted June 27, 2010 Author Share Posted June 27, 2010 Well that does make it endless... That and the sleep for 32 seconds... Yes..ish. When you press a button your script goes into the while/wend loop and stays there going round and round. In the loops the only thing the script is doing is what you tell it to do, ie send a string to NotePad and wait for 2 seconds or 32 seconds. To respond to anything it needs to be looking out for other things. If someone presses a button then the script will only find out by seeing what the result of GuiGetMsg is, so you you could make your loop change from while 1 send... sleep... Wend to while GuiGetMsg <> -3 ;while the close button is not clicked send... sleep.. wend Then it would respond to the window being closed, except that there would be a big delay sometimes because the script is sleeping so much, and it still doesn't respond the clicks on other things. This means that you need a different approach for your send bits. One method that helps in this situation is the way of responding to events like a click on a button by using a mode of operation for the script called GuiEventMode. Since I assume you are just starting with all this then I suggest you keep that in mind but leave it for the moment and understand ways using the GuiGetMsg approach which you are already using. So what's needed is something like this While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 ;set up something which sends a line of text every 2 seconds ;but lets the script carry on and do other things Case $Button2 ;set up something which sends a line of text every 32 seconds ;but lets the script carry on and do other things EndSwitch WEnd There is a way of dealing with that sort of thing built into AutoIt. Look up AdlibRegister. You can also use timers (look up _Timer_setTimer) but AdlibRegister is the best way to start I think. If you get stuck then, as you see, there are willing helpers here. Also in these situations there is good approach to replace Sleep() command by TimerInit()/TimerDiff() to be possible to cancel desired waiting cycles. thanks for the help guys i wanted my button to continuosly sending some test to a control, i tried replacing while 1 ControlSend("[CLASS:Notepad]", "", "Edit1", "line ") Sleep (2000) wend to while GuiGetMsg <> -3 ControlSend("[CLASS:Notepad]", "", "Edit1", "line ") Sleep (2000) wend but the GUI closes itself after I press Button 1 and that wouldn't send the text repeatedly is it possible to make Button 1 sends a text to a control continuosly every 2 seconds and having my Button 2 be able to do other things while button 1 is sending the text? thanks for any hep guys, i really appreciate it Link to comment Share on other sites More sharing options...
BrettF Posted June 27, 2010 Share Posted June 27, 2010 Call it fix the errors or something. $SENDIT = False $timer = TimerInit While 1 If ($SENDIT = TRUE) AND (TimerDiff ($timer) >= 2000) Then Send stuff EndIf Switch GUIGetMsg () Case -3 Exit Case $button1 $SENDIT = True EndSwitch WEnd Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version! 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