CircusMusic Posted November 12, 2009 Posted November 12, 2009 I have a script that polls a PHP script and depending on what the PHP sends back it pops up a MsgBox asking a question. My problem is that it only seems to run the main while loop when the mouse is hovering over the tray icon. As soon as I move the mouse over the tray icon checkForQuestion() runs and then I get the popup (if conditions are met). Since this is for a confirmation I need checkForQuestion() to be run on a regular basis without intervention from the user. expandcollapse popup#include <GUIConstantsEx.au3> #include "WinHTTP.au3" ; From http://www.autoitscript.com/forum/index.php?showtopic=84133 Opt("TrayMenuMode",1) ; Default tray menu items (Script Paused/Exit) will not be shown. Opt("TrayAutoPause",0) $turnon = TrayCreateItem("Turn On") TrayCreateItem("") $turnoff = TrayCreateItem("Turn Off") TrayCreateItem("") $exititem = TrayCreateItem("Exit") TraySetState() While 1 $msg = TrayGetMsg() Select Case $msg = 0 ContinueLoop Case $msg = $turnon turnon() Case $msg = $turnoff turnoff() Case $msg = $exititem ExitLoop EndSelect checkForQuestion() WEnd Exit Func turnon () $LocalIP = "192.168.1.205" $hw_open = _WinHttpOpen() $hw_connect = _WinHttpConnect($hw_open, $LocalIP) $h_openRequest = _WinHttpOpenRequest($hw_connect, "POST", "lightboard/connector.php") $data = "name=Desktop&password=password&action=on" _WinHttpSendRequest($h_openRequest,"Content-Type: application/x-www-form-urlencoded" & @CRLF, $WINHTTP_NO_REQUEST_DATA, StringLen($data), 0) _WinHttpWriteData($h_openRequest, $data) _WinHttpReceiveResponse($h_openRequest) _WinHttpCloseHandle($h_openRequest) _WinHttpCloseHandle($hw_connect) _WinHttpCloseHandle($hw_open) EndFunc Func turnoff () $LocalIP = "192.168.1.205" $hw_open = _WinHttpOpen() $hw_connect = _WinHttpConnect($hw_open, $LocalIP) $h_openRequest = _WinHttpOpenRequest($hw_connect, "POST", "lightboard/connector.php") $data = "name=Desktop&password=password&action=off" _WinHttpSendRequest($h_openRequest,"Content-Type: application/x-www-form-urlencoded" & @CRLF, $WINHTTP_NO_REQUEST_DATA, StringLen($data), 0) _WinHttpWriteData($h_openRequest, $data) _WinHttpReceiveResponse($h_openRequest) _WinHttpCloseHandle($h_openRequest) _WinHttpCloseHandle($hw_connect) _WinHttpCloseHandle($hw_open) EndFunc Func checkForQuestion() #include "WinHTTP.au3" $hOpen = _WinHttpOpen() $hConnect = _WinHttpConnect($hOpen, "192.168.1.205") $hRequest = _WinHttpOpenRequest($hConnect, "GET", "lightboard/connector.php?name=Desktop") _WinHttpSendRequest($hRequest) _WinHttpReceiveResponse($hRequest) If _WinHttpQueryDataAvailable($hRequest) Then ;$header = _WinHttpQueryHeaders($hRequest) $body = _WinHttpReadData($hRequest) If ($body == "Need Confirmation") Then $confirmIt = MsgBox(36, "Dispatch Needs Confirmation", "Do you need a pickup?") If ($confirmIt == 6) Then turnon() ElseIf ($confirmIt == 7) Then turnoff() EndIf EndIf EndIf _WinHttpCloseHandle($hRequest) _WinHttpCloseHandle($hConnect) _WinHttpCloseHandle($hOpen) EndFunc
marc0v Posted November 12, 2009 Posted November 12, 2009 In your script 'ContinueLoop' goes back to the 'While 1' statement if no tray message is received ($msg = 0), and checkForQuestion() is therefore not executed if no tray message is received (there are some MOUSEOVER/MOUSECLICK messages, with negative values, that triggers your checkForQuestion()) ContinueLoop means in fact Go_To_Loop_Testing_Line (The 'While 1' line) main loop should be (with a sleep, possibly, to reduce CPU/Network usage) : While 1 $msg = TrayGetMsg() Select Case $msg = $turnon turnon() Case $msg = $turnoff turnoff() Case $msg = $exititem ExitLoop EndSelect Sleep(250) checkForQuestion() WEnd
CircusMusic Posted November 16, 2009 Author Posted November 16, 2009 Thanks for the info! It's good to know that is what's going on when it hits the ContinueLoop Thanks for the tip on adding a sleep... I was going to add one but had waited till I got it working correctly =)
GEOSoft Posted November 16, 2009 Posted November 16, 2009 You don't need the sleep in message loops.To quote the help fileRemarksThis function automatically idles the CPU when required so that it can be safely used in tight loops without hogging all the CPU.There is already a delay to idle the CPU. George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!"
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