Javascript event keypress returns invalid value with uncased
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 "a" is pressed, charCode returns "A", and when "A" is pressed, charCode returns "a".
It is very strange.
Typing "a" will result in:
keydown input which are: 65 keyCode: 65 charCode: 0
keystroke which: 97 keyCode: 97 charCode: 97
input keyboard which are: 65 keyCode: 65 charCode: 0
+3
source to share
No one has answered this question yet
See similar questions:
or similar: