Can anyone shed some light on why numpad keyup and keydown events return different key values?
Consider this:
<input type="text" />
<script>
document.getElement('input').addEvents({
'keydown':function(e){
console.log('keydown: code:' + e.code + ', key:' + e.key);
},
'keyup':function(e){
console.log('keyup : code:' + e.code + ', key:' + e.key + '\n');
}
});
</script>
I was expecting each event to return the same key value for both keydown and keyup but instead, I got the output below (after pressing 0,1,2,8 and 9):
keydown: code:96, key:0
keyup : code:96, key:`keydown: code:97, key:1
keyup : code:97, key:akeydown: code:98, key:2
keyup : code:98, key:bkeydown: code:104, key:8
keyup : code:104, key:hkeydown: code:105, key:9
keyup : code:105, key:i
Normally I would use keypress, and as such, have never had any problems. I came across this when highlighting numpad representative buttons on the screen when the corresponding numpad key was pressed on the keyboard (highlight on down, and remove highlight on up).
Any ideas?