GithubHelp home page GithubHelp logo

Comments (33)

octalmage avatar octalmage commented on September 26, 2024

Hi Max!

Could you try putting a sleep between the two? I believe the mouse event is just taking longer on your computer. The tests confirm that getting and setting like that should work as expected.

from robotjs.

maxdeepfield avatar maxdeepfield commented on September 26, 2024

\node_modules\robotjs\test>node mouse.js
TAP version 13
Get the initial mouse position.
ok 1 successfully retrieved mouse position.
ok 2 mousepos.x is a valid value.
ok 3 mousepos.y is a valid value.
Move the mouse.
ok 4 successfully moved the mouse.
not ok 5 mousepos.x is correct.


operator: ok
expected: true
actual:   false

...
not ok 6 mousepos.y is correct.


operator: ok
expected: true
actual:   false

...

1..6
tests 6
pass 4
fail 2

from robotjs.

octalmage avatar octalmage commented on September 26, 2024

Yeah those tests failing mean it's the mouse delay. :/

You could use RobotJS from GitHub which includes a setMouseDelay function. The default delay is currently 10ms and I knew this was going to be an issue.

from robotjs.

maxdeepfield avatar maxdeepfield commented on September 26, 2024
robot.moveMouse(10, 10);
setTimeout(function(){
    console.log(robot.getMousePos());
},1000);
// { x: 9, y: 9 }

It seems like mouse always try to reach 0,0 coordinates.

from robotjs.

octalmage avatar octalmage commented on September 26, 2024

Hmm that's super odd! Thanks for trying that.

@Deltatiger could you try the above code when you get a chance? It works in my VM, I wonder if it's a Windows 10 issue.

from robotjs.

maxdeepfield avatar maxdeepfield commented on September 26, 2024

I compiled robotjs from github master sources using node-gyp.
Sad, but it works same. :(

from robotjs.

maxdeepfield avatar maxdeepfield commented on September 26, 2024

I also will try this later on other Windows.

from robotjs.

maxdeepfield avatar maxdeepfield commented on September 26, 2024

Interesting: moveMouse(1,1) moves mouse precisely on very left top corner (0,0)
I think this is not getMousePos problem, but moveMouse issue...

from robotjs.

maxdeepfield avatar maxdeepfield commented on September 26, 2024
var pos = robot.getMousePos();
robot.moveMouse(pos.x, pos.y);

This should not do anything, but it moves cursor a bit to left and top according to current position (depends of current position distance from 0,0, very far - very large step)

from robotjs.

maxdeepfield avatar maxdeepfield commented on September 26, 2024

SetCursorPos(point.x, point.y); instead of mouse_event in mouse.c works very nice.

from robotjs.

octalmage avatar octalmage commented on September 26, 2024

Thanks that's good to know! I believe mouse _event is being deprecated anyway. I'll use this as an opportunity to test different mouse setting functions ( I believe there's 4 ways on Windows). If I remember correctly, SendInput works really well.

from robotjs.

maxdeepfield avatar maxdeepfield commented on September 26, 2024

I tested SendInput and it worked like mouse_event - weird 65535 divisions seems to be not so precise. Maybe this depends on some mouse or screen configuration.

from robotjs.

maxdeepfield avatar maxdeepfield commented on September 26, 2024

I found solution: #78
This will work for SendInput too.

from robotjs.

Deltatiger avatar Deltatiger commented on September 26, 2024

@maxdeepfield I think SendInput should be used in windows. It supports multiple input devices and is recommended by MS.
@octalmage I will test things out again in Windows 7 and 10. Just to check if things work out. Also will set up a branch on my repo to convert stuff to SendInput(Mouse and Keyboard). If that works out then it should be better.

from robotjs.

maxdeepfield avatar maxdeepfield commented on September 26, 2024

@Deltatiger agree, but SendInput also must use 65536.0f instead of 65536 or 0xFFFF

from robotjs.

maxdeepfield avatar maxdeepfield commented on September 26, 2024

Strange, but this 65536.0f correction doesnot work very fine using over remote desktop. Its is now going closer, but not so precise as SetCursorPos

from robotjs.

octalmage avatar octalmage commented on September 26, 2024

I was afraid of that, since the current code works for some users.

from robotjs.

dkrutsko avatar dkrutsko commented on September 26, 2024

The mouse code has some issues, first of all why is mouse_event being used instead of SendInput? According to MSDN mouse_event has been deprecated for quite some time. As for mouse movement why not use SetCursorPos here?

from robotjs.

maxdeepfield avatar maxdeepfield commented on September 26, 2024

As mentioned in discussion above - SendInput should be used, but this does not help in some cases, SetCursorPos working best for me.

from robotjs.

Deltatiger avatar Deltatiger commented on September 26, 2024

@maxdeepfield I tried tweaking stuff a bit. Try this out.

point.x = ceil(point.x * 65536.0 / GetSystemMetrics(SM_CXSCREEN));
point.y = ceil(point.y * 65536.0 / GetSystemMetrics(SM_CYSCREEN));

I still am using the mouse_event but this gives me close to accurate readings.

from robotjs.

Deltatiger avatar Deltatiger commented on September 26, 2024

@octalmage @maxdeepfield So the issue was mouse_event was dealing with the screen by normalizing it between values 0 to 65536. Very inaccurate if you ask me. The rounding issue fixes it a bit. But to completely fix it we would have to migrate to SendInput. That deals with pixels directly.

from robotjs.

DomiStyle avatar DomiStyle commented on September 26, 2024

Has there been any update to this?
I had issues with my mouse drifting when using moveMouse on Windows 10.

var mouse = robot.getMousePos();
robot.moveMouse(mouse.x, mouse.y);

This will make your mouse drift to the top left corner when running it in a loop.

from robotjs.

Deltatiger avatar Deltatiger commented on September 26, 2024

@DomiStyle This is an issue with Windows API that is being used currently. The problem has already been identified. Will send a PR soon so that it can be fixed.

from robotjs.

octalmage avatar octalmage commented on September 26, 2024

Should we maybe use SetCursorPos for now? I would like to get #105 finished and this is blocking it.

from robotjs.

octalmage avatar octalmage commented on September 26, 2024

Actually I'm going to go ahead and merge the appveyor branch. This is broken so the tests should fail.

from robotjs.

octalmage avatar octalmage commented on September 26, 2024

Thanks to AutoHotkey, I got it! Looks like they went through the same thing we did:

https://github.com/Lexikos/AutoHotkey_L/blob/a0bc036d4f09825b3478f14ffcaca11c782782e0/source/keyboard_mouse.cpp#L2447

Man I LOVE open source.

Anyway, this needs more testing but I'm going to merge it soon.

from robotjs.

octalmage avatar octalmage commented on September 26, 2024

We can switch to SendInput later, it should be easy now that we have the conversion down. I'll open a new issue for this.

from robotjs.

octalmage avatar octalmage commented on September 26, 2024

@maxdeepfield could you confirm if the code in the master branch resolves this for you? In my tests moveMouse was accurate.

from robotjs.

DomiStyle avatar DomiStyle commented on September 26, 2024

@octalmage Works fine for me now.

from robotjs.

octalmage avatar octalmage commented on September 26, 2024

Awesome thanks @DomiStyle! I'll release a new version later today.

from robotjs.

octalmage avatar octalmage commented on September 26, 2024

v0.3.2 published to npm which fixes this issue.

from robotjs.

ChrisAntaki avatar ChrisAntaki commented on September 26, 2024

Thanks for fixing this @octalmage! 👍

from robotjs.

octalmage avatar octalmage commented on September 26, 2024

Of course! That's why I'm here!

from robotjs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.