KeyboardEvent code Property

Example

Return the key that was pressed:

let key = event.code;
Try it Yourself »

Description

The code property returns the key code when a keyboard event occurs.

The code property is read-only.

Warning!

The code property returns different values for different keyboard layouts.

Use the key property instead.


Syntax

event.code

Technical Details

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

Browser Support

event.code is a DOM Level 4 (2015) feature.

It is supported in all modern browsers:

Chrome Edge Firefox Safari Opera
Yes Yes Yes Yes Yes

event.code is not supported in Internet Explorer 11 (or earlier).



Copyright 1999-2023 by Refsnes Data. All Rights Reserved.