gpt4 book ai didi

jquery - 如何检测到: Press twice the same key,但第二次按住2秒

转载 作者:行者123 更新时间:2023-12-01 04:14:15 24 4
gpt4 key购买 nike

如何检测:按两次同一键,但第二次按住 2 秒?

我正在寻找一种有效的方法来检测键码 37(左箭头)(或必要时的任何其他键)的按键事件,然后在释放按键后立即检测相同键码的第二次按键事件 1.5 或 2 秒key,在给定的延迟内,例如 1 秒。

这是返回,不会混淆“返回到上一页”(这就是我想要做的)和“转到同一页上的此元素之前的元素”

我已经在 $(document.ready() 标记中尝试使用 old_keycode 和 old_keycode_timepressed 以及 new_keycode new_keycode_timepressed ,但我需要复制/粘贴我想要的每个键码的整个代码,并且代码本身效率不高。

有人听说过可以帮助我解决这个问题的插件,或者有人愿意帮助我吗?

感谢您的宝贵时间。

最佳答案

<强> jsFiddle demo

var twice_37 = 0;

$(document).on('keyup', function( e ){

if(e.which===37){ // If left arrow

if(twice_37===1){ // (remember that twice_37 is 0 initially)
alert('Do something! (you pressed Left twice!)');
}

twice_37 = 1; // Set to 1 and...
setTimeout(function(){ // ...reset to 0 after 1s
twice_37 = 0;
}, 1000);

}

});

关于jquery - 如何检测到: Press twice the same key,但第二次按住2秒,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16454375/

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