Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slight misalignment of moveMouse on Windows #126

Closed
maruta opened this issue Jun 11, 2022 · 1 comment
Closed

Slight misalignment of moveMouse on Windows #126

maruta opened this issue Jun 11, 2022 · 1 comment

Comments

@maruta
Copy link

maruta commented Jun 11, 2022

Version
2.1.8

Short overview
Slight misalignment of moveMouse on Windows

Steps to reproduce error
The following code periodically gives the coordinates obtained by getMousePos to moveMouse, so the mouse cursor is expected to be stationary, but in my Windows environment the cursor gradually moves up until the y-coordinate becomes a multiple of 135.

const { mouse } = require('@nut-tree/nut-js')

function loop() {
  mouse.getPosition().then(
    (mp) => {
        mouse.setPosition(mp)
        console.log(mp)
    })
  window.requestAnimationFrame(loop)
}

loop()

Detailed error description
I have not been able to track down the details, but I suspect the problem is in the following code
https://github.com/nut-tree/libnut/blob/9f366a9f551bb653a3e43106804edf83cfeb696c/src/win32/mouse.c#L35-L38

The corresponding code in robotjs appears to differ in the rounding process and the correction according to the sign of the coordinates.
With this as a reference, if CalculateAbsoluteCoordinates is changed as follows, the problem in the test code above is no longer apparent.

MMPoint CalculateAbsoluteCoordinates(MMPoint point) {
	MMSize displaySize = getMainDisplaySize();
	return MMPointMake((ABSOLUTE_COORD_CONST * point.x / displaySize.width) + (point.x < 0 ? -1 : 1) ,  (ABSOLUTE_COORD_CONST * point.y / displaySize.height) + (point.y < 0 ? -1 : 1));
}

This change seemed to cause a new left-right misalignment, but for some reason it did not, and I still do not know why...

@s1hofmann
Copy link
Member

Fixed with release https://github.com/nut-tree/libnut-core/tree/v2.5.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants