是否有能力捕捉任何按键?即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>
如何捕获这些密钥?