是否有能力捕获任何按键?即 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>
如何捕获这些密钥?
答案 0 :(得分:4)
答案 1 :(得分:2)
答案 2 :(得分:2)
AFAIK你必须使用keyup或keydown事件来捕获转移,keyPress不捕获它。如果您需要更多详细信息,请查看每个事件捕获的this list个密钥。由于shift是修饰键,因此不会捕获它。为什么会出现这种情况我无法解释。