What is replacing Javascript keyCode?

how are we writing the following, to see if a letter of the alphabet is being pressed, now keyCode is deprecated?
if (e.keyCode > 64 && e.keyCode < 91) {
console.log('alphabet letter pressed')
}
if (e.keyCode > 64 && e.keyCode < 91) {
console.log('alphabet letter pressed')
}
4 Replies
Doksuri
Doksuriβ€’3w ago
e.key ? ah i see.. you need a range i guess e.key + regep :/
if(e.key.match(/[a-zA-Z]/) { console.log('letter presseed'); }
if(e.key.match(/[a-zA-Z]/) { console.log('letter presseed'); }
Mannix
Mannixβ€’3w ago
MDN Web Docs
KeyboardEvent: key property - Web APIs | MDN
The KeyboardEvent interface's key read-only property returns the value of the key pressed by the user, taking into consideration the state of modifier keys such as Shift as well as the keyboard locale and layout.
Chooβ™šπ•‚π•šπ•Ÿπ•˜
MDN Web Docs
KeyboardEvent: code property - Web APIs | MDN
The KeyboardEvent.code property represents a physical key on the keyboard (as opposed to the character generated by pressing the key). In other words, this property returns a value that isn't altered by keyboard layout or the state of the modifier keys.
Blackwolf
BlackwolfOPβ€’3w ago
Thank you guys
Want results from more Discord servers?
Add your server