gpt4 book ai didi

javascript - HTML\Javascript - 获取 ALT\CTRL\SHIFT 按键

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:26:40 25 4
gpt4 key购买 nike

是否可以捕获任何按键?即 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com