JS 代码
<html> <head> <script type = "text/javaScript"> window.onload = function () {hotkeyhandler.init () ؛ } var hotkeyhandler = {currentmainkey: null ، currentValueKey: null ، init: function () {hotkeyhandler.register (0 ، "k" ، function () {Alert ("注册成功") ؛}) ؛ } ، التسجيل: الدالة (العلامة ، القيمة ، func) {var mainkey = "" ؛ Switch (TAG) {case 0: mainkey = 17 ؛ // استراحة Ctrl ؛ الحالة 1: mainkey = 16 ؛ // كسر الانفصال. الحالة 2: mainkey = "18" ؛ // BET Break ؛ } document.onkeyup = function (e) {hotkeyhandler.currentMainKey = null ؛ } document.onkeydown = function (event) {// 获取键值 var keycode = event.keycode ؛ var keyvalue = string.fromcharcode (event.keycode) ؛ if (hotkeyhandler.currentMainKey! = null) {if (keyvalue == value) {hotkeyhandler.currentMainKey = null ؛ if (func! = null) func () ؛ }} if (keycode == mainkey) hotkeyhandler.currentMainKey = keycode ؛ })