<script language="JavaScript"> document.onkeydown = checkKeycode function checkKeycode(e) { var keycode; if (window.event) keycode = window.event.keyCode; else if (e) keycode = e.which; alert("keycode: " + keycode); } </script>
You may also use this sort of function to disable certain keys, by adding a void(0) in the function as shown. This essentially tells the page to cancel the last event, e.g. the pressing of that certain key. In the example below, the key that is disabled is the enter key.
<script language="JavaScript"> document.onkeydown = checkKeycode function checkKeycode(e) { var keycode; if (window.event) keycode = window.event.keyCode; else if (e) keycode = e.which; if(keycode == 13){ void(0); } } </script>
This text was copied verbatim from the'Javascript keyCode checker tool' page http://www.ryancooper.com/resources/keycode.asp