Reputation: 1245
I can't just know which button is clicked because all below methods are returning false. I am trying to grab the click type on a HBox
control and using the code below. How to differentiate right and left click?
hb.addEventHandler(MouseEvent.MOUSE_CLICKED, event ->
{
System.out.println("Meta Down?" + event.isMetaDown());
System.out.println("Middle Down?" + event.isMiddleButtonDown());
System.out.println("Primary Down?" + event.isPrimaryButtonDown());
System.out.println("Secondary Down?" + event.isSecondaryButtonDown());
System.out.println("Synthesized?" + event.isSynthesized());
}
Output;
Meta Down?false
Middle Down?false
Primary Down?false
Secondary Down?false
Synthesized?false
Upvotes: 1
Views: 220
Reputation: 1498
The reason none of them are down is because MouseClicked gets called when a mouse button is pressed and then released, in other words, it's a Mouse Pressed event followed by a Mouse Released event.
If you need to know what triggered it, look at the event.getButton()
and see if it is any of the MouseButton
s. Try changing your code to something like this:
hb.addEventHandler(MouseEvent.MOUSE_CLICKED, event ->
{
System.out.println("Middle Clicked?" + event.getButton()== MouseButton.MIDDLE);
System.out.println("Primary Clicked?" + event.getButton()== MouseButton.PRIMARY);
System.out.println("Secondary Clicked?" + event.getButton()== MouseButton.SECONDARY);
System.out.println("None Clicked?" + event.getButton()== MouseButton.NONE);
}
Upvotes: 4