fenomas / game-inputs

A simple module for abstracting key/mouse input for games. Demo:
http://fenomas.github.io/game-inputs/
20 stars 6 forks source link

Left mouse key getting stuck as down #13

Open justthatrio opened 3 months ago

justthatrio commented 3 months ago

When both the left and right mouse keys are released at the same, the release of the left mouse key is not detected. Whichever mouse key was pressed first is the key that gets stuck. The behavior is repeatable on the live demo.

Edit: The bug seems to not be timing related but rather related to the order of events. If you press left, then press right, then release left, then release right, the left will remain detected as pressed despite it not being.

fenomas commented 3 months ago

Thanks for the report! You're right - I'm currently defaulting to pointer events if possible since they're modern, but now that I check, the Pointer API just doesn't emit any "down" events for chorded mouse buttons.

It looks like there's an easy but hacky workaround, at least in Chrome... or it might make sense for this library to just use mousedown events. Let me think about this a little and I'll hack something out.

justthatrio commented 3 months ago

You could use both pointer and mouse event listeners and let the mouse ones take precedence, ignoring pointer events if a corresponding mouse event was received. That would allow supporting mobile devices without feature detection and greater backwards compatibility for older browsers that don't support point events, and handle the edge that some browsers send both mouse and pointer events for mouse devices, but only pointer events for touch inputs.