I am tyring to read the input characters on keydown event and try to process them. When I am triing to convert them into character using "String.fromCharCode(key);" Its always giving me the capital letters.
Upadte: Strangely the code works if I listen for "keypress" event. What is the reason for this. Could some one please explain this behavoir.
The sample code is given below:
var inp = document.getElementById("ti");
inp.addEventListener("keydown", onKeyDown);
function onKeyDown(e) {
if (window.event) {
var key = window.event.keyCode;
} else {
var key = e.keyCode;
}
document.getElementById("output").innerHTML += String.fromCharCode(key);
}
What is the best practice to read the character on keydown event