Course Recommendation:

KeyboardEvent location property

Definition and Usage

This number is represented by 4 constants:

The location property returns a number indicating the position of the key on the keyboard or device.

0. DOM_KEY_LOCATION_STANDARD:

The key is not pressed on the right or left side of the keyboard, nor on the numeric keypad (this value represents almost every key on the keyboard, such as "A", "U", "SPACE", or "5")

1. DOM_KEY_LOCATION_LEFT:

The left key is pressed (e.g., the left "CTRL" key or left "ALT" key on the standard 101-key US keyboard)

2. DOM_KEY_LOCATION_RIGHT:

The right key is pressed (e.g., the right "CTRL" key or right "ALT" key on the standard 101-key US keyboard)

3. DOM_KEY_LOCATION_NUMPAD:

Note:Pressing the key on the numeric keypad (e.g., the "2" key on the standard keyboard on the right) The location property can only be used onkeydown and event, cannot be used onkeypress.

Note:This property is read-only.

Example

Get the position of the key:

var x = event.location;

Try It Yourself

Syntax

event.location

Technical Details

Return value:

Numeric value, indicating the position of the key on the keyboard or device.

This 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

Browser Support

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

Properties Chrome IE Firefox Safari Opera
location Supported 9.0 15.0 Not Supported Supported