Scala MouseEvent - How to know which button was pressed?
I'm writing a scala application using scala swing. I can listen for MouseClicked
to get notified whenever the mouse is clicked, but how do i know which button was pressed. The documentation is pretty bad, so i have looked in the Java documentation for MouseEvent
, which says that the key can be retrieved from the modifiers field, so i tried to output the modifiers field of the scala MouseClicked
event, which turned out to be an integer, 0 for left click, mouse button 3 and mouse button 4 and 256 for right click.
It looks like it will work if i only need to know the difference between left and right click, but can i be sure the modifiers all ways work this way? The documentation says nothing, and for what i know modifiers could be affected by other things than just which mouse button was pressed. I would also like to know the difference between left click and mouse button 开发者_Go百科3 and 4. I don't think users expect them to do the same thing as left click.
In the scala documentation there is a MouseButtonEvent
, can this be used for anything? The documentation says nothing about what it does.
You can always use x.peer.getButton
to get the Java mapping (where x
is your Scala MouseClicked
event). peer
almost always contains a Java equivalent to the Scala class--and it does in this case.
精彩评论