Imbuter2000 Posted June 25, 2011 Share Posted June 25, 2011 (edited) I need to check the text in a windows in background every 10 seconds until it finds a certain text, leaving the user to do other things on PC... Unfortunately this window is of a Java program and I saw that AutoIT (or Windows "control" technology...) is unable to read the text contained in this window as a "control", in background, like instead for example I can do with other apps like Notepad. The only thing I found I can do to read the text is this window is to focus this window and send a CTRL+C (to pass it to clipboard). I made this cycle: While 1=1 do ; endless loop sleep(10000) ; for doing a check every 10 seconds... $handle = WinGetHandle("") ; reads the handle of the last window in focus, to restore it focus and the end of the following commands blockinput(1) ; I temporarily block keyboard & mouse to avoid user interference with the following two commands WinActivate("Java window") ; sets focus to Java window to check send("^c") ; sends CTRL+C blockinput(0) ClipGet($windowtext) ; reads clipboard and put the text into variable $windowtext if stringregexp($windowtext,"text I want") then msgbox(0,"","TEXT FOUND!") ; alerts when wanted text is found WinActivate($handle) ; restore the focus to the last window in focus, to let the user continue his work on PC... WEnd It works well most of the times: it sleeps for 10 seconds then takes only an instant to check the Java window with CTRL+C. The main exception/disturbance is that when, for example, the check is executed while the user is moving a window by dragging the title bar with mouse left button down, the moving action is unwantedly interrupted. To avoid this disturbance, how can I check the status of the mouse buttons (check if any mouse buttons are down) or the status of a window (check if (any) window is in moving action!) to tell to my script to jump the execution in this cases? Edited June 25, 2011 by Imbuter2000 Link to comment Share on other sites More sharing options...
Tvern Posted June 25, 2011 Share Posted June 25, 2011 You can check the active window to see if a drag action is active, but I think it's far simpler and just as effective to just wait untill the LMB is not pressed before doing the actions. #include <Misc.au3> AdlibRegister("_Check",10000) Global $dll = DllOpen("user32.dll") While 1 ;no "do" after While, just something that evaluates to True for as long as the loop has to run. Sleep(10) If _IsPressed("1B",$dll) Then DllClose($dll) AdlibUnRegister("_Check") Exit EndIf WEnd Func _Check() While _IsPressed("01",$dll) ;Wait untill LMB is not pressed. Sleep(10) WEnd Local $hWin = WinGetHandle("") BlockInput(1) WinActivate("Java window") Send("^c") WinActivate($hWin) ;I'd move this here, restoring the control to the user asap BlockInput(0) Local $sWinText = ClipGet() ;old syntax was wrong If StringRegExp($sWinText,"text I want") then MsgBox(0,"","TEXT FOUND!") EndFunc You could still play around with ControlSend, but just leave the control parameter blank. The keystrokes will usually be picked up by the control that has focus in that window. I know I wouldn't want to work on a PC that screws around with my control and windows every ten seconds. Link to comment Share on other sites More sharing options...
Imbuter2000 Posted July 1, 2011 Author Share Posted July 1, 2011 Great Tvern, your code works! thanks for it! I also played around with ControlSend with black control parameter like you said and wow, it works! the only problem is that it works only if that window (destination of ControlSend action) is focused so I still need to precede the ControlSend command with Winactivate or Controlshow to make it works... and therefore it still "screws around with my control and windows every ten seconds"... Interestingly it also works if I do a Controlhide (that hides the window!) before the Winactivate/Controlshow + Controlsend but the Winactivate/Controlshow action still removes the focus from the current focused window... I found no ways to avoid removing the focus from the current focused window while making the ControlSend work... ControlSetText can only change the title of the window... Any other ideas? Link to comment Share on other sites More sharing options...
Tvern Posted July 1, 2011 Share Posted July 1, 2011 Any other ideas?Not really. Unless the program you are trying to automate is available for us to test with, it'll be tough to come up with solutions, if it's even possible to automate that program without giving it focus. 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