The MDN documentation states the following:
You should avoid using this (keyCode) if possible; it's been deprecated for some time. Instead, you should use KeyboardEvent.code, if it's implemented. Unfortunately, some browsers still don't have it, so you'll have to be careful to make sure you use one which is supported on all target browsers.
https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/keyCode
If you need to support older browsers (like Internet Explorer) you may want to use feature detection to use the correct one.
if (event.code !== undefined) {
// Handle the event with KeyboardEvent.key
}
else if (event.keyCode !== undefined) {
// Handle the event with KeyboardEvent.keyCode
}