Finding Event Key Codes using javascript
by Sanju[ Edit ] 2010-02-01 20:24:49
Finding Event Key Codes using javascript
Use the below code to get keyboard key event number when the specific key is pressed using javascript:
document.onkeydown = trigger;
function trigger(e)
{
if (!e) var e = window.event;
if (e.keyCode) x = e.keyCode;
else if (e.which) x = e.which; // Here x is the key code
alert ("You have pressed the key event "+x+" in keyboard");
}
Result :
If you press space bar the result will be