OneManPen Posted December 1, 2011 Share Posted December 1, 2011 I'm writing an auto response script for a chat program and am using TrayMenu as a means of control. I started using AutoIT 2 days ago and I'm sure I'm just making a rookie mistake. The problem is when I use a loop in a Case command for a TrayMenu it won't get out of the loop and I can't quite figure out how to make it check if the option has changed. Thanks in advance for any help. expandcollapse popup;Set the options and icons #NoTrayIcon Opt("WinTitleMatchMode",2) Opt("TrayMenuMode",1) TraySetIcon("off.ico") ;Set and declare the tray items $on = TrayCreateItem("Turn AFK reply on") TrayCreateItem("") $off = TrayCreateItem("Turn AFK reply off") TrayCreateItem("") $exit = TrayCreateItem("Exit") TraySetState() TrayItemSetState($off, 1) ;Tray loop While 1 $msg = TrayGetMsg() Select Case $msg = 0 ContinueLoop ;ON Case $msg = $on TraySetIcon("on.ico") $msg=$on TrayItemSetState($off, 4) ;Can't get out of this loop once it starts While $msg=$on MsgBox(0, "", "I'm in the Loop") WinWait("[CLASS:ChatSkinWnd]", "") MsgBox(0, "", "Xfire found") ControlSend("[CLASS:ChatSkinWnd]", "", "RichEdit20W2", "I am not here right now..., Please leave a message after the beep") ControlSend("[CLASS:ChatSkinWnd]", "", "RichEdit20W2", "{ENTER}") ControlSend("[CLASS:ChatSkinWnd]", "", "RichEdit20W2", "BEEP") ControlSend("[CLASS:ChatSkinWnd]", "", "RichEdit20W2", "{ENTER}") $previoustext = ControlGetText("[CLASS:ChatSkinWnd]", "", "RichEdit20W1") $currenttext = ControlGetText("[CLASS:ChatSkinWnd]", "", "RichEdit20W1") while $previoustext == $currenttext MsgBox(0, "", "Derp stuck") $currenttext = ControlGetText("[CLASS:ChatSkinWnd]", "", "RichEdit20W1") WEnd ControlSend("[CLASS:ChatSkinWnd]", "", "RichEdit20W2", "I am not here right now..., Please leave a message after the beep") ControlSend("[CLASS:ChatSkinWnd]", "", "RichEdit20W2", "{ENTER}") ControlSend("[CLASS:ChatSkinWnd]", "", "RichEdit20W2", "BEEP") ControlSend("[CLASS:ChatSkinWnd]", "", "RichEdit20W2", "{ENTER}") WEnd $msg=$off TrayItemSetState($on, 4) ;OFF Case $msg = $off TraySetIcon("off.ico") $msg=$off TrayItemSetState($on, 4) ;EXIT Case $msg = $exit ExitLoop EndSelect WEnd Exit Link to comment Share on other sites More sharing options...
FaridAgl Posted December 2, 2011 Share Posted December 2, 2011 1. On line 27 you enter a new Loop and you will never exit this loop coz there is no way out. 2. WinWait("[CLASS:ChatSkinWnd]", "") = When the script reached to this line will stop here and wait for ... While it's stopped here it means your loop is stopped so your script cannot react to user's input ( even if he click on exit item ). 3. You have another While loop at line 38, once script reached this line it will goes trough this Loop and your script cannot react to User's input. You can use TrayGetMsg() inside all of your loops to ensue User's inputs will be reacted. To solve the WinWait() problem to something like this: Do Sleep(1000) Until WinWait("[CLASS:ChatSkinWnd]", "", 1) And of course you need to use TrayGetMsg() inside this Loop as well as others. http://faridaghili.ir Link to comment Share on other sites More sharing options...
OneManPen Posted December 2, 2011 Author Share Posted December 2, 2011 Sadly, I do not think I understand you. I've tried what you've said for the loops, but it still fails. I think I'm not understanding the point of TrayGetMsg command what it does is check if the options have changed correct? But when I add it to the top of my loop to check if it still doesn't seem to work... I'ma just rewrite the code and replace some of the while loops with if commands. 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