读取特殊的鼠标按钮 [英] Reading Special MouseButtons

查看:109
本文介绍了读取特殊的鼠标按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有兴趣从资源管理器的鼠标按钮(通常用于在Web浏览器中前后移动的鼠标侧面的特殊按钮)捕获输入.

I am interested in capturing input from the explorer mouse buttons (the special buttons on the side of mice normally used to go forward and back on web browsers).

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.Pane;
import javafx.stage.Stage;
import javafx.scene.input.MouseButton;
import static java.lang.System.*;

public class MouseThing extends Application
{
    @Override
    public void start(Stage stage) throws Exception
    {
        Pane pane = new Pane();

        pane.setOnMousePressed(e -> {
            if(e.getButton() == MouseButton.PRIMARY)
                out.println("LEFT"); 
            if(e.getButton() == MouseButton.SECONDARY)
                out.println("RIGHT");      
            if(e.getButton() == MouseButton.MIDDLE)
                out.println("MIDDLE");    
            if(e.getButton() == MouseButton.NONE)
                out.println("OTHER");  
            // How read explorer buttons?  
            out.println("click");
        });

        Scene scene = new Scene(pane, 300, 100);
        stage.setTitle("Demo");
        stage.setScene(scene);
        stage.show();
    }
}

仅作为示例,我想记录一下前进和后退按钮已激活的情况.在这一点上,我唯一可以实现的交互是左键,右键和中键单击.按下鼠标上的forwardback按钮甚至无法注册click打印.

Just for the example, I would like to record that the advance and retreat buttons were activated. The only interaction I can achieve at this point is left, right and middle clicks. Pressing the forward and back buttons on the mouse doesn't even register the click print.

有一篇关于Javascript的帖子: JS特殊鼠标按钮,但并非如此对我有用.

There was this post for Javascript: JS special mouse buttons, but it wasn't useful for my purposes.

推荐答案

自JavaFX 12起,后退按钮将被识别,因此您可以执行以下操作:

Since JavaFX 12, the forward and back buttons on the mouse are recognized, so you can do:

pane.setOnMousePressed(e -> {
    if(e.getButton() == MouseButton.PRIMARY)
        out.println("LEFT");
    if(e.getButton() == MouseButton.SECONDARY)
        out.println("RIGHT");
    if(e.getButton() == MouseButton.MIDDLE)
        out.println("MIDDLE");
    if(e.getButton() == MouseButton.BACK)
        out.println("BACK");
    if(e.getButton() == MouseButton.FORWARD)
        out.println("FORWARD");
    if(e.getButton() == MouseButton.NONE)
        out.println("NONE");  
    out.println("click");
});

这篇关于读取特殊的鼠标按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆