5 ms·
When you attach 'keypress' event it will give char code which can be easily converted to sign, e.g.: document.addEventListener('keypress', function(event)
by jarek-foksa 15y ago
When you attach 'keypress' event it will give char code which can be easily converted to sign, e.g.:
document.addEventListener('keypress', function(event) {
sign = String.fromCharCode(event.charCode);
if (sign === 'A') {
console.log('Pressed shift+a');
}
else if (sign === 'c' && event.ctrlKey) {
console.log('Pressed ctrl+c');
}
});
I have tested this technique with several layouts (azerty, dvorak, bepo) and it seems to be working fine. For special keys such as enter, esc or backspace you will have to listen for 'keydown' event instead.