看文章之前来一个热身吧[JavaScript键码表]身为一个键盘侠,不搞清楚键码映射表怎么可以???_你挚爱的强哥()-CSDN博客keycode 0 =keycode 1 =keycode 2 =keycode 3 =keycode 4 =keycode 5 =keycode 6 =keycode 7 =keycode 8 = BackSpacekeycode 9 = Tabkeycode 10 =keycode 11 =keycode 12 = Clearkeycode 13 = Enterkeycode 14 =keycode 15 =keycode 16 = Shift_Lkeycode 17./qq_37860634/article/details/120446294
<!doctype html><html lang="en"><head><meta charset="UTF-8"></head><body></body><script>var multiKeyPress = {keyPressTimes: 0,// 2秒内5连击(默认)________________________trigger(multiKeyPressCallback,singleClickCallback,maxTimes = 5,time = 2000) {this.keyPressTimes || (this.keyPressTimes = 0);++this.keyPressTimes >= maxTimes &&(multiKeyPressCallback && multiKeyPressCallback(),singleClickCallback || (this.keyPressTimes = 0));this.keyPressTimes === 1 &&setTimeout(() => {this.keyPressTimes < maxTimes &&singleClickCallback &&singleClickCallback(); //执行单击键盘or少于maxTimes次数的点击this.keyPressTimes = 0;}, time);}};/*设置快捷键*/onkeyup = e => {var k = e.keyCode || e.which || e.charCode, ck = e.ctrlKey || e.metaKey, ak = e.altKey, sk = e.shiftKey;/*独立键*/if (k === 19) {/*按下Pause/Break键时候执行*/multiKeyPress.trigger(() => {// 双击键盘alert(`【更新时间】${versionTime}\n(注意校对是否已发布最新代码)`);},() => {// 单击键盘console.count();console.log("单击Pause/Break键");}, 2, 300);}};var versionTime='01月01日 00:00:00';</script></html>
如果觉得《【fiveKeyPress】2秒内五次点击键盘任意键(或组合键)触发自定义事件(以Pause/Break键为例)》对你有帮助,请点赞、收藏,并留下你的观点哦!