Any ideas how to capture the mouse with emscripten/html5.h functions?

275 views
Skip to first unread message

Floh

unread,
Feb 8, 2022, 8:28:30 AM2/8/22
to emscripten-discuss
First...I don't mean pointer-lock (which works fine), but instead the setCapture() (old) or setPointerCapture() (new) functionality.

For example, if I drag a Dear ImGui window and the mouse pointer goes out of the browser window, mouse events are no longer reported. Releasing the mouse button outside the window means that the ImGui window now sticks to the mouse button when the mouse is moved back inside, because the application still thinks the mouse button is pressed.

In the olden times, there was a setCapture()/releaseCapture() event pair, which doesn't work in Chrome.

In modern times, there's a new setPointerCapture()/releasePointerCapture() event pair, but this requires a 'pointerId' parameter, which isn't part of the regular mouse events, but of the derived 'pointer events'.

Long story short, has anybody managed to hack this somehow with the emscripten_*() functions? I tinkered around with calling an EM_JS() function from within the mouse button event handlers, which then calls setPointerCapture/releasePointerCapture, but that isn't successful because those functions want an actual, active "pointerId" object, not just some random number :D

I guess that emscripten/html5.h needs a new set of event functions for pointer events (https://developer.mozilla.org/en-US/docs/Web/API/Pointer_events), instead of regular mouse events?

Thanks!
-Floh.

Floh

unread,
Feb 8, 2022, 8:29:44 AM2/8/22
to emscripten-discuss
oops typos:

> setCapture()/releaseCapture() event pair

...this should be "function pair". Don't know why I got that wrong *twice* :)

Александр Гурьянов

unread,
Feb 8, 2022, 11:20:59 AM2/8/22
to emscripte...@googlegroups.com
I use "leave" event as workaround. When "pressed" pointer leaves canvas it automatically became unpressed. It works fine in most cases for me.

вт, 8 февр. 2022 г. в 20:29, Floh <flo...@gmail.com>:
--
You received this message because you are subscribed to the Google Groups "emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-disc...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/emscripten-discuss/6f17bf5e-5c08-4e8b-996c-437d62d0fa1fn%40googlegroups.com.

Floh

unread,
Feb 8, 2022, 2:14:50 PM2/8/22
to emscripten-discuss
> I use "leave" event as workaround. 

That's what I do too at the moment, but compared to the mouse capture on native platform it doesn't feel great for UI applications, for instance when grabbing a UI slider and accidentally moving the mouse outside the window, you suddenly lose the slider and need to grab it again.

Reply all
Reply to author
Forward
0 new messages