KeyboardEvent location Property
THE WORLD'S LARGEST WEB DEVELOPER SITE

KeyboardEvent location Property

❮ DOM Events ❮ KeyboardEvent

Example

Get the location of the key:

var x = event.location;
Try it Yourself »

Definition and Usage

The location property returns a number that indicates the location of a key on the keyboard or device.

The number is represented by 4 constants:

0. DOM_KEY_LOCATION_STANDARD:

The key is not pressed on the right or left side of the keyboard, and was not pressed on the numeric keypad (this value represents almost every key on the keyboard, e.g. "A", "U", "SPACE" or "5")

1. DOM_KEY_LOCATION_LEFT:

A left key was pressed (e.g. the left "CTRL" key or left "ALT" key on a standard 101 key US keyboard)

2. DOM_KEY_LOCATION_RIGHT:

A right key was pressed (e.g. the right "CTRL" key or right "CTRL" key on a standard 101 key US keyboard)

3. DOM_KEY_LOCATION_NUMPAD:

The key was pressed on the numeric keypad (e.g. the "2" key on the right side on a standard keyboard)

Note: The location property can only be used on the onkeydown and onkeyup event, not onkeypress.

Note: This property is read-only.


Browser Support

The numbers in the table specify the first browser version that fully supports the property.

Property
location Yes 9.0 15.0 Not supported Yes

Syntax

event.location

Technical Details

Return Value: A Number, representing the location of a key on the keyboard or device

The number is represented by 4 constants:

0. DOM_KEY_LOCATION_STANDARD
1. DOM_KEY_LOCATION_LEFT
2. DOM_KEY_LOCATION_RIGHT
3. DOM_KEY_LOCATION_NUMPAD

DOM Version: DOM Level 3 Events

❮ DOM Events ❮ KeyboardEvent