HOME BLOG PORTFOLIO PHOTO CONTACT Admin Login
How can we know which key is pressed

Which key you have pressed in web page for try you need to press Left Arrow Key or Right Arrow Key or Esc Key then you see the result

NOTE : If you don't have  jquery.js don't worry go to google com search  jquery-1.2.6.pack.js / or jquery.js  and save it as above name in appropriate folder.


< !DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Key press jquery , javascript code jay bharat</title>
</head>
<script src='jquery-1.2.6.pack.js'  type='text/javascript'></script>
<script>
$(document).keyup(function(e) {
var code;
if (!e) var e = window.event;
if (e.keyCode) code = e.keyCode;
else if (e.which) code = e.which;
alert("Key Code="+e.which);
if(e.which == '39')
{
alert("Right");
}
else if(e.which == '37')
{
alert("Left");
}
else if(e.which == '27')
{
alert("Esc");
}
});
</script>
<body>
<table width="100%" border="0">
<tr>
<td>You can press left Arrow, Right arrow ,Esc Key</td>
</tr>
</table>

</body>
</html>

   Share on Facebook

Page views:929