admin管理员组文章数量:1425545
Simply put, is there any way to detect additional mouse button presses in JavaScript? It's not documented with the rest of the mouse input, so I guess it's not in standard implementation.
Is there any way, such as a library, which can enable extra mouse buttons?
Simply put, is there any way to detect additional mouse button presses in JavaScript? It's not documented with the rest of the mouse input, so I guess it's not in standard implementation.
Is there any way, such as a library, which can enable extra mouse buttons?
Share Improve this question edited Apr 11, 2016 at 15:57 Zakaria Acharki 67.5k15 gold badges78 silver badges106 bronze badges asked Apr 11, 2016 at 15:45 Gregory SimsGregory Sims 5611 gold badge8 silver badges19 bronze badges 2- 4 developer.mozilla/en-US/docs/Web/API/MouseEvent/button – Groben Commented Apr 11, 2016 at 15:51
- The working draft of the spec is found at the link below - the mozilla implementation of detecting auxiliary button clicks as described in the link provided by @Briggy should work cross browser. w3/TR/DOM-Level-3-Events/#events-mouseevents – Korgrue Commented Apr 11, 2016 at 15:57
2 Answers
Reset to default 4Yes you could do this, check MouseEvent.button, see example below that will detect 3 and 4 buttons click.
Some pointing devices provide or simulate more buttons. To represent such buttons, the value must be doubled for each successive button (in the binary series 8, 16, 32, ... ) as mentioned in https://www.w3/TR/DOM-Level-3-Events/#events-mouseevents
var whichButton = function (e) {
// Handle different event models
var e = e || window.event;
var btnCode;
if ('object' === typeof e) {
btnCode = e.button;
switch (btnCode) {
case 3:
console.log('Browser Back button clicked.');
break;
case 4:
console.log('Browser Forward button clicked.');
break;
default:
console.log('Unexpected code: ' + btnCode);
}
}
}
<button onmouseup="whichButton(event);" oncontextmenu="event.preventDefault();">Click with mouse...</button>
var whichButton = function (e) {
// Handle different event models
var e = e || window.event;
var btnCode;
if ('object' === typeof e) {
btnCode = e.button;
switch (btnCode) {
case 3:
console.log();
break;
case 4:
console.log();
break;
default:
console.log('Unexpected code: ' + btnCode);
}
}
}
本文标签: javascriptIs it possible to get mouse buttons 45etcStack Overflow
版权声明:本文标题:javascript - Is it possible to get mouse buttons 4, 5, etc? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744688653a2619857.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论