KeyboardEvent: location property

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

The KeyboardEvent.location read-only property returns an unsigned long representing the location of the key on the keyboard or other input device.

Possible values are:

Constant Value Description
DOM_KEY_LOCATION_STANDARD 0 The key has only one version, or can't be distinguished between the left and right versions of the key, and was not pressed on the numeric keypad or a key that is considered to be part of the keypad.
DOM_KEY_LOCATION_LEFT 1 The key was the left-hand version of the key; for example, the left-hand Control key was pressed on a standard 101 key US keyboard. This value is only used for keys that have more than one possible location on the keyboard.
DOM_KEY_LOCATION_RIGHT 2 The key was the right-hand version of the key; for example, the right-hand Control key is pressed on a standard 101 key US keyboard. This value is only used for keys that have more than one possible location on the keyboard.
DOM_KEY_LOCATION_NUMPAD 3

The key was on the numeric keypad, or has a virtual key code that corresponds to the numeric keypad.

Note: When NumLock is locked, Firefox always returns DOM_KEY_LOCATION_NUMPAD for the keys on the numeric pad. Otherwise, when NumLock is unlocked and the keyboard actually has a numeric keypad, Firefox always returns DOM_KEY_LOCATION_NUMPAD too. On the other hand, if the keyboard doesn't have a keypad, such as on a notebook computer, some keys become Numpad only when NumLock is locked. When such keys fires key events, the location attribute value depends on the key. That is, it must not be DOM_KEY_LOCATION_NUMPAD.

Note: NumLock key's key events indicate DOM_KEY_LOCATION_STANDARD both on Firefox and Internet Explorer.

DOM_KEY_LOCATION_MOBILE 4

The key was on a mobile device; this can be on either a physical keypad or a virtual keyboard.

DOM_KEY_LOCATION_JOYSTICK 5

The key was a button on a game controller or a joystick on a mobile device.

Value

A number.

Examples

js
function keyEvent(event) {
  console.log(`Location of key pressed: ${event.location}`);
}

Specifications

Specification
UI Events
# dom-keyboardevent-location

Browser compatibility

desktop mobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
location
Chrome – Full support
Chrome 30 (Release date: 2013-10-01)
footnote Full support
Edge – Full support
Edge 12 (Release date: 2015-07-29)
footnote Full support
Firefox – Full support
Firefox 15 (Release date: 2012-08-28)
footnote Full support
Opera – Full support
Opera 17 (Release date: 2013-10-08)
footnote Full support
Safari – Full support
Safari 8 (Release date: 2014-10-16)
footnote Full support
Chrome Android – Full support
Chrome Android 30 (Release date: 2013-10-02)
footnote Full support
Firefox for Android – Full support
Firefox for Android 15 (Release date: 2012-08-28)
footnote Full support
Opera Android – Full support
Opera Android 18 (Release date: 2013-11-20)
footnote Full support
Safari on iOS – Full support
Safari on iOS 8 (Release date: 2014-09-17)
footnote Full support
Samsung Internet – Full support
Samsung Internet 2 (Release date: 2014-10-17)
footnote Full support
WebView Android – Full support
WebView Android 4.4 (Release date: 2013-12-09)
footnote Full support
WebView on iOS – Full support
WebView on iOS 8 (Release date: 2014-09-17)
footnote Full support

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support

See also