是否有能力捕獲任何按鍵?即Ctrl + Shift + Alt按鍵(沒有其他按鍵)。HTML Javascript - 獲取ATL CTRL SHIFT鍵按
在下面的代碼段中(在Chrome中選中),我只能在按下其他「常規」鍵時捕獲換檔。
UPDATE:
<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>
如何這些密鑰被捕獲?
是不是隻是'if(event.keyCode == x)'其中x是shift/ctrl/alt的關鍵代碼? – 11684 2012-07-26 21:14:21
又一個jQuery解決方案,我不會去釣魚downvotes :) http://craig.is/killing/mice – 2012-07-26 21:15:07
哎呀,對不起,[重複我找到](http://stackoverflow.com/questions)/10655202/detect-multiple-keys-on-single-keypress-event-on-jquery/10655273#10655273)是jQuery特有的。仍然,很容易適應,我認爲它唯一的jQuery方面是鉤住事件,這很容易修改。 – 2012-07-26 21:15:59