KeyboardEvent code property

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 ensure the correct character is returned, please use event.key.

Example

Return the key pressed:

var x = event.code;

Try it yourself

Syntax

event.code

Technical details

Return value: String value representing the key pressed.

Browser supports

Atribute Chrome IE Firefox Safari Opera
code 48 Hindi Suportado 32 10 Suporta

Nakakasangguni na Pahina

HTML DOM Reference Manual:KeyboardEvent key Atribute

HTML DOM Reference Manual:KeyboardEvent charCode Atribute

HTML DOM Reference Manual:KeyboardEvent keyCode Atribute