javascript - Keydown and keypress events gives different keyCode -
i've read through related answers , articles on so, still doesn't :
on chrome console if add 2 listeners output keycode on keypress , keydown events different keycode when key lowercase.
when uppercase however, keycode appears same 2 events.
example:
document.addeventlistener('keypress', function(e){ console.log('keypress', e.keycode); }); document.addeventlistener('keydown', function(e){ console.log('keydown', e.keycode); }); // open console // typing 'a' in result field outputs 'keypress 97' 'keydown 65' // on chrome 42 console. activate uppercase, , typing 'a' outputs 'keypress 65' , 'keydown 65' // why ?
so normal behaviour ?
what's difference between keydown , keypress in .net?… explains well. keydown tracking key itself, not state of key. if press a keydown generates keycode of keys.a , if press shift+a keycode of keys.a.
Comments
Post a Comment