Hacker News new | past | comments | ask | show | jobs | submit login
MouseEvent: buttons property (developer.mozilla.org)
8 points by keepamovin 6 months ago | hide | past | favorite | 11 comments



Is there something specific or quirky that we should be paying attention to?

Mozilla dev docs are great, nice to see them getting to the top of HN :)

But why just MouseEvent.buttons?


I thought the interesting thing was how it's a bitmask (a bit rare in IDL attributes / DOM properties). Also I was unaware there were 4th and (shock) 5th buttons for some mouses. So theoretically there's 32 possible states of pressing such a mouse.

I wasn't aware JS surfaced this "multi touch" capability for buttons, as the bitmask indicates which buttons were pressed "at the same time" for whatever the event is (mouse/pointer down etc). Just thought it was cool and a little rare.

Nice digging into the MDN docs and discover new parts of the DOM. Like a new room in a giant familiar house! :) For me at least haha :)


I feel like the bit flags structure of this event isn't Javascript-y because javascript doesn't support int primitives. Wonder why they didn't translate it.


I think it's elegant actually. Appropriate and a nice link with "device driver" stuff from the past. :) haha

At least they didn't overcomplicate it. I shudder to think of: MouseEvent.MIDDLE_BUTTON_PRESSED etcs.


It could work as an Array if javascript supports C++'s small-buffer-optimization on the backend.


That's what I thought it was, based on the name. But more interesting to see the bitmask heh :) I don't know about C++ internal, but in JS you can just go

  if ( mousedown.buttons & 4 ) alert('aux pressed')
Tho thinking of it now as you mentioned array I'd feel mousedown.buttons.includes(4) would be slightly inefficient due to the loop. We like our efficiency! Haha :)

For me tho the API feels right for JS. As it's kind of a rare a 'low level' thing, it's appropriate it's API is more akin to that than something heavier like

  MouseEvent.buttons.<button> = Boolean
I like the efficiency of the bit mask to immediately check multiple buttons too :) haha


how is a magic "4" better than MouseEvent.MIDDLE_BUTTON_PRESSED?


Heheheh. Well I guess we're getting down into the weeds now and into the aesthetics of it which are nevertheless personal.

To me, it's obscene and ugly. Over the top. 4 isn't so magic when you realize that the middle button is normally considered the 3rd after the first and second buttons. And when you stretch those values into a bit field, with zero representing nothing, it's natural that the middle (or aux button) will occupy 4.

Hahaha! :) At least to my thinking. Hahaha :)

What do you think? :)


> On Mac OS X 10.5, the buttons attribute always returns 0 because there is no platform API for implementing this feature.

Is that right? And is it just specifically 10.5?


For those who aren't readily familiar with Mac OS X versions, OS X 10.5 is very old and became unsupported as of 2011.


I get the right buttons values in Sonoma latest. Not sure about older :)




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: