JS 代码
<html> <Head> <script type = "text/javascript"> window.onload = function () {hotkeyhandler.init (); } var hotkeyhandler = {currentMainkey: null, currentValueKey: null, init: function () {hotkeyhandler.gregister (0, "k", function () {alert ("注册成功");}); }, Регистр: function (tag, value, func) {var mainkey = ""; Switch (Tag) {case 0: Mainekey = 17; // CTRL Break; Случай 1: MANEKEY = 16; // сдвиг перерыв; Случай 2: Mainkey = "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 == mainekey) hotkeyhandler.currentmainkey = keyCode; }}} </script> </head> <body> 测试 , 按下 ctrl+k 你就会发现神奇的事情发生了 </body> </html>