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, Gecko always returns Note: NumLock key's key events indicate |
DOM_KEY_LOCATION_MOBILE ' Obsolete since Gecko 38
|
4 |
The key was on a mobile device; this can be on either a physical keypad or a virtual keyboard. Note: Gecko always returns |
DOM_KEY_LOCATION_JOYSTICK ' Obsolete since Gecko 38
|
5 |
The key was a button on a game controller or a joystick on a mobile device. Note: Gecko never fires trusted key events with |
Syntax
var location = event.location;
Example
function keyEvent(event) {
console.log("Location of key pressed: " + event.location);
}
Specifications
Specification | Status | Comment |
Document Object Model (DOM) Level 3 Events SpecificationThe definition of 'KeyboardEvent.location' in that specification. | Obsolete | Initial definition. |
Browser compatibility
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
Update compatibility data on GitHub
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
location
|
Chrome
Full support Yes |
Edge
Full support 12 |
Firefox
Full support 15 |
IE
Full support 9 |
Opera
Full support Yes |
Safari
Full support 6.1 |
WebView Android
Full support Yes |
Chrome Android
Full support Yes |
Firefox Android
Full support 15 |
Opera Android
Full support Yes |
Safari iOS
Full support 8 |
Samsung Internet Android
Full support Yes |
Legend
- Full support
- Full support
See also
KeyboardEvent.location by Mozilla Contributors is licensed under CC-BY-SA 2.5.