JS专用鼠标按键

发布于 2024-12-12 02:43:27 字数 124 浏览 0 评论 0原文

我的鼠标侧面有两个按钮,其默认行为是“后退”和“前进”。

我想知道的是是否可以在 JavaScript 中检测这些鼠标按钮的点击,或者这些按钮是否是类似于键盘的“播放”、“音量调高”和“无线开/关”的“特殊”按钮按钮。

My mouse has two buttons on the side, whose default behaviour are "Back" and "Forward".

What I'd like to know is whether or not it's possible to detect clicks of these mouse buttons in JavaScript, or if these are "special" buttons akin to the keyboard's "Play", "Volume Up" and "Wireless on/off" buttons.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

七度光 2024-12-19 02:43:27

我不知道任何特定的鼠标事件。

不过,您可以通过检查 mousedown 事件的 event 对象轻松找到答案。 全屏小提琴:http://jsfiddle.net/dWfDL/1/show/

var text = typeof document.body.textContent != "undefined" ? "textContent" : "innerText";
window.onmousedown = function(e){
    //Inspect the `e` object, for example using a for(var i in e) loop, or:
    //console.log(e);
    var s = [];
    for(var i in e){
        try{
            if(e[i] !== null){
                if(i.toUpperCase() == i) continue; //Ignore constants
                if(typeof e[i] == "function") continue; //Ignore functions
                if(e[i].parentNode) continue; //Ignore elements
                if(e[i] === window) continue; //Ignore Window
            }
            s.push(i + " =\t\t" + e[i]);
        }catch(err){s.push(i + " \tERROR reading property.")}
    }
    e.preventDefault();
    s = s.join("\n") + "\n\n";
    document.body[text] = s + document.body[text];
}
//Double-click to wipe contents
window.ondblclick = function(){
    document.body[text] = "";
}

I am not aware of any specific mouse events.

You can, however, easily find out yourself by inspecting the event object of the mousedown event. Fullscreen fiddle: http://jsfiddle.net/dWfDL/1/show/

var text = typeof document.body.textContent != "undefined" ? "textContent" : "innerText";
window.onmousedown = function(e){
    //Inspect the `e` object, for example using a for(var i in e) loop, or:
    //console.log(e);
    var s = [];
    for(var i in e){
        try{
            if(e[i] !== null){
                if(i.toUpperCase() == i) continue; //Ignore constants
                if(typeof e[i] == "function") continue; //Ignore functions
                if(e[i].parentNode) continue; //Ignore elements
                if(e[i] === window) continue; //Ignore Window
            }
            s.push(i + " =\t\t" + e[i]);
        }catch(err){s.push(i + " \tERROR reading property.")}
    }
    e.preventDefault();
    s = s.join("\n") + "\n\n";
    document.body[text] = s + document.body[text];
}
//Double-click to wipe contents
window.ondblclick = function(){
    document.body[text] = "";
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文