Wednesday, January 9, 2013

JavaScript Determine which key is pressed

Needed to act based on button pressed. So here it is.


function RandomEP(e)
{
var evtobj=window.event? event : e //distinguish between IE's explicit event object (window.event) and Firefox's implicit.
var unicode=evtobj.charCode? evtobj.charCode : evtobj.keyCode
var actualkey=String.fromCharCode(unicode)
if (actualkey=="d")
{
//your code here
}
}

Then in the body tag you insert onkeypress=”RandomEP()” or whatever your function is called.

0 comments:

Post a Comment