LDRをパクった参考にした。
とりあえず、IE/FF/Operaで動作確認。MacとSafariは不明。
Firefoxの「キー入力時に検索を開始する」はstop_eventで抑止。
<html> <head> <script> function add_event(obj, type, handler, flag) { function handler_wrapper(e) { e = e || event; return handler(e); } if (obj.addEventListener) { obj.addEventListener(type, handler_wrapper, flag); } else if (obj.attachEvent) { obj.attachEvent("on" + type, handler_wrapper); } } cancel_event = function(e) { e.preventDefault ? e.preventDefault() : (e.returnValue = false); }; stop_event = function(e) { e.stopPropagation ? e.stopPropagation() : (e.cancelBubble = true); }; function add_key_event(obj, event, handler, flag) { function handler_wrapper(e) { var key = e.keyCode || e.which; return handler(e, key, e.altKey, e.ctrlKey, e.shiftKey); } add_event(obj, event, handler_wrapper, flag); } function log(x) { var console = document.getElementById('console'); console.innerHTML = x; } add_key_event(document, 'keydown', function(e, key, alt, ctrl, shift) { var msg = 'key:' + key + ' alt:' + alt + ' ctrl:' + ctrl + ' shift:' + shift; log(msg); stop_event(e); cancel_event(e); return false; }); </script> </head> <body> abcdefg hijklmn opqrstu vwxyz <div id="console"></div> </body> </html>