gpt4 book ai didi

javascript - 检测shift键输入事件

转载 作者:行者123 更新时间:2023-11-28 18:49:23 25 4
gpt4 key购买 nike

我需要检测持续 5 秒的 Shift 键输入并需要执行一些功能。

在 javascript/JQ 中,事件是否可以识别持续 5 秒的 Shift 键条目?

请帮忙,提前致谢。

最佳答案

这会起作用!

$(function () {
var tmr = 0;
$(document).keydown(function (e) {
if (e.shiftKey == true)
tmr = setTimeout(function () {
$("#status").append("You held the Shift key for 5 seconds!<br>");
clearTimeout(tmr);
}, 5000);
}).keyup(function (e) {
if (e.shiftKey == false)
clearTimeout(tmr);
});
});
<script src="https://code.jquery.com/jquery-1.11.3.js"></script>
<div id="status">
Ready...<br>
</div>

关于javascript - 检测shift键输入事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34738553/

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