locationEvent Attributes

事件对象参考手册Event Object

Example

Get the position of the key:

var x = event.location;

xThe output result is:

0

Try it yourself »


Definition and Usage

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

The number can be represented by 4 constants:

0. DOM_KEY_LOCATION_STANDARD:

Represents a key that is not the leftmost or rightmost key, and not a number on the numeric keypad (this value includes almost all keys, such as "A", "U", "SPACE" or "5")

1. DOM_KEY_LOCATION_LEFT:

Left key (if the left "CTRL" key or left "ALT" key)

2. DOM_KEY_LOCATION_RIGHT:

Right key (if the right "CTRL" key or left "ALT" key)

3. DOM_KEY_LOCATION_NUMPAD:

Number key (on the right side of a standard keyboard)

Note:The location property can be used foronkeydownandonkeyupevents, but cannot be used foronkeypressevents.

Note:This property is read-only.


Browser Support

The numbers in the table indicate the version number of the first browser that supports this property.

Property
location Yes 9.0 15.0 Not supported Yes


Syntax

event.location

Technical Details

Return Value: A number representing the position of the key on the keyboard or device.

4 numbers can be represented by 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


事件对象参考手册Event Object

Other Extensions