1j01 / tracky-mouse

Mouse control via head tracking, as a cross platform desktop app and JS library. eViacam alternative.
https://trackymouse.js.org/
MIT License
25 stars 4 forks source link

Manual mouse movement detection false positives #44

Closed 1j01 closed 1 month ago

1j01 commented 2 months ago

There is a feature for regaining mouse control (pausing the head tracker temporarily) by just moving the mouse normally. You don't want to interrupt head tracking by accident, so there's a threshold of movement before the mouse will take control from the head tracker. However, I'm noticing it pausing randomly, perhaps especially when moving the cursor significantly with my head, on Windows 11.

Possible solutions:

  1. Maybe disable the mouse movement detection until the setMouseLocation promise is resolved? Might not work if outstanding promises overlap. If so, there wouldn't be a period of time where the mouse movement detection is enabled, or it would be enabled even though a later request to move the mouse is already in progress, making it sporadic.
  2. Maybe store a queue of mouse positions requested, and compare the current mouse position against each point in the queue.
    I think that should be robust. How long should the queue be? Points could be removed when setMouseLocation resolves, if and only if it's guaranteed that getMouseLocation will return the new position at that point. However, a simple time or count limit should be fine.

Also, this could help:

Related:

1j01 commented 2 months ago

I could simulate latency by adding setTimeout before setMouseLocation to test this. Maybe wrap it in a function, also for tracking the positions requested.

1j01 commented 1 month ago

I got this to be robust by comparing the retrieved mouse position to a queue of mouse positions. It now behaves reliably even with await new Promise((resolve) => setTimeout(resolve, Math.random() * 100)); before setMouseLocation.

1j01 commented 1 month ago

Some minor notes from when I closed this: