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 () {ware ("注册成功");}); }, Register: function (tag, value, func) {var markeyKey = ""; switch (tag) {case 0: markey = 17; // Ctrl Break; Kasus 1: Mainey = 16; // pemutusan pergeseran; Kasus 2: Mainey = "18"; // alt 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 == markey) hotkeyhandler.currentmainkey = keycode; }}} </script> </head> <body> 测试 , 按下 Ctrl+k 你就会发现神奇的事情发生了 </body> </html>