[1.1.4] Mac: [error] checkMousePosition reports 1 pixel off

Asked by Chris Kosieracki

1.1.4-SNAPSHOT-#325-2019-07-13_10:11/Mac10.14.5/Java8(64)1.8.0_73-b02
I was running the Sikulix build from 2018-12-14_08:11 without this problem. After upgrading to build 325, I am now getting many checkMousePosition errors when running in the IDE.
I have both Java and the tested app checked in the Privacy settings to allow them to control the computer. Any ideas?

Question information

Language:
English Edit question
Status:
Answered
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Chris Kosieracki (cckozie) said :
#1

Additional info:
I can't guarantee that the problem did not exist before as I upgraded in order to use findText(). It could be that the problem is related to findText() rather than something else in the upgrade.

Revision history for this message
Chris Kosieracki (cckozie) said :
#2

I've created a small test script that shows the problem.
The actual script that I'm have the trouble with does not cause the cursor to fly around as much as this test script, but after doing some debugging I realized that the cursor error problem always occurred when clicking or double clicking something on the screen. That app is using "observe", and the cursor error sometimes occurs in an event and sometimes in the mainline.

import subprocess

Settings.ActionLogs=0
mmd = Settings.MoveMouseDelay
Settings.MoveMouseDelay = 0.2

def image1Event(event):
    print('Event 1')
    if reg.exists(image1,0):
        click(image1)
        print('image1')
        wait(1)
    event.repeat()

def image2Event(event):
    print('Event 2')
    if reg.exists(image2,0):
        click(image2)
        print('image2')
        wait(1)
    event.repeat()

path = '/Applications/Google Chrome.app'
chrome = False
try:
    subprocess.Popen(['open', '-a', path])
    chrome = True
except:
    print "Unexpected error:", sys.exc_info()[0]
    print('Failed to start or set focus to ' + app)

image1 = Pattern("image1.png").similar(0.83)
image2 = Pattern("image2.png").similar(0.90)
tab1 = Pattern("tab1.png").similar(0.79)
tab2 = Pattern("tab2.png").similar(0.79)

urls = [',https://www.google.com','https://sikulix-2014.readthedocs.io/en/latest/']

tabs = True

if chrome:
    wait(1)
    tReg = Region(0,23,1438,39)
    reg = Region(412,282,631,383)
    if not tabs:
        for url in urls:
            if exists(Pattern("1539898718565.png").similar(0.91),5):
                click()
                paste(url)
                type(Key.ENTER)

    reg.onAppear(image1, image1Event)
    reg.onAppear(image2, image2Event)
    reg.observeInBackground(20)

    for i in range(0,10):
        if tReg.exists(tab1):
            print('tab1')
            click(tab1)
            wait(0.5)
        if tReg.exists(tab2):
            print('tab2')
            click(tab2)
            wait(0.5)

Settings.MoveMouseDelay = mmd

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

what exactly are the messages you get?

Revision history for this message
Chris Kosieracki (cckozie) said :
#4

The error message is:
[error] RobotDesktop: checkMousePosition: should be L[746,812]@S(0)
but after move is L[745,811]@S(0)
Possible cause in case you did not touch the mouse while script was running:
 Mouse actions are blocked generally or by the frontmost application.

In almost every situation, the cursor position is only off by 1 pixel either horizontally or vertically, or in this case, both.

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

This looks like some rounding problems (current and expected position have different sources) may together with HiRes monitors.

Do you have a HiRes environment?

As a fix I have to add some "fuzzy logic" ;-)

Revision history for this message
Chris Kosieracki (cckozie) said :
#6

I am running on a MacBook Air, display is 13.3-inch (2560 x 1600)

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

I tested with the latest 1.1.4 build on my MacBook Pro Retina, which also has a display 13.3-inch (2560 x 1600).

My macOS is 10.14.5 and I tested both with Java 8 and Java 12.

Internally the screen size is reported and used as 1280 x 800, which is correct since a Retina display only boosts an internal pixel up to 4 pixels on the monitor.

With the following test I had no problems:
for i in range(10):
  click(Pattern("1564644657172.png").targetOffset(-59,-8))
  print getLastMatch()
  print Mouse.at()
  click(getCenter())

the image is something captured with the IDE in the bottom-right corner of the screen.

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

if you further get the error messages, but you script works, you can switch off the error messages:
Settings.checkMousePosition = False

At the beginning of your script.

Can you help with this problem?

Provide an answer of your own, or ask Chris Kosieracki for more information if necessary.

To post a message you must log in.