Giulio Franco
Giulio Franco

Reputation: 3230

How to distinguish left and right mouse buttons in JavaFX?

I'm making a toy hearing test application with Java8 (I'm using JavaFX version 8). In order to assess if the user can hear the sound he has to click on a UI button with the mouse button which corresponds to the side the sound was coming from.

So, in the click event, I need to distinguish between right and left click buttons, but all JFX seems to be giving me is

PRIMARY 
Represents primary (button 1, usually the left) mouse button.

SECONDARY 
Represents seconday (button 3, usually the right) mouse button. 

which is clearly not good enough: stereo channels aren't going to be inverted only because the user is left-handed.

So, is there any way to tell if PRIMARY is the left or right mouse button?

PS: I can obviously solve the problem by explicitly asking the user to right-click and left-click before starting. I'd like to know if it's possible to avoid that.

Upvotes: 2

Views: 864

Answers (1)

Tumladhir
Tumladhir

Reputation: 170

I've been browsing through the API and Microsoft docs. The primary and secondary mousebuttons have no unique name - as far as I'm aware of. I can't find a method in Java to find out whether the box "invert mousebuttons" is ticked off or not.

Creating a button "Click left to begin" could function as a "start" and primary mousebutton detection. Maybe there are Java libraries out there which provide a more flexibility using primary/secondary mouse buttons.

Upvotes: 1

Related Questions