Move mouse while Sikuli is running?

Asked by Fall

In my startup routine, I start a sikuli to move my mouse cursor to a pop up window and click the "x" button to close it. But the problem is, if I move my mouse, Sikuli won't move to the right place because I have interfered the movement. Is there a way to let Sikuli to lock the mouse movement from the user when it is moving the mouse? Or could it display a prompt window that remind me that I should wait because it is gonna control my mouse? And it would be great if I could set a period that after which the window automatically closes itself so I don't need to close it myself.

Thanks for any help.

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
RaiMan
Solved:
Last query:
Last reply:
Revision history for this message
Best RaiMan (raimund-hocke) said :
#1

No, it is not possible to lock/secure the mouse in any way against interferences by the user.

One thing you can do in all cases is to set
Settings-MoveMouseDelay = 0

which lets the mouse "jump" directly to its end point.

What you can do additionally, is to generally make mouse actions on Locations only, means you should separate the find operation and the mouse action.
find("something.png")
click(getLastMatch())

So you could check directly before, that the mouse is still at its place from the last action, and afterwards, that it is still at the intended location, so it is most probable, that the click has hit the correct location.
find("something.png")
if not mousePos == Env.getMouseLocation(): print "mouse is corrupted by other process or user"
mousePos = getLastMatch().getTargetOffset()
click(mousePos)
if not mousePos == Env.getMouseLocation(): print "mouse is corrupted by other process or user"

You could even add a subprocess, that constantly checks that mouse movements are only the ones intended by the script, so you could pause the script at critical points, until the mouse is free again.

But be aware: Generally, Sikuli scripts are intended to be used without interference by a user and that, if it happens, the situation on the screen usually changes in a way, that might make a script unusable.

Revision history for this message
Fall (fxkill2006) said :
#2

Thanks RaiMan, thanks for the detailed answer, that solved my question.

After checked with latest documentation, I found that to set move mouse delay to 0, the newest argument is changed to "Settings.MoveMouseDelay = 0", note the "." instead of "-".

Revision history for this message
RaiMan (raimund-hocke) said :
#3

Uuuups, I missed the right key sitting in the sun with my laptop ;-)
Thanks for feedback.