I have implemented this skeleton code for executing a different action depending on what mouse button you click and how many clicks over a button.
Button button = new Button("Action!");
button.setOnMouseClicked(new EventHandler<MouseEvent>(){
@Override
public void handle(MouseEvent event){
if(event.getButton().equals(MouseButton.PRIMARY)){
if(event.getClickCount() == 2){
System.out.println("Double click");
}else if(event.getClickCount() == 1){
System.out.println("Single click");
}else{
System.out.println("SUPER click");
}
}else{
System.out.println("Secondary click");
}
}
});
I would like to capture a key (Ctrl for example) + mouse click event, so if the user clicks the button when the key is pressed, I can capture the key event inside the mouse event handler, in order to extend the possible actions. How could I perform that?
you can do it with:
if(event.isControlDown()){...}
for ctrl. There are more methods like that (Alt,shift, ... )
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.