Reacting to Keyboard Events

Learn about the type of events that occur when using a keyboard.

We'll cover the following

The most common solution for reacting to key presses on a keyboard involves handling keypress events that happen on a web page (the DOM body element, which corresponds to the global variable called document in JavaScript).

Keyboard event properties

The following example shows in the console the character associated with a pressed key. The character info is given by the charCode property of the Event object associated with the event. This property returns a numerical value (called Unicode value) that can be translated to a string value by the String.FromCharCode() method.

Get hands-on with 1200+ tech skills courses.