Jump to content
Sign in to follow this  

"check if mouse buttons are down" or "check if window is in moving action"

Recommended Posts

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
   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...

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 by Imbuter2000

Share this post

Link to post
Share on other sites

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>
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.
   If _IsPressed("1B",$dll) Then

Func _Check()
    While _IsPressed("01",$dll) ;Wait untill LMB is not pressed. 
    Local $hWin = WinGetHandle("")
    WinActivate("Java window")
    WinActivate($hWin) ;I'd move this here, restoring the control to the user asap
    Local $sWinText = ClipGet() ;old syntax was wrong
    If StringRegExp($sWinText,"text I want") then MsgBox(0,"","TEXT FOUND!")

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.

Share this post

Link to post
Share on other sites

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?

Share this post

Link to post
Share on other sites

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.

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...