aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/keyboardevent/location/index.html
blob: 753da8023ad775586d18f5215c6a47467653df8f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
---
title: KeyboardEvent.location
slug: Web/API/KeyboardEvent/location
translation_of: Web/API/KeyboardEvent/location
---
<div>{{APIRef("DOM Events")}}</div>

<p><code><strong>KeyboardEvent.location</strong></code> 是一个只读属性,返回一个无符号的长整型 <code>unsigned long</code>,表示按键在键盘或其他设备上的位置</p>

<p>可选值:</p>

<table class="standard-table">
 <tbody>
  <tr>
   <td class="header">Constant</td>
   <td class="header">Value</td>
   <td class="header">Description</td>
  </tr>
  <tr>
   <td><code>DOM_KEY_LOCATION_STANDARD</code></td>
   <td>0</td>
   <td>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.</td>
  </tr>
  <tr>
   <td><code>DOM_KEY_LOCATION_LEFT</code></td>
   <td>1</td>
   <td>The key was the left-hand version of the key; for example, the left-hand <kbd>Control</kbd> 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.</td>
  </tr>
  <tr>
   <td><code>DOM_KEY_LOCATION_RIGHT</code></td>
   <td>2</td>
   <td>The key was the right-hand version of the key; for example, the right-hand <kbd>Control</kbd> 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.</td>
  </tr>
  <tr>
   <td><code>DOM_KEY_LOCATION_NUMPAD</code></td>
   <td>3</td>
   <td>
    <p>The key was on the numeric keypad, or has a virtual key code that corresponds to the numeric keypad.</p>

    <div class="note"><strong>Note:</strong> When <kbd>NumLock</kbd> is locked, Gecko always returns <code>DOM_KEY_LOCATION_NUMPAD</code> for the keys on the numeric pad. Otherwise, when <kbd>NumLock</kbd> is unlocked and the keyboard actually has a numeric keypad, Gecko always returns <code>DOM_KEY_LOCATION_NUMPAD</code> 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 <code>DOM_KEY_LOCATION_NUMPAD</code>.</div>

    <div class="note"><strong>Note:</strong> <kbd>NumLock</kbd> key's key events indicate <code>DOM_KEY_LOCATION_STANDARD</code> both on Gecko and Internet Explorer.</div>
   </td>
  </tr>
  <tr>
   <td><code>DOM_KEY_LOCATION_MOBILE</code> {{Non-standard_inline()}}{{obsolete_inline(38)}}</td>
   <td>4</td>
   <td>
    <p>The key was on a mobile device; this can be on either a physical keypad or a virtual keyboard.</p>

    <div class="note"><strong>Note: </strong>Gecko always returns <code>DOM_KEY_LOCATION_MOBILE</code> on Android (Prior to 18), Maemo, and <a href="/en-US/docs/Mozilla/Boot_to_Gecko" title="Boot to Gecko">Boot to Gecko</a>. However, at {{gecko("38")}}, this is dropped.</div>
   </td>
  </tr>
  <tr>
   <td><code>DOM_KEY_LOCATION_JOYSTICK</code> {{Non-standard_inline()}}{{obsolete_inline(38)}}</td>
   <td>5</td>
   <td>
    <p>The key was a button on a game controller or a joystick on a mobile device.</p>

    <div class="note"><strong>Note: </strong>Gecko never fires trusted key events with <code>DOM_KEY_LOCATION_JOYSTICK</code> except on Android. Starting 18, native key events on Android may have this value. {{gecko_minversion_inline("18.0")}} However, at {{gecko("38")}}, this is dropped.</div>
   </td>
  </tr>
 </tbody>
</table>

<h2 id="Syntax">Syntax</h2>

<pre class="syntaxbox">var <em>location</em> = <em>event</em>.location;</pre>

<h2 id="Example">Example</h2>

<pre class="brush: js">function keyEvent(event) {
  console.log("Location of key pressed: " + event.location);
}
</pre>

<h2 id="Specifications">Specifications</h2>

<table class="standard-table">
 <tbody>
  <tr>
   <th scope="col">Specification</th>
   <th scope="col">Status</th>
   <th scope="col">Comment</th>
  </tr>
  <tr>
   <td>{{SpecName('DOM3 Events', '#widl-KeyboardEvent-location', 'KeyboardEvent.location')}}</td>
   <td>{{Spec2('DOM3 Events')}}</td>
   <td>Initial definition.</td>
  </tr>
 </tbody>
</table>

<h2 id="Browser_compatibility">Browser compatibility</h2>



<p>{{Compat("api.KeyboardEvent.location")}}</p>

<h2 id="See_also">See also</h2>

<ul>
 <li>{{domxref("KeyboardEvent")}}</li>
</ul>