In #177 I implemented a fix for moving the mouse in a game, but it's not perfect. Unfortunately we'll need to create a new function or parameter for a special mouse move just for games. We need to only set the deltas, and not the new mouse position. This only applies to Mac.
Haha thanks @Camilleeyries!
Hater of the year

For real though, I think I'm just going to add a new option to moveMouse for games. Something like:
robot.moveMouse(5, 5, true);
This is unfortunate because the app controlling the mouse might not always know what application they're controlling, like ScreenCat. I've looked into how other applications do it, and it seems to be a common problem.
Is this limited to Mac ? I have not tested this on Windows but neither have I seen anyone with an issue on Windows.
@octalmage What's wrong with moving a delta in other applications?
@Deltatiger the issue is limited to Mac.
@demipixel The issue isn't with moving the delta in other applications, it's about moving the absolute in games. It causes a double mouse move when you move your real mouse.
I just created a new branch that only sets the deltas, you can test it here:
https://github.com/octalmage/robotjs/tree/move-mouse-game
@nroadley could you try this code? I just modified the moveMouse code. It won't work for non-games.
I only tested this in Minecraft and a few online games, but from what I can tell based on other applications it seems right.
Would it make sense to expose a moveMouseByDelta function? I'm writing an application that maps the Wii U gamepad's gyroscope to mouse movements on my mac for use in FPS-type games, and right now I'm doing something like:
var currentMousePosition = robot.getMousePos();
robot.moveMouse(currentMousePosition.x + gyroX, currentMousePosition.y + gyroY);
So why not just expose a separate moveMouseByDelta function to save code, and resources by preventing the getMousePos from calling twice?
I thought about that, or at least allowing users to move the mouse by only setting the deltas using an option. The problem is the platform inconsistency. On Mac I can specify the delta, but on Windows I'd have to get the current mouse position then calculate the delta. Mac is also the only OS that needs a special mouse function for games.
What I really want is a mouse function that works in all situations. There might be an option using the apps process ID, but I haven't figured it out yet.
For now I'll at the least create a moveMouseGame/moveMouseDelta or something while I figure it out.
Also, the app you're making sounds awesome. Are you running into issues with moving the mouse in games?
@octalmage Thanks, I'll keep an eye on the repo, let me know if you need me to test anything.
As for issues in-game, it's hard to say. There exists some stuttering inside _and_ outside games, but I believe that has less to do with robot.js and more to do with the way I'm sending data to the app. And aside from that, the movement is not quite as smooth as moving the mouse on the trackpad (maybe I should try moveMouseSmooth), but again that exists in and out of games, so I don't think there are any game-specific issues that I've noticed yet, though I've only been working on this for a day and only tested it on Portal, so maybe I'll run into something at some point.
I created the branch moveMouseGame, could someone test this and let me know how it works? I've tested it with Minecraft and it seems to work well.
The new function is moveMouseGame and it works just like moveMouse.
It doesn't work for me. I tried on windows at least, and it says that:
"robot.moveMouseGame is not a function"
Could this be merged? I think it's a core feature that should be merged! (moveMouseGame branch)
Any update on this? My game locks the mouse and i would like to move it properly
Would also like to see an update to this
Most helpful comment
Could this be merged? I think it's a core feature that should be merged! (moveMouseGame branch)