How to determine which key is pressed in javascript?
A:
You can handle the keydown and keyup events on the document and set a flag for each key.
SLaks
2010-06-14 19:57:36
A:
in the function which takes the key event:
function(e){
var key = String.fromCharCode(e.keyCode);
}
mkoryak
2010-06-14 19:57:40
@Matt I'll give you a -1 for sarcasm. And a +1 for being right. =P
Aaron Harun
2010-06-14 20:03:53
+1
A:
In jQuery:
jQuery(window).live('keydown', function(e) {
var keyCode = e.keyCode || e.which;
//do stuff with keycode
}
});
Normal:
document.onkeyup = KeyCheck;
function KeyCheck(){
var KeyID = event.keyCode;
//do stuff
}
Aaron Harun
2010-06-14 19:59:38