将"任意"两个按键作为热键,包括非功能键。
原生JavaScript,不依赖任何库。
Use 'any' two keys as hotkey, including non-function keys.
Uses JavaScript, no dependencies.
You will need Node.js
installed on your system.
npm install anyhotkey --save
HTML
<input>
JavaScript
import { AnyHotKey } from 'anyhotkey';
const inputElement = document.querySelector('input');
AnyHotKey(inputElement, {
interval: 250, // 主副按键按下的最大时间间隔
key: 13, // 主按键的键代码
subKey: 17, // 副按键的键代码
onKey: function() { // 主按键按下时触发的回调函数
console.log("onKey")
},
onHotkey: function() { // 主副按键按下时触发的回调函数
console.log("onHotkey")
}
});
Example demo.html
You can manually download and link AnyHotKey.min.js in your HTML.
HTML
<script src="../dist/AnyHotKey.min.js"></script>
<input>
JavaScript
const inputElement = document.querySelector('input');
AnyHotKey(inputElement, {
interval: 250, // 主副按键按下的最大时间间隔
key: 13, // 主按键的键代码
subKey: 17, // 副按键的键代码
onKey: function() { // 主按键按下时触发的回调函数
console.log("onKey")
},
onHotkey: function() { // 主副按键按下时触发的回调函数
console.log("onHotkey")
}
});
Example demo_manually.html