KeyboardEvent.location - Web APIs 编辑

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:

ConstantValueDescription
DOM_KEY_LOCATION_STANDARD0The 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_LEFT1The 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_RIGHT2The 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_NUMPAD3

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 DOM_KEY_LOCATION_NUMPAD for the keys on the numeric pad. Otherwise, when NumLock is unlocked and the keyboard actually has a numeric keypad, Gecko 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 Gecko and Internet Explorer.
DOM_KEY_LOCATION_MOBILE This API has not been standardized.Obsolete since Gecko 384

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_MOBILE on Android (Prior to 18), Maemo, and Boot to Gecko. However, at Gecko 38, this is dropped.
DOM_KEY_LOCATION_JOYSTICK This API has not been standardized.Obsolete since Gecko 385

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

Note: Gecko never fires trusted key events with DOM_KEY_LOCATION_JOYSTICK except on Android. Starting 18, native key events on Android may have this value. However, at Gecko 38, this is dropped.

Syntax

var location = event.location;

Example

function keyEvent(event) {
  console.log("Location of key pressed: " + event.location);
}

Specifications

SpecificationStatusComment
Document Object Model (DOM) Level 3 Events Specification
The definition of 'KeyboardEvent.location' in that specification.
ObsoleteInitial definition.

Browser compatibility

BCD tables only load in the browser

See also

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:110 次

字数:5456

最后编辑:6年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文