View Single Post
Old 01-22-2013, 07:50 PM   PM User | #2
sunfighter
Senior Coder

 
Join Date: Jan 2011
Location: Missouri
Posts: 2,383
Thanks: 18
Thanked 350 Times in 349 Posts
sunfighter is on a distinguished road
I am giving you pure javascript for this not jquery as you have. This is how to detect a key press and gets what key was pressed. This code uses an input box, but if you remove the comment on the first js line you will get the alerts if a key is typed anywhere. FYI the anywhere thing does not work in IE, use the box.

Code goes in <body>
Code:
<script type="text/javascript">
//document.onkeyup=displayunicode;

function displayunicode(e){
var unicode=e.keyCode? e.keyCode : e.charCode
//alert(unicode);  // USE THIS TO SEE THE CODES
if (unicode == 65) alert("its an A"); // INSTEAD OF AN ALERT USE THIS TO CALL THE XML
if (unicode == 66) alert("its an B");
if (unicode == 67) alert("its an C");
if (unicode == 68) alert("its an D");
}
</script>

<form>
<input type="text" size="2" maxlength="1" onkeyup="displayunicode(event);" />
</form>
PS: onkeyup and onkeydown are the only things that work.
sunfighter is offline   Reply With Quote