Description
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...