mxrlkn / mouselock

Lock mouse cursor to a centered area of the screen for MacOS.
MIT License
46 stars 6 forks source link

[BUG] using this with polling rate >250hz causes the cursor to jitter/jump ingame #17

Open LoweloDev opened 9 months ago

LoweloDev commented 9 months ago

Update: I figured out what the problem is. The problem is the polling rate and the amount of events sent. 250hz is the maximum I could get running without issues using the method implemented by @mxrlkn.

I may or may not look for a better solution than to downgrade my mouses polling rate e.g. according to https://stackoverflow.com/a/40922095 wine developers impl. of mouse capture. But I am probably going to buy a gaming pc soon TM anyways so... probably not.

EDIT: With an MX Master 3, a G502 (not hero) and a very old Performance MX it is not reproducible btw. I could only reproduce it with G Pro Wireless and Pro X Superlight so far. Peronally running out of mouses by now lmao

Steps to reproduce:

install OS Ventura 13.1 use mouselock start League of legends using G pro wireless or Pro X Superlight produce high apm with mouse like clicking around or, simpler way to cause teleportation -> hold left click and drag your mouse around.

This happens especially while holding left click but also happens if having a high clickrate on rightclick ingame combined with movement. It's like the tracking just stops frequently.

Doesnt matter if Linear Mouse or GHub is used parallel to mouselock.

ontimond commented 9 months ago

@LoweloDev @mxrlkn I think this issue maybe is related https://github.com/mxrlkn/mouselock/issues/16#issue-2022185348

LoweloDev commented 9 months ago

@LoweloDev @mxrlkn I think this issue maybe is related #16 (comment)

Certainly sounds like it. Didn't look at the code yet but what you said would perfectly describe what I observed, I think.

EDIT: With an MX Master 3, a G502 (not hero) and a very old Performance MX it is apparently not reproducible btw. I could only reproduce it with G Pro Wireless and Pro X Superlight so far. Peronally running out of mouses by now lmao

LoweloDev commented 9 months ago

Edit2: Okay I think the problem is the polling rate and the amount of events that are sent by 1000hz polling rate. Unfortunately event 125hz seems to be too much. I just don't understand why I didn't seem to have the problem with the G502 then as its polling rate is most definitely > 125hz. I will test that again. My MX Master 3 is capped at max. 125hz and default apparently it even runs on 90hz.

Edit: @ontimond @mxrlkn

Welp. I cloned the repo fooled around in swift and c. Even tried some stuff with the help of copilot. What I learned:

You can either use the higher level event tap thing which is also used in this application or you can use the lower level one. However, with the higher level one you have one of 6-7 options:

  1. You do it like in this software and constantly update the position -> jittering
  2. You do it only if the mouse is near edge -> mouse is able to leave screen occasionally because there are events that you don't catch (this is the version league of legends itself implemented)
  3. You do it near edge with this warp method to update position, which causes the pointer to stuck to the border frequently for a short time
  4. You use the lower level api and constantly monitor the position and update the position -> jittering
  5. You use the lower level api and do it near the edge via SetLocation method -> doesn't work at all.
  6. You try to discard the event by returning NULL -> doesn't work at all. You cannot truly discard events apparently.
  7. You update the position either manually or with warp method -> mouse gets either stuck to the borders frequently or with a slightly different implementation it is able to occasionally leave the screen as it does default in league of legends.

There is however another implementation that I did not try yet which is this: https://stackoverflow.com/a/40922095

mxrlkn commented 9 months ago

Yeah I tried a lot of different things but in the end I could only get it to work by constantly updating the position.

This has worked on all my mice, with no jittering.

They are all set to 1000hz polling rate in Windows, which I believe gets carried over when I use them on MacOS. But I'm not 100% sure.

Try and check activity monitor when you test. If my CPU is overloaded I have found that I get some jittering. It uses quite a bit CPU. Maybe higher polling rate creates more CPU usage? I have an M1 mac

ontimond commented 9 months ago

I'm uncertain about my polling rate, but I believe it exceeds 1000Hz, likely at least 2500Hz. This implies that the process operates on a linear basis according to the mouse polling rate.

Yeah I tried a lot of different things but in the end I could only get it to work by constantly updating the position.

I'm curious to know about the methods you've explored

mxrlkn commented 9 months ago

The methods @LoweloDev mentioned. I'm not well versed in swift or c so I can't really say if it's possible or not. If you want to explore more, I found the Godot source code interesting: https://github.com/godotengine/godot/blob/51a00c2855009ce4cd6475c09209ebd22641f448/platform/osx/display_server_osx.mm#L1087

pldumn commented 6 months ago

Hi guys, I recently got a Superlight 2 and seem to be suffering from the same problem. Whenever the polling rate is set to anything over 250hz the cursor starts going crazy.

Did you find a solution to this? @LoweloDev