[Java] can not use mouseMove() --- workaround: use hover() instead

Asked by xlzdew

when I use Sikuli Scripts in JAVA programs, the method mouseMove(Env.getMouseLocation().offset(50, 50)) can not be used.
I want to handle an scroll bar by using sikuli scripts, and refer to example in the page of http://sikuli.org/docx/tutorials/resize/resize.html
It works fine when I write scripts in Sikuli IDE, but get an following error message of "The method mouseMove(Location) is undefined for the type Screen" when I using sikuli scripts in java programes.
following are some of my code
            Match mTL=screen.find(element_left);
            Match mTR=mTL.nearby(200).right().find(element_right);
            Region mBR=mTR.below().find(element_target);
            screen.mouseDown(screen.hover(mBR.getCenter().offset(targetOffsetX,targetOffsetY)));

            screen.mouseMove(Env.getMouseLocation().offset(50, 50));
            screen.mouseUp(1);
Can you help me?

Thanks in advance.

Question information

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

This is one of the many inconsistencies between the Python level API and the Java API (but they are working on that).

--- workaround:
use hover() instead
(mouseDown() on Python level simply calls hover() on the Java level ;-)

Revision history for this message
xlzdew (xlzdewgood) said :
#2

Thanks for quickly response.
I try using hover() instead of mouseMove(), it seems the mouse can move as expected now. But the method mouseDown(Button.LEFT) and mouseUp() still can not work, so it can not press and hold left button , then let the scroll bar move.
Following is my updated code. The code mouseDown(Button.LEFT) get an error message of "Button.LEFT can not resolved". The code mouseUp() get an error message of "The method mouseUp(int) in the type Region is not applicable for the arguments ()"

Match mTL=screen.find(element_left);
Match mTR=mTL.nearby(100).right().find(element_right);
screen.mouseDown(Button.LEFT);
screen.hover(mTR.getCenter().offset(2,10));
screen.hover(Env.getMouseLocation().offset(targetOffsetX, targetOffsetY));
screen.mouseUp();

Is my understanding for your comment correct? And can you help to resolve problems above?
Thanks

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

sorry, for having been blind :-(

the class Button is not available on the Python side.

As already mentioned, that is under repair now (hope for rc3)

meanwhile use this (from Python class Button):

from java.awt.event import InputEvent

# has to be translated to Java ;-)
LEFT = InputEvent.BUTTON1_MASK
MIDDLE = InputEvent.BUTTON2_MASK
RIGHT = InputEvent.BUTTON3_MASK

Revision history for this message
Tsung-Hsiang Chang (vgod) said :
#4

The Button and Key classes have been moved to the Java layer in the latest build (r758), which can be downloaded at http://sikuli.org/download.shtml#last-build
Feel free to give it a try.

Revision history for this message
Tsung-Hsiang Chang (vgod) said :
#5

btw, mouseMove is also available in Java in r758.

Revision history for this message
xlzdew (xlzdewgood) said :
#6

Thank you so much. It works fine now.