Dev UtilitiesLesson 143Free preview
JavaScript Key Code Info
This lesson is part of Web Developer Tools · All levels
Summary
This page displays information about the keyboard keys you press, such as event.key, event.code, keyCode, and which. With this data, you can choose the right values when creating shortcuts, game controls, or accessibility-friendly navigation. The keyCode property is outdated, so the new code should use the key or code.
Key points
- Event.key labels a character or function, e.g. a or ArrowLeft
- Event.code refers to the physical position of the button, e.g. KeyA
- KeyCode and which is an old API that's been deprecated
- Listeners mounted on event keydown or keyup
- Provide an alternative so that the shortcut doesn't depend on a single keyboard layout
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.