Detect simultaneously pressed mousebuttons

Hi community,

I’m having problems implementing the steering of the player in my current project.
Left mouse button should trigger firing, right mouse button should trigger acceleration.
It already works to a certain degree, but I’m struggling to implement the behavior that when the right mouse button (acceleration) is held down it still is possible to trigger fire with left mouse button without stopping acceleration. Here is a playground which only implements non-simultaneously pressed buttons The left box indicates firing with CCW rotation, the right box indicates acceleration with CW rotation.

According to MouseEvent.buttons - Web APIs | MDN the event.buttons property indicates simultaneously pressed buttons which probably can be used to aceive what I’m looking for. But all attempts messing around with this property failed. Maybe someone already has done something similar in the past and could modify the playground.

Any help appreciated!

Hi holger,

Does this do what you’re looking for? The only changes I made were to remove the state reset on controlEnabled and switch the setting of your acceleration flags to depend only on the buttons variable, which uses bit flags to indicate which mouse buttons are currently pressed. I think it works pretty well, though if there were special cases you were guarding against with some of those conditions I removed, you should double-check that those cases aren’t broken now. :upside_down_face:

1 Like

That’s exactly how it should work :smiley: :smiley: Thank you very much for your effort, much appreciated!
The bit flags did the trick.