Here's what I tried:
Screen screenWithCalendarField = new Screen();
Match calendar = new Match();
try{
calendar = screenWithCalendarField.find(new File("D:\\Sikuli\\CalendarField.png").getAbsolutePath());
}
catch(Exception e){
}
calendar.hover();
delay(5)
calendar.mouseMove(25, 0)
delay(10)
calendar.click();
The mouse moves as expected (25 pixels right from the match), but then it moves back and the click is still performed at the location of the match.
What should I use to have the click done 25 pixels right from the match?
This is RaiMan from SikuliX.
since calendar
is a Match, a click()
will always click at the location, that is currently stored with the match (the center in your case). mouseMove()
only moves the mouse, but does not change the stored location in the match.
To click at the current mouse position instead of calendar.click()
use screenWithCalendarField.click(Mouse.at())
.
You might as well use calendar.click(Mouse.at())
, but using the Screen class is clearer, since the current mouse position is in the coordinates of the screen anyway.
If the offset you want to click at is known from the beginning, you should use the Pattern class to define an object to search, since it allows to set an offset with the image to search for.
So this would be my version (simplified to show the basics):
Screen scr = new Screen;
String image = "D:\\Sikuli\\CalendarField.png";
Pattern pattern = new Pattern(image).targetOffset(25, 0);
Match calendar = scr.exists(pattern, 0); //exists() avoids exception handling.
if (offset != null) calendar.click();
else doSomethingIfNotFound(pattern); //doSomethingIfNotFound to be defined ;-)
Hope it helps.