Sign in to follow this  
Followers 0
OneManPen

TrayMenu While loop fails

3 posts in this topic

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.

;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

Share this post


Link to post
Share on other sites



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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0