I found that keypress
is not returning the correct charCode value.
http://jsfiddle.net/cheonhyang/t9hL1k1n/
HTML:
<h1> keydown, keyup and keypress event</h1>
<input id="input"></input>
JS:
var input = document.getElementById('input');
input.addEventListener('keydown', function(e){
console.log("input keydown");
console.log("which: " + e.which);
console.log("keyCode: " + e.keyCode);
console.log("charCode: " + e.charCode);
});
input.addEventListener('keyup', function(e){
console.log("input keyup");
console.log("which: " + e.which);
console.log("keyCode: " + e.keyCode);
console.log("charCode: " + e.charCode);
});
input.addEventListener('keypress', function(e){
console.log("input keypress");
console.log("which: " + e.which);
console.log("keyCode: " + e.keyCode);
console.log("charCode: " + e.charCode);
});
When pressed "a", the charCode is returning "A", while when pressed "A", the charCode is returning "a".
It's very weird.
When typing "a", the result will be :
input keydown
which: 65
keyCode: 65
charCode: 0
input keypress
which: 97
keyCode: 97
charCode: 97
input keyup
which: 65
keyCode: 65
charCode: 0