KeyboardEvent code Property
THE WORLD'S LARGEST WEB DEVELOPER SITE

KeyboardEvent code Property

❮ DOM Events ❮ KeyboardEvent

Example

Return the key that was pressed:

var x = event.code;
Try it Yourself »

Definition and Usage

The code property returns the key that triggered the event.

Note: This property returns different values for different keyboard layouts.

Tip: To make sure you return the correct character, use event.key instead


Browser Support

Property
code 48 Not supported 32 10 Yes


Syntax

event.code

Technical Details

Return Value: A String, representing the key that was pressed

Related Pages

HTML DOM reference: KeyboardEvent key Property

HTML DOM reference: KeyboardEvent charCode Property

HTML DOM reference: KeyboardEvent keyCode Property


❮ DOM Events ❮ KeyboardEvent