mozilla
您的搜索结果

    KeyboardEvent

    KeyboardEvent objects describe a user interaction with the keyboard. Each event describes a key; the event type (keydown, keypress, or keyup) identifies what kind of activity was performed.

    Note: The KeyboardEvent indicates just what's happening on a key. When you need to handle text input, use HTML5 input event instead. For example, if user inputs text from hand-writing system like tablet PC, key events may not be fired.

    Method overview

    boolean getModifierState(in DOMString keyArg);
    void initKeyboardEvent(in DOMString typeArg, in boolean canBubbleArg, in boolean cancelableArg, in views::AbstractView viewArg, in DOMString charArg, in DOMString keyArg, in unsigned long locationArg, in DOMString modifiersListArg, in boolean repeat, in DOMString localeArg);

    Attributes

    Attribute Type Description
    altKey boolean true if the Alt (or Option, on Mac) key was active when the key event was generated. Read only.
    char DOMString

    The character value of the key. If the key corresponds to a printable character, this value is a non-empty Unicode string containing that character. If the key doesn't have a printable representation, this is an empty string. See key names and char values for the detail. Read only.

    Note: If the key is used as a macro that inserts multiple characters, this attribute's value is the entire string, not just the first character.

    Gecko note: Not yet implemented; see bug 680830.

    This attribute is not implemented in Gecko at this time.

    charCode unsigned long

    The Unicode reference number of the key; this attribute is used only by the keypress event. For keys whose char attribute contains multiple characters, this is the Unicode value of the first character in that attribute. Read only.

    Warning: This attribute is deprecated; you should use char instead, if available.
    ctrlKey boolean true if the Control key was active when the key event was generated. Read only.
    key DOMString

    The key value of the key represented by the event. If the value has a printed representation, this attribute's value is the same as the char attribute. Otherwise, it's one of the key value strings specified in Key values. If the key can't be identified, this is the string "Unidentified". See key names and char values for the detail. Read only.

    Gecko note: Not yet implemented; see bug 680830.

    This attribute is not implemented in Gecko at this time.

    keyCode

    unsigned long

    A system and implementation dependent numerical code identifying the unmodified value of the pressed key. This is usually the decimal ASCII (RFC 20) or Windows 1252 code corresponding to the key; see Virtual key codes for a list of common values. If the key can't be identified, this value is 0. Read only.

    Warning: This attribute is deprecated; you should use key instead, if available.
    locale DOMString

    A locale string indicating the locale the keyboard is configured for. This may be the empty string if the browser or device doesn't know the keyboard's locale. Read only.

    Note: This does not describe the locale of the data being entered. A user may be using one keyboard layout while typing text in a different language.

    location DOM level 3

    unsigned long

    The location of the key on the keyboard or other input device; see Key location constants below. Read only.

    metaKey boolean true if the Meta (or Command, on Mac) key was active when the key event was generated. Read only.
    repeat boolean

    true if the key is being held down such that it is automatically repeating. Read only.

    Gecko note: Not yet implemented; see bug 600117.

    This attribute is not implemented in Gecko at this time.

    shiftKey boolean true if the Shift key was active when the key event was generated. Read only.
    which unsigned long

    A system and implementation dependent numeric code identifying the unmodified value of the pressed key; this is usually the same as keyCode. Read only.

    Warning: This attribute is deprecated; you should use key instead, if available.

    Constants

    Virtual key codes

    已废弃
    该特性已经从 Web 标准中删除,虽然一些浏览器目前仍然支持它,但也许会在未来的某个时间停止支持,请尽量不要使用该特性。

    These constants represent virtual key codes as reported by the deprecated keyCode attribute; that is, keys that do not correspond to printable characters. The diagram below represents a standard ANSI US keyboard; Mac and most PC keyboards have the same layout for the printable characters, and a similar layout for the remaining keys.

    Starting in Gecko 15 (Firefox 15.0 / Thunderbird 15.0 / SeaMonkey 2.12), Gecko decides keycode by following rules for printable keys:

    1. If the system is Windows and native keycode of pressed key indicates that the key is a-z or 0-9, uses a keycode for it.
    2. If the system is Mac and native keycode of pressed key indicates that the key is 0-9, uses a keycode for it.
    3. If pressed key inputs an ASCII alphabet or numeric with no modifier key, uses a keycode for it.
    4. If pressed key inputs an ASCII alphabet or numeric with Shift key, uses a keycode for it.
    5. If pressed key inputs another ASCII character with no modifier key, uses a keycode for it.
    6. If pressed key inputs another ASCII character with Shift key, users a keycode for it.
    7. Otherwise, i.e., pressed key inputs a Unicode character:
      1. If the keyboard layout is ASCII capable keyboard layout (i.e., can input ASCII alphabets), uses 0.
      2. Otherwise, i.e., the keyboard layout isn't ASCII capable, using ASCII capable keyboard layout which is installed on the environment and has highest priority:
        1. If pressed key on the alternative keyboard layout inputs an ASCII alphabet or numeric, uses a keycode for it.
        2. Otherwise, uses 0.
    Note: Web developers shouldn't use keycode attribute of printable keys in keydown and keyup event handlers. As described above, keycode is not usable for checking character which will be inputted especially when Shift key or AltGr key is pressed. When web developers implement shortcut key handler, keypress event is better event for that purpose on Gecko at least. See Gecko Keypress Event for the detail.
    Constant Value Description
    DOM_VK_CANCEL 3 Cancel key.
    DOM_VK_HELP 6 Help key.
    DOM_VK_BACK_SPACE 8 退格键.
    DOM_VK_TAB 9 Tab键.
    DOM_VK_CLEAR 12 "5" key on Numpad when NumLock is unlocked. Or on Mac, clear key which is positioned at NumLock key.
    DOM_VK_RETURN 13 Return/enter key on the main keyboard.
    DOM_VK_ENTER 14 Reserved, but not used.
    DOM_VK_SHIFT 16 Shift 键.
    DOM_VK_CONTROL 17 Ctrl 键.
    DOM_VK_ALT 18 Alt 键(Mac上为Option 键).
    DOM_VK_PAUSE 19 Pause key.
    DOM_VK_CAPS_LOCK 20 Caps lock.
    DOM_VK_ESCAPE 27 Escape 键.
    DOM_VK_SPACE 32 空格键.
    DOM_VK_PAGE_UP 33 Page Up key.
    DOM_VK_PAGE_DOWN 34 Page Down key.
    DOM_VK_END 35 End key.
    DOM_VK_HOME 36 Home key.
    DOM_VK_LEFT 37 Left arrow.
    DOM_VK_UP 38 Up arrow.
    DOM_VK_RIGHT 39 Right arrow.
    DOM_VK_DOWN 40 Down arrow.
    DOM_VK_SELECT 41  
    DOM_VK_PRINT 42  
    DOM_VK_EXECUTE 43  
    DOM_VK_PRINTSCREEN 44 Print Screen key.
    DOM_VK_INSERT 45 Ins(ert) key.
    DOM_VK_DELETE 46 Del(ete) key.
    DOM_VK_0 48  
    DOM_VK_1 49  
    DOM_VK_2 50  
    DOM_VK_3 51  
    DOM_VK_4 52  
    DOM_VK_5 53  
    DOM_VK_6 54  
    DOM_VK_7 55  
    DOM_VK_8 56  
    DOM_VK_9 57  
    DOM_VK_COLON 58 Colon (":") key.
    DOM_VK_SEMICOLON 59 Semicolon (";") key.
    DOM_VK_LESS_THAN 60 Less-than ("<") key.
    DOM_VK_EQUALS 61 Equals ("=") key.
    DOM_VK_GREATER_THAN 62 Greater-than (">") key.
    DOM_VK_QUESTION_MARK 63 Question mark ("?") key.
    DOM_VK_AT 64 Atmark ("@") key.
    DOM_VK_A 65  
    DOM_VK_B 66  
    DOM_VK_C 67  
    DOM_VK_D 68  
    DOM_VK_E 69  
    DOM_VK_F 70  
    DOM_VK_G 71  
    DOM_VK_H 72  
    DOM_VK_I 73  
    DOM_VK_J 74  
    DOM_VK_K 75  
    DOM_VK_L 76  
    DOM_VK_M 77  
    DOM_VK_N 78  
    DOM_VK_O 79  
    DOM_VK_P 80  
    DOM_VK_Q 81  
    DOM_VK_R 82  
    DOM_VK_S 83  
    DOM_VK_T 84  
    DOM_VK_U 85  
    DOM_VK_V 86  
    DOM_VK_W 87  
    DOM_VK_X 88  
    DOM_VK_Y 89  
    DOM_VK_Z 90  
    DOM_VK_CONTEXT_MENU 93  
    DOM_VK_NUMPAD0 96 0 on the numeric keypad.
    DOM_VK_NUMPAD1 97 1 on the numeric keypad.
    DOM_VK_NUMPAD2 98 2 on the numeric keypad.
    DOM_VK_NUMPAD3 99 3 on the numeric keypad.
    DOM_VK_NUMPAD4 100 4 on the numeric keypad.
    DOM_VK_NUMPAD5 101 5 on the numeric keypad.
    DOM_VK_NUMPAD6 102 6 on the numeric keypad.
    DOM_VK_NUMPAD7 103 7 on the numeric keypad.
    DOM_VK_NUMPAD8 104 8 on the numeric keypad.
    DOM_VK_NUMPAD9 105 9 on the numeric keypad.
    DOM_VK_MULTIPLY 106 * on the numeric keypad.
    DOM_VK_ADD 107 + on the numeric keypad.
    DOM_VK_SEPARATOR 108  
    DOM_VK_SUBTRACT 109 - on the numeric keypad.
    DOM_VK_DECIMAL 110 Decimal point on the numeric keypad.
    DOM_VK_DIVIDE 111 / on the numeric keypad.
    DOM_VK_F1 112 F1 键.
    DOM_VK_F2 113 F2 键.
    DOM_VK_F3 114 F3 键.
    DOM_VK_F4 115 F4 键.
    DOM_VK_F5 116 F5 键.
    DOM_VK_F6 117 F6 键.
    DOM_VK_F7 118 F7 键.
    DOM_VK_F8 119 F8 键.
    DOM_VK_F9 120 F9 键.
    DOM_VK_F10 121 F10 键.
    DOM_VK_F11 122 F11 键.
    DOM_VK_F12 123 F12 键.
    DOM_VK_F13 124 F13 键.
    DOM_VK_F14 125 F14 键.
    DOM_VK_F15 126 F15 键.
    DOM_VK_F16 127 F16 键.
    DOM_VK_F17 128 F17 键.
    DOM_VK_F18 129 F18 键.
    DOM_VK_F19 130 F19 键.
    DOM_VK_F20 131 F20 键.
    DOM_VK_F21 132 F21 键.
    DOM_VK_F22 133 F22 键.
    DOM_VK_F23 134 F23 键.
    DOM_VK_F24 135 F24 键.
    DOM_VK_NUM_LOCK 144 Num Lock key.
    DOM_VK_SCROLL_LOCK 145 Scroll Lock key.
    DOM_VK_CIRCUMFLEX 160 Circumflex ("^") key.
    DOM_VK_EXCLAMATION 161 Exclamation ("!") key.
    DOM_VK_DOUBLE_QUOTE 162 Double quote (""") key.
    DOM_VK_HASH 163 Hash ("#") key.
    DOM_VK_DOLLAR 164 Dollar sign ("$") key.
    DOM_VK_PERCENT 165 Percent ("%") key.
    DOM_VK_AMPERSAND 166 Ampersand ("&") key.
    DOM_VK_UNDERSCORE 167 Underscore ("_") key.
    DOM_VK_OPEN_PAREN 168 Open parenthesis ("(") key.
    DOM_VK_CLOSE_PAREN 169 Close parenthesis (")") key.
    DOM_VK_ASTERISK 170 Asterisk ("*") key.
    DOM_VK_PLUS 171 Plus ("+") key.
    DOM_VK_PIPE 172 Pipe ("|") key.
    DOM_VK_HYPHEN_MINUS 173 Hyphen/Minus ("-") key.
    DOM_VK_OPEN_CURLY_BRACKET 174 Open curly bracket ("{") key.
    DOM_VK_CLOSE_CURLY_BRACKET 175 Close curly bracket ("}") key.
    DOM_VK_TILDE 176 Tilde ("~") key.
    DOM_VK_COMMA 188 Comma (",") key.
    DOM_VK_PERIOD 190 Period (".") key.
    DOM_VK_SLASH 191 Slash ("/") key.
    DOM_VK_BACK_QUOTE 192 Back tick ("`") key.
    DOM_VK_OPEN_BRACKET 219 Open square bracket ("[") key.
    DOM_VK_BACK_SLASH 220 Back slash ("\") key.
    DOM_VK_CLOSE_BRACKET 221 Close square bracket ("]") key.
    DOM_VK_QUOTE 222 Quote (''') key.
    DOM_VK_META 224 Command key on Mac.
    DOM_VK_ALTGR 225 AltGr key on Linux.
    DOM_VK_WIN 91 Windows logo key on Windows. Or Super or Hyper key on Linux.
    DOM_VK_KANA 21 Linux support for this keycode was added in Gecko 4.0.
    DOM_VK_HANGUL 21 Linux support for this keycode was added in Gecko 4.0.
    DOM_VK_EISU 22 "英数" key on Japanese Mac keyboard.
    DOM_VK_JUNJA 23 Linux support for this keycode was added in Gecko 4.0.
    DOM_VK_FINAL 24 Linux support for this keycode was added in Gecko 4.0.
    DOM_VK_HANJA 25 Linux support for this keycode was added in Gecko 4.0.
    DOM_VK_KANJI 25 Linux support for this keycode was added in Gecko 4.0.
    DOM_VK_CONVERT 28 Linux support for this keycode was added in Gecko 4.0.
    DOM_VK_NONCONVERT 29 Linux support for this keycode was added in Gecko 4.0.
    DOM_VK_ACCEPT 30 Linux support for this keycode was added in Gecko 4.0.
    DOM_VK_MODECHANGE 31 Linux support for this keycode was added in Gecko 4.0.
    DOM_VK_SELECT 41 Linux support for this keycode was added in Gecko 4.0.
    DOM_VK_PRINT 42 Linux support for this keycode was added in Gecko 4.0.
    DOM_VK_EXECUTE 43 Linux support for this keycode was added in Gecko 4.0.
    DOM_VK_SLEEP 95 Linux support for this keycode was added in Gecko 4.0.

    Key location constants

    These constants describe the location on the keyboard of key events. DOM level 3

    Constant Value Description
    DOM_KEY_LOCATION_STANDARD 0 The key must not 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, this is the value of the location attribute when the left-hand Control key is pressed on a standard 101 key US keyboard. This value is only used for keys that have more that one possible location on the keyboard.
    DOM_KEY_LOCATION_RIGHT 2 The key was the right-hand version of the key; for example, this is the value of the location attribute when the right-hand Control key is pressed on a standard 101 key US keyboard. This value is only used for keys that have more that 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 DOM_KEY_LOCATION_NUMPAD for the keys on NumPad.  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 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_MOBILE on Android, Maemo, and Boot to Gecko.
    DOM_KEY_LOCATION_JOYSTICK 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 DOM_KEY_LOCATION_JOYSTICK (See bug 756504 for Android).

    Methods

    getModifierState()

    返回指定的修饰键的当前状态.  DOM level 3

    boolean getModifierState(
      in DOMString keyArg
    );
    
    参数
    keyArg
    A string identifying the modifier key whose value you wish to determine. This may be an implementation-defined value or one of: "Alt", "AltGraph", "CapsLock", "Control", "Fn", "Meta", "NumLock", "ScrollLock", "Shift", "SymbolLock", or "OS". Note that IE9 uses "Scroll" for "ScrollLock" and "Win" for "OS". If you use these older draft's name, Gecko's getModifierState() always returns false.
    返回值

    如果指定的修饰键处于按下状态,则返回true,否则返回false.

    在Gecko中,getModifierState()什么时候返回true
      Windows Linux (GTK) Mac
    "Alt" Either Alt key or AltGr key pressed 按下Alt键 option key pressed
    "AltGraph"

    Both Alt and Ctrl keys are pressed, or AltGr key is pressed

    按下AltGr键 option key pressed
    "CapsLock" During LED for Caps Lock turned on
    "Control" 按下Ctrl键或者AltGr键 按下Ctrl 键 按下control 键
    "Fn" 不支持
    "Meta" 不支持 command key pressed
    "NumLock" During LED for Num Lock turned on A key on numpad pressed
    "ScrollLock" During LED for Scroll Lock turned on During LED for Scroll Lock turned on, but typically this isn't supported by platform Not supported
    "Shift" Shift key pressed
    "SymbolLock" Not supported
    "OS" Windows Logo key Super key or Hyper key pressed (typically, mapped to Windows Logo key) Not supported

    On the other platforms, "Alt", "Control" and "Shift" may be supported.

    All modifiers are always supported for untrusted events on Gecko. This doesn't depend on the platform.

    initKeyboardEvent()

    已废弃
    该特性已经从 Web 标准中删除,虽然一些浏览器目前仍然支持它,但也许会在未来的某个时间停止支持,请尽量不要使用该特性。

    Initializes the attributes of a keyboard event object. This method was introduced in draft of DOM Level 3 Events, but deprecated in newer draft. Gecko doesn't implement this method but there is similar one, see initKeyEvent().

    void initKeyboardEvent(
      in DOMString typeArg,
      in boolean canBubbleArg,
      in boolean cancelableArg,
      in views::AbstractView viewArg,
      in DOMString charArg,
      in DOMString keyArg,
      in unsigned long locationArg,
      in DOMString modifiersListArg,
      in boolean repeat,
      in DOMString localeArg
    );
    
    参数
    typeArg
    The type of keyboard event; this will be one of keydown, keypress, or keyup.
    canBubbleArg
    Whether or not the event can bubble.
    cancelableArg
    Whether or not the event can be canceled.
    viewArg
    ?
    charArg
    The value of the char attribute.
    keyArg
    The value of the key attribute.
    locationArg
    The value of the location attribute.
    modifiersListArg
    A whitespace-delineated list of modifier keys that should be considered to be active on the event's key. For example, specifying "Control Shift" indicates that the user was holding down the Control and Shift keys when pressing the key described by the event.
    repeatArg
    The value of the repeat attribute.
    localeArg
    The value of the locale attribute.

    Processing of key events

    There are keydown, keypress, and keyup events. For most keys, Gecko dispatches a sequence of key events like this:

    1. When the key is first depressed, the keydown event is sent.
    2. If the key is not a modifier key, the keypress event is sent.
    3. When the user releases the key, the keyup event is sent.

    Special cases

    Certain keys toggle the state of an LED indicator, such as Caps Lock, Num Lock, and Scroll Lock. On Windows and Linux, these keys dispatch only the keydown and keyup events. Note that on Linux, Firefox 12 and earlier also dispatched the keypress event for these keys.

    On Mac, however, Caps Lock dispatches only the keydown event due to a platform event model limitation. Num Lock on an external keyboard (that is, without needing to press the Fn key to generate the Num Lock key code) dispatches keydown, keypress, and keyup, but Num Lock and Scroll Lock generated using the Fn key doesn't dispatch any events at all. This inconsistent behavior is a bug; see bug 602812.

    Auto-repeat handling

    When a key is pressed and held down, it begins to auto-repeat. This results in a sequence of events similar to the following being dispatched:

    1. keydown
    2. keypress
    3. keydown
    4. keypress
    5. <<repeating until the user releases the key>>
    6. keyup

    This is what the DOM Level 3 specification says should happen. There are some caveats, however, as described below.

    Auto-repeat on some GTK environments such as Ubuntu 9.4

    In some GTK-based environments, auto-repeat dispatches a native key-up event automatically during auto-repeat, and there's no way for Gecko to know the difference between a repeated series of keypresses and an auto-repeat. On those platforms, then, an auto-repeat key will generate the following sequence of events:

    1. keydown
    2. keypress
    3. keyup
    4. keydown
    5. keypress
    6. keyup
    7. <<repeating until the user releases the key>>
    8. keyup

    In these environments, unfortunately, there's no way for web content to tell the difference between auto-repeating keys and keys that are just being pressed repeatedly.

    Auto-repeat handling prior to Gecko 4.0

    Before Gecko 4.0 , keyboard handling was less consistent across platforms.

    Windows
    Auto-repeat behavior is the same as in Gecko 4.0 and later.
    Mac
    After the initial keydown event, only keypress events are sent until the keyup event occurs; the inter-spaced keydown events are not sent.
    Linux
    The event behavior depends on the specific platform. It will either behave like Windows or Mac depending on what the native event model does.

    Key names and Char values

    key names and char values on Windows
    Virtual-Key Codes IE 9
    VK_LBUTTON (0x01) "Unidentified" null
    VK_RBUTTON (0x02) "Unidentified" null
    VK_CANCEL (0x03) "" 0x03
    VK_MBUTTON (0x04) "Unidentified" null
    VK_XBUTTON1 (0x05) "Unidentified" null
    VK_XBUTTON2 (0x06) "Unidentified" null
    VK_BACK (0x08) "Backspace" 0x08
    VK_TAB (0x09) "Tab" 0x09
    VK_CLEAR (0x0C) "Clear" null
    VK_RETURN (0x0D) "Enter" 0x0A for keydown,
    0x0D for keypress
    VK_SHIFT (0x10) "Shift" null
    VK_CONTROL (0x11) "Control" null
    VK_MENU (0x12) "Alt" null
    VK_PAUSE (0x13) "Pause" null
    VK_CAPITAL (0x14) "CapsLock" null
    VK_KANA,
    VK_HANGUEL,
    VK_HANGUL (0x15)
    "KanaMode" null
    VK_JUNJA (0x17) "JunjaMode" null
    VK_FINAL (0x18) "HanjaMode" null
    VK_HANJA,
    VK_KANJI (0x19)
    "KanjiMode" null
    VK_ESCAPE (0x1B) "Esc" 0x1B
    VK_CONVERT (0x1C) "Convert" null
    VK_NONCONVERT (0x1D) "Nonconvert" null
    VK_ACCEPT (0x1E) "Accept" null
    VK_MODECHANGE (0x1F) "ModeChange" null
    VK_SPACE (0x20) "Spacebar" Depends on actual inputted character
    VK_PRIOR (0x21) "PageUp" null
    VK_NEXT (0x22) "PageDown" null
    VK_END (0x23) "End" null
    VK_HOME (0x24) "Home" null
    VK_LEFT (0x25) "Left" null
    VK_UP (0x26) "Up" null
    VK_RIGHT (0x27) "Right" null
    VK_DOWN (0x28) "Down" null
    VK_SELECT (0x29) "Select" null
    VK_PRINT (0x2A) "Unidentified" null
    VK_EXECUTE (0x2B) "Execute" null
    VK_SNAPSHOT (0x2C) "PrintScreen" null
    VK_INSERT (0x2D) "Insert" null
    VK_DELETE (0x2E) "Del" null
    VK_HELP (0x2F) "Help" null
    VK_LWIN (0x5B) "Win" null
    VK_RWIN (0x5C) "Win" null
    VK_APPS (0x5D) "Apps" null
    VK_SLEEP (0x5F) "Unidentified" null
    VK_NUMPAD0 (0x60)VK_NUMPAD9 (0x69) "0" ~ "9" "0" ~ "9"
    VK_MULTIPLY (0x6A) "Multiply" "*"
    VK_ADD (0x6B) "Add" "+"
    VK_SEPARATOR (0x6C) "Separator" null
    VK_SUBTRACT (0x6D) "Subtract" "-"
    VK_DECIMAL (0x6E) "Decimal" "."
    VK_DIVIDE (0x6F) "Divide" "/"
    VK_F1 (0x70)VK_F24 (0x87) "F1" ~ "F24" null
    VK_NUMLOCK (0x90) "NumLock" null
    VK_SCROLL (0x91) "Scroll" null
    VK_LSHIFT (0xA0) "Shift" null
    VK_RSHIFT (0xA1) "Shift" null
    VK_LCONTROL (0xA2) "Control" null
    VK_RCONTROL (0xA3) "Control" null
    VK_LMENU (0xA4) "Alt" null
    VK_RMENU (0xA5) "Alt" null
    VK_BROWSER_BACK (0xA6) "BrowserBack" null
    VK_BROWSER_FORWARD (0xA7) "BrowserForward" null
    VK_BROWSER_REFRESH (0xA8) "BrowserRefresh" null
    VK_BROWSER_STOP (0xA9) "BrowserStop" null
    VK_BROWSER_SEARCH (0xAA) "BrowserSearch" null
    VK_BROWSER_FAVORITES (0xAB) "BrowserFavorites" null
    VK_BROWSER_HOME (0xAC) "BrowserHome" null
    VK_VOLUME_MUTE (0xAD) "VolumeMute" null
    VK_VOLUME_DOWN (0xAE) "VolumeDown" null
    VK_VOLUME_UP (0xAF) "VolumeUp" null
    VK_MEDIA_NEXT_TRACK (0xB0) "MediaNextTrack" null
    VK_MEDIA_PREV_TRACK (0xB1) "MediaPreviousTrack" null
    VK_MEDIA_STOP (0xB2) "MediaStop" null
    VK_MEDIA_PLAY_PAUSE (0xB3) "MediaPlayPause" null
    VK_LAUNCH_MAIL (0xB4) "LaunchMail" null
    VK_LAUNCH_MEDIA_SELECT (0xB5) "SelectMedia" null
    VK_LAUNCH_APP1 (0xB6) "LaunchApplication1" null
    VK_LAUNCH_APP2 (0xB7) "LaunchApplication2" null
    VK_PROCESSKEY (0xE5) "Unidentified" (tested without IME) null
    VK_PACKET (0xE7) 0x00 (null character at 1st, tested without SendInput() API) null
    VK_ATTN (0xF6) "Attn" null
    VK_CRSEL (0xF7) "Crsel" null
    VK_EXSEL (0xF8) "Exsel" null
    VK_EREOF (0xF9) "EraseEof" null
    VK_PLAY (0xFA) "Play" null
    VK_ZOOM (0xFB) "Zoom" null
    VK_NONAME (0xFC) "Unidentified" null
    VK_PA1 (0xFD) "Unidentified" null
    VK_OEM_CLEAR (0xFE) "Clear" null

    规范

    DOM 3 Events: KeyboardEvent

    例子

    <!DOCTYPE html>
    <html>
    <head>
    <script>
      var metaChar = false;
      var exampleKey = 16;
      function keyEvent(event) {
        var key = event.keyCode || event.which;
        var keychar = String.fromCharCode(key);
        if (key == exampleKey) {
          metaChar = true;
        }
        if (key != exampleKey) {
          if (metaChar) {
            alert("Combination of metaKey + " + keychar);
            metaChar = false;
          } else {
            alert("Key pressed " + key);
          }
        }
      }
    
      function metaKeyUp (event) {
        var key = event.keyCode || event.which;
        if (key==exampleKey) {
          metaChar = false;
        }
      }
    </script>
    </head>
    
    <body onkeydown="keyEvent(event)" onkeyup="metaKeyUp(event)">
    </body>
    </html>
    

    文档标签和贡献者

    此页面的贡献者有: ziyunfei, teoli
    最后编辑者: teoli,