Jump to content

Strange MouseClick problem


Recommended Posts

So last night I wrote a script to find and image and click on, it work perfectly all night while testing. When I woke up this morning it not longer worked for some reason and I have no idea what couldn't changed. The script still finds the image, and right after I post a msgbox to make sure it hits that line of code and returns x,y, but the mouse click never fires

It does however fire once if I click back to Scite? But only once since the window is not longer active, it's almost as if there is a setting in Scite that needs focus? Or maybe the window is all of a sudden blocking automated mouse clicks somehow?

Any ideas?

#include <ImageSearch.au3>
Opt("MouseCoordMode", 1)

$WinName = "TestWindow"
$ImageLoc = "z:\dev\Images\TestImage.png"

HotKeySet("{F2}", "ClickImage")
HotKeySet("x", "Stop") 

$X= 0
$Y= 0

Main()

Func Main()
   while 1
      sleep(10)
      IF WinActive($WinName) Then
         ClickImage()
      EndIf
   wend
EndFunc

Func ClickImage()

  $result = _ImageSearch($ImageLoc ,1,$X,$Y,5)
   IF $result=1 Then
      MsgBox(0, "", "Found Image at" & $X& ":"& $Y)
      MouseMove($X, $Y)
      MouseClick("left")
   EndIf
   Sleep(100)
EndFunc


Func Stop() ;to allow the script to stop
    Exit
EndFunc

 

Edited by Nezoic
Link to comment
Share on other sites

Well I just figure out that it IS only when the window is active that non of the mouse click functions work.

I made another function that just moves the mouse and attached it to a hot key which works unless this particular window is active. Very strange.

Link to comment
Share on other sites

Thanks for the replies

I put the message box in just as a test to make sure it was getting to that line of code. It happens with or without it. I also tried other MouseCoordMode options and it's the same result. The click only works whenever that window does NOT have focus / is active. If I click on another window or the desktop then it runs.

I'm assuming there is something in that window that blocks calls to mouse functions, I may need to try the api route with SendMessage / PostMessage.

Link to comment
Share on other sites

The reason I suggested it is that when you have a problem with window focus, then using ConsoleWrite would be better for trouble shooting than using msgbox which will take focus until clicked. Although it appears unrelated to your problem things like that might sometimes affect how the script runs.

. . . maybe the window is all of a sudden blocking automated mouse clicks somehow?

 

Perhaps this is true.

Edited by czardas
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...