Closed 1j01 closed 1 month 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.
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
.
Some minor notes from when I closed this:
const mousePosHistoryDuration = 5000; // in milliseconds; affects time to switch back to camera control after manual mouse movement (although maybe it shouldn't)
and
const regainControlForTime = 2000; // in milliseconds, AFTER the mouse hasn't moved for more than mouseMoveRequestHistoryDuration milliseconds (I think)
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:
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.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 thatgetMouseLocation
will return the new position at that point. However, a simple time or count limit should be fine.Also, this could help:
getMouseLocation
results, rather than a queue ofsetMouseLocation
requests. Should consider framerate independence, and ideally define the threshold in terms of travel within a period of time. (Should distance be measured in pixels, inches/cm, or screen percentage? probably pixels, to keep it simple.)Related: