是否有能力捕捉任何按键?即 Ctrl + Shift + Alt 按键(没有其他按键)。
在下面的代码段中(在 Chrome 下检查),只有在按下其他“常规”键时,我才能捕获移位。
更新 :
<html>
<head>
<script>
function onKeyPressed(event) {
event = event || window.event;
var code = event.keyCode;
var key = String.fromCharCode(event.keyCode);
var shift = event.shiftKey;
var alt = event.altKey;
var ctrl = event.ctrlKey;
var which = event.which;
var str = "code = " + code + "\n" +
"key = " + key + "\n" +
"shift = " + shift + "\n" +
"alt = " + alt + "\n" +
"ctrl = " + ctrl + "\n" +
"which = " + which;
alert(str);
};
function onClick(event) {
event = event || window.event;
var x = event.clientX;
var y = event.clientY;
var str = "x = " + x + "\n" +
"y = " + y;
alert(str);
};
function onKeyUp(event) {
alert("onKeyUp");
};
function onKeyDown(event) {
alert("onKeyDown");
}
</script>
</head>
<body onmousedown="onClick(event)" onkeypress="onKeyPressed(event)" onkeyup="onKeyUp(event)" onkeydown="onKeyDown(event)"></body>
</html>
如何捕获这些 key ?
最佳答案
有一个非常好的新 JS 库,它在跟踪浏览器中的键盘事件方面做得很好。
它叫做捕鼠器。这是链接:http://craig.is/killing/mice
希望有帮助。
关于javascript - HTML\Javascript - 获取 ALT\CTRL\SHIFT 按键,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/11678114/