IT. Expert System.

Android Reference

KeyEvent


android.view

Class KeyEvent

  • All Implemented Interfaces:
    Parcelable


    public class KeyEvent
    extends InputEvent
    implements Parcelable
    Object used to report key and button events.

    Each key press is described by a sequence of key events. A key press starts with a key event with ACTION_DOWN. If the key is held sufficiently long that it repeats, then the initial down is followed additional key events with ACTION_DOWN and a non-zero value for getRepeatCount(). The last key event is a ACTION_UP for the key up. If the key press is canceled, the key up event will have the FLAG_CANCELED flag set.

    Key events are generally accompanied by a key code (getKeyCode()), scan code (getScanCode()) and meta state (getMetaState()). Key code constants are defined in this class. Scan code constants are raw device-specific codes obtained from the OS and so are not generally meaningful to applications unless interpreted using the KeyCharacterMap. Meta states describe the pressed state of key modifiers such as META_SHIFT_ON or META_ALT_ON.

    Key codes typically correspond one-to-one with individual keys on an input device. Many keys and key combinations serve quite different functions on different input devices so care must be taken when interpreting them. Always use the KeyCharacterMap associated with the input device when mapping keys to characters. Be aware that there may be multiple key input devices active at the same time and each will have its own key character map.

    As soft input methods can use multiple and inventive ways of inputting text, there is no guarantee that any key press on a soft keyboard will generate a key event: this is left to the IME's discretion, and in fact sending such events is discouraged. You should never rely on receiving KeyEvents for any key on a soft input method. In particular, the default software keyboard will never send any key event to any application targetting Jelly Bean or later, and will only send events for some presses of the delete and return keys to applications targetting Ice Cream Sandwich or earlier. Be aware that other software input methods may never send key events regardless of the version. Consider using editor actions like EditorInfo.IME_ACTION_DONE if you need specific interaction with the software keyboard, as it gives more visibility to the user as to how your application will react to key presses.

    When interacting with an IME, the framework may deliver key events with the special action ACTION_MULTIPLE that either specifies that single repeated key code or a sequence of characters to insert.

    In general, the framework cannot guarantee that the key events it delivers to a view always constitute complete key sequences since some events may be dropped or modified by containing views before they are delivered. The view implementation should be prepared to handle FLAG_CANCELED and should tolerate anomalous situations such as receiving a new ACTION_DOWN without first having received an ACTION_UP for the prior key press.

    Refer to InputDevice for more information about how different kinds of input devices and sources represent keys and buttons.

    • Field Detail

      • KEYCODE_UNKNOWN

        public static final int KEYCODE_UNKNOWN
        Key code constant: Unknown key code.
        See Also:
        Constant Field Values
      • KEYCODE_SOFT_LEFT

        public static final int KEYCODE_SOFT_LEFT
        Key code constant: Soft Left key. Usually situated below the display on phones and used as a multi-function feature key for selecting a software defined function shown on the bottom left of the display.
        See Also:
        Constant Field Values
      • KEYCODE_SOFT_RIGHT

        public static final int KEYCODE_SOFT_RIGHT
        Key code constant: Soft Right key. Usually situated below the display on phones and used as a multi-function feature key for selecting a software defined function shown on the bottom right of the display.
        See Also:
        Constant Field Values
      • KEYCODE_HOME

        public static final int KEYCODE_HOME
        Key code constant: Home key. This key is handled by the framework and is never delivered to applications.
        See Also:
        Constant Field Values
      • KEYCODE_BACK

        public static final int KEYCODE_BACK
        Key code constant: Back key.
        See Also:
        Constant Field Values
      • KEYCODE_CALL

        public static final int KEYCODE_CALL
        Key code constant: Call key.
        See Also:
        Constant Field Values
      • KEYCODE_ENDCALL

        public static final int KEYCODE_ENDCALL
        Key code constant: End Call key.
        See Also:
        Constant Field Values
      • KEYCODE_STAR

        public static final int KEYCODE_STAR
        Key code constant: '*' key.
        See Also:
        Constant Field Values
      • KEYCODE_POUND

        public static final int KEYCODE_POUND
        Key code constant: '#' key.
        See Also:
        Constant Field Values
      • KEYCODE_DPAD_UP

        public static final int KEYCODE_DPAD_UP
        Key code constant: Directional Pad Up key. May also be synthesized from trackball motions.
        See Also:
        Constant Field Values
      • KEYCODE_DPAD_DOWN

        public static final int KEYCODE_DPAD_DOWN
        Key code constant: Directional Pad Down key. May also be synthesized from trackball motions.
        See Also:
        Constant Field Values
      • KEYCODE_DPAD_LEFT

        public static final int KEYCODE_DPAD_LEFT
        Key code constant: Directional Pad Left key. May also be synthesized from trackball motions.
        See Also:
        Constant Field Values
      • KEYCODE_DPAD_RIGHT

        public static final int KEYCODE_DPAD_RIGHT
        Key code constant: Directional Pad Right key. May also be synthesized from trackball motions.
        See Also:
        Constant Field Values
      • KEYCODE_DPAD_CENTER

        public static final int KEYCODE_DPAD_CENTER
        Key code constant: Directional Pad Center key. May also be synthesized from trackball motions.
        See Also:
        Constant Field Values
      • KEYCODE_VOLUME_UP

        public static final int KEYCODE_VOLUME_UP
        Key code constant: Volume Up key. Adjusts the speaker volume up.
        See Also:
        Constant Field Values
      • KEYCODE_VOLUME_DOWN

        public static final int KEYCODE_VOLUME_DOWN
        Key code constant: Volume Down key. Adjusts the speaker volume down.
        See Also:
        Constant Field Values
      • KEYCODE_POWER

        public static final int KEYCODE_POWER
        Key code constant: Power key.
        See Also:
        Constant Field Values
      • KEYCODE_CAMERA

        public static final int KEYCODE_CAMERA
        Key code constant: Camera key. Used to launch a camera application or take pictures.
        See Also:
        Constant Field Values
      • KEYCODE_CLEAR

        public static final int KEYCODE_CLEAR
        Key code constant: Clear key.
        See Also:
        Constant Field Values
      • KEYCODE_COMMA

        public static final int KEYCODE_COMMA
        Key code constant: ',' key.
        See Also:
        Constant Field Values
      • KEYCODE_PERIOD

        public static final int KEYCODE_PERIOD
        Key code constant: '.' key.
        See Also:
        Constant Field Values
      • KEYCODE_ALT_LEFT

        public static final int KEYCODE_ALT_LEFT
        Key code constant: Left Alt modifier key.
        See Also:
        Constant Field Values
      • KEYCODE_ALT_RIGHT

        public static final int KEYCODE_ALT_RIGHT
        Key code constant: Right Alt modifier key.
        See Also:
        Constant Field Values
      • KEYCODE_SHIFT_LEFT

        public static final int KEYCODE_SHIFT_LEFT
        Key code constant: Left Shift modifier key.
        See Also:
        Constant Field Values
      • KEYCODE_SHIFT_RIGHT

        public static final int KEYCODE_SHIFT_RIGHT
        Key code constant: Right Shift modifier key.
        See Also:
        Constant Field Values
      • KEYCODE_TAB

        public static final int KEYCODE_TAB
        Key code constant: Tab key.
        See Also:
        Constant Field Values
      • KEYCODE_SPACE

        public static final int KEYCODE_SPACE
        Key code constant: Space key.
        See Also:
        Constant Field Values
      • KEYCODE_SYM

        public static final int KEYCODE_SYM
        Key code constant: Symbol modifier key. Used to enter alternate symbols.
        See Also:
        Constant Field Values
      • KEYCODE_EXPLORER

        public static final int KEYCODE_EXPLORER
        Key code constant: Explorer special function key. Used to launch a browser application.
        See Also:
        Constant Field Values
      • KEYCODE_ENVELOPE

        public static final int KEYCODE_ENVELOPE
        Key code constant: Envelope special function key. Used to launch a mail application.
        See Also:
        Constant Field Values
      • KEYCODE_ENTER

        public static final int KEYCODE_ENTER
        Key code constant: Enter key.
        See Also:
        Constant Field Values
      • KEYCODE_GRAVE

        public static final int KEYCODE_GRAVE
        Key code constant: '`' (backtick) key.
        See Also:
        Constant Field Values
      • KEYCODE_MINUS

        public static final int KEYCODE_MINUS
        Key code constant: '-'.
        See Also:
        Constant Field Values
      • KEYCODE_EQUALS

        public static final int KEYCODE_EQUALS
        Key code constant: '=' key.
        See Also:
        Constant Field Values
      • KEYCODE_LEFT_BRACKET

        public static final int KEYCODE_LEFT_BRACKET
        Key code constant: '[' key.
        See Also:
        Constant Field Values
      • KEYCODE_RIGHT_BRACKET

        public static final int KEYCODE_RIGHT_BRACKET
        Key code constant: ']' key.
        See Also:
        Constant Field Values
      • KEYCODE_BACKSLASH

        public static final int KEYCODE_BACKSLASH
        Key code constant: '\' key.
        See Also:
        Constant Field Values
      • KEYCODE_SEMICOLON

        public static final int KEYCODE_SEMICOLON
        Key code constant: ';' key.
        See Also:
        Constant Field Values
      • KEYCODE_APOSTROPHE

        public static final int KEYCODE_APOSTROPHE
        Key code constant: ''' (apostrophe) key.
        See Also:
        Constant Field Values
      • KEYCODE_SLASH

        public static final int KEYCODE_SLASH
        Key code constant: '/' key.
        See Also:
        Constant Field Values
      • KEYCODE_AT

        public static final int KEYCODE_AT
        Key code constant: '@' key.
        See Also:
        Constant Field Values
      • KEYCODE_HEADSETHOOK

        public static final int KEYCODE_HEADSETHOOK
        Key code constant: Headset Hook key. Used to hang up calls and stop media.
        See Also:
        Constant Field Values
      • KEYCODE_FOCUS

        public static final int KEYCODE_FOCUS
        Key code constant: Camera Focus key. Used to focus the camera.
        See Also:
        Constant Field Values
      • KEYCODE_PLUS

        public static final int KEYCODE_PLUS
        Key code constant: '+' key.
        See Also:
        Constant Field Values
      • KEYCODE_MENU

        public static final int KEYCODE_MENU
        Key code constant: Menu key.
        See Also:
        Constant Field Values
      • KEYCODE_NOTIFICATION

        public static final int KEYCODE_NOTIFICATION
        Key code constant: Notification key.
        See Also:
        Constant Field Values
      • KEYCODE_SEARCH

        public static final int KEYCODE_SEARCH
        Key code constant: Search key.
        See Also:
        Constant Field Values
      • KEYCODE_MEDIA_PLAY_PAUSE

        public static final int KEYCODE_MEDIA_PLAY_PAUSE
        Key code constant: Play/Pause media key.
        See Also:
        Constant Field Values
      • KEYCODE_MEDIA_STOP

        public static final int KEYCODE_MEDIA_STOP
        Key code constant: Stop media key.
        See Also:
        Constant Field Values
      • KEYCODE_MEDIA_NEXT

        public static final int KEYCODE_MEDIA_NEXT
        Key code constant: Play Next media key.
        See Also:
        Constant Field Values
      • KEYCODE_MEDIA_PREVIOUS

        public static final int KEYCODE_MEDIA_PREVIOUS
        Key code constant: Play Previous media key.
        See Also:
        Constant Field Values
      • KEYCODE_MEDIA_REWIND

        public static final int KEYCODE_MEDIA_REWIND
        Key code constant: Rewind media key.
        See Also:
        Constant Field Values
      • KEYCODE_MEDIA_FAST_FORWARD

        public static final int KEYCODE_MEDIA_FAST_FORWARD
        Key code constant: Fast Forward media key.
        See Also:
        Constant Field Values
      • KEYCODE_PAGE_UP

        public static final int KEYCODE_PAGE_UP
        Key code constant: Page Up key.
        See Also:
        Constant Field Values
      • KEYCODE_PAGE_DOWN

        public static final int KEYCODE_PAGE_DOWN
        Key code constant: Page Down key.
        See Also:
        Constant Field Values
      • KEYCODE_PICTSYMBOLS

        public static final int KEYCODE_PICTSYMBOLS
        Key code constant: Picture Symbols modifier key. Used to switch symbol sets (Emoji, Kao-moji).
        See Also:
        Constant Field Values
      • KEYCODE_SWITCH_CHARSET

        public static final int KEYCODE_SWITCH_CHARSET
        Key code constant: Switch Charset modifier key. Used to switch character sets (Kanji, Katakana).
        See Also:
        Constant Field Values
      • KEYCODE_BUTTON_A

        public static final int KEYCODE_BUTTON_A
        Key code constant: A Button key. On a game controller, the A button should be either the button labeled A or the first button on the upper row of controller buttons.
        See Also:
        Constant Field Values
      • KEYCODE_BUTTON_B

        public static final int KEYCODE_BUTTON_B
        Key code constant: B Button key. On a game controller, the B button should be either the button labeled B or the second button on the upper row of controller buttons.
        See Also:
        Constant Field Values
      • KEYCODE_BUTTON_C

        public static final int KEYCODE_BUTTON_C
        Key code constant: C Button key. On a game controller, the C button should be either the button labeled C or the third button on the upper row of controller buttons.
        See Also:
        Constant Field Values
      • KEYCODE_BUTTON_X

        public static final int KEYCODE_BUTTON_X
        Key code constant: X Button key. On a game controller, the X button should be either the button labeled X or the first button on the lower row of controller buttons.
        See Also:
        Constant Field Values
      • KEYCODE_BUTTON_Y

        public static final int KEYCODE_BUTTON_Y
        Key code constant: Y Button key. On a game controller, the Y button should be either the button labeled Y or the second button on the lower row of controller buttons.
        See Also:
        Constant Field Values
      • KEYCODE_BUTTON_Z

        public static final int KEYCODE_BUTTON_Z
        Key code constant: Z Button key. On a game controller, the Z button should be either the button labeled Z or the third button on the lower row of controller buttons.
        See Also:
        Constant Field Values
      • KEYCODE_BUTTON_L1

        public static final int KEYCODE_BUTTON_L1
        Key code constant: L1 Button key. On a game controller, the L1 button should be either the button labeled L1 (or L) or the top left trigger button.
        See Also:
        Constant Field Values
      • KEYCODE_BUTTON_R1

        public static final int KEYCODE_BUTTON_R1
        Key code constant: R1 Button key. On a game controller, the R1 button should be either the button labeled R1 (or R) or the top right trigger button.
        See Also:
        Constant Field Values
      • KEYCODE_BUTTON_L2

        public static final int KEYCODE_BUTTON_L2
        Key code constant: L2 Button key. On a game controller, the L2 button should be either the button labeled L2 or the bottom left trigger button.
        See Also:
        Constant Field Values
      • KEYCODE_BUTTON_R2

        public static final int KEYCODE_BUTTON_R2
        Key code constant: R2 Button key. On a game controller, the R2 button should be either the button labeled R2 or the bottom right trigger button.
        See Also:
        Constant Field Values
      • KEYCODE_BUTTON_THUMBL

        public static final int KEYCODE_BUTTON_THUMBL
        Key code constant: Left Thumb Button key. On a game controller, the left thumb button indicates that the left (or only) joystick is pressed.
        See Also:
        Constant Field Values
      • KEYCODE_BUTTON_THUMBR

        public static final int KEYCODE_BUTTON_THUMBR
        Key code constant: Right Thumb Button key. On a game controller, the right thumb button indicates that the right joystick is pressed.
        See Also:
        Constant Field Values
      • KEYCODE_BUTTON_START

        public static final int KEYCODE_BUTTON_START
        Key code constant: Start Button key. On a game controller, the button labeled Start.
        See Also:
        Constant Field Values
      • KEYCODE_BUTTON_SELECT

        public static final int KEYCODE_BUTTON_SELECT
        Key code constant: Select Button key. On a game controller, the button labeled Select.
        See Also:
        Constant Field Values
      • KEYCODE_BUTTON_MODE

        public static final int KEYCODE_BUTTON_MODE
        Key code constant: Mode Button key. On a game controller, the button labeled Mode.
        See Also:
        Constant Field Values
      • KEYCODE_ESCAPE

        public static final int KEYCODE_ESCAPE
        Key code constant: Escape key.
        See Also:
        Constant Field Values
      • KEYCODE_FORWARD_DEL

        public static final int KEYCODE_FORWARD_DEL
        Key code constant: Forward Delete key. Deletes characters ahead of the insertion point, unlike KEYCODE_DEL.
        See Also:
        Constant Field Values
      • KEYCODE_CTRL_LEFT

        public static final int KEYCODE_CTRL_LEFT
        Key code constant: Left Control modifier key.
        See Also:
        Constant Field Values
      • KEYCODE_CTRL_RIGHT

        public static final int KEYCODE_CTRL_RIGHT
        Key code constant: Right Control modifier key.
        See Also:
        Constant Field Values
      • KEYCODE_CAPS_LOCK

        public static final int KEYCODE_CAPS_LOCK
        Key code constant: Caps Lock key.
        See Also:
        Constant Field Values
      • KEYCODE_SCROLL_LOCK

        public static final int KEYCODE_SCROLL_LOCK
        Key code constant: Scroll Lock key.
        See Also:
        Constant Field Values
      • KEYCODE_META_LEFT

        public static final int KEYCODE_META_LEFT
        Key code constant: Left Meta modifier key.
        See Also:
        Constant Field Values
      • KEYCODE_META_RIGHT

        public static final int KEYCODE_META_RIGHT
        Key code constant: Right Meta modifier key.
        See Also:
        Constant Field Values
      • KEYCODE_FUNCTION

        public static final int KEYCODE_FUNCTION
        Key code constant: Function modifier key.
        See Also:
        Constant Field Values
      • KEYCODE_SYSRQ

        public static final int KEYCODE_SYSRQ
        Key code constant: System Request / Print Screen key.
        See Also:
        Constant Field Values
      • KEYCODE_BREAK

        public static final int KEYCODE_BREAK
        Key code constant: Break / Pause key.
        See Also:
        Constant Field Values
      • KEYCODE_MOVE_HOME

        public static final int KEYCODE_MOVE_HOME
        Key code constant: Home Movement key. Used for scrolling or moving the cursor around to the start of a line or to the top of a list.
        See Also:
        Constant Field Values
      • KEYCODE_MOVE_END

        public static final int KEYCODE_MOVE_END
        Key code constant: End Movement key. Used for scrolling or moving the cursor around to the end of a line or to the bottom of a list.
        See Also:
        Constant Field Values
      • KEYCODE_INSERT

        public static final int KEYCODE_INSERT
        Key code constant: Insert key. Toggles insert / overwrite edit mode.
        See Also:
        Constant Field Values
      • KEYCODE_FORWARD

        public static final int KEYCODE_FORWARD
        Key code constant: Forward key. Navigates forward in the history stack. Complement of KEYCODE_BACK.
        See Also:
        Constant Field Values
      • KEYCODE_MEDIA_PLAY

        public static final int KEYCODE_MEDIA_PLAY
        Key code constant: Play media key.
        See Also:
        Constant Field Values
      • KEYCODE_MEDIA_PAUSE

        public static final int KEYCODE_MEDIA_PAUSE
        Key code constant: Pause media key.
        See Also:
        Constant Field Values
      • KEYCODE_MEDIA_CLOSE

        public static final int KEYCODE_MEDIA_CLOSE
        Key code constant: Close media key. May be used to close a CD tray, for example.
        See Also:
        Constant Field Values
      • KEYCODE_MEDIA_EJECT

        public static final int KEYCODE_MEDIA_EJECT
        Key code constant: Eject media key. May be used to eject a CD tray, for example.
        See Also:
        Constant Field Values
      • KEYCODE_MEDIA_RECORD

        public static final int KEYCODE_MEDIA_RECORD
        Key code constant: Record media key.
        See Also:
        Constant Field Values
      • KEYCODE_F1

        public static final int KEYCODE_F1
        Key code constant: F1 key.
        See Also:
        Constant Field Values
      • KEYCODE_F2

        public static final int KEYCODE_F2
        Key code constant: F2 key.
        See Also:
        Constant Field Values
      • KEYCODE_F3

        public static final int KEYCODE_F3
        Key code constant: F3 key.
        See Also:
        Constant Field Values
      • KEYCODE_F4

        public static final int KEYCODE_F4
        Key code constant: F4 key.
        See Also:
        Constant Field Values
      • KEYCODE_F5

        public static final int KEYCODE_F5
        Key code constant: F5 key.
        See Also:
        Constant Field Values
      • KEYCODE_F6

        public static final int KEYCODE_F6
        Key code constant: F6 key.
        See Also:
        Constant Field Values
      • KEYCODE_F7

        public static final int KEYCODE_F7
        Key code constant: F7 key.
        See Also:
        Constant Field Values
      • KEYCODE_F8

        public static final int KEYCODE_F8
        Key code constant: F8 key.
        See Also:
        Constant Field Values
      • KEYCODE_F9

        public static final int KEYCODE_F9
        Key code constant: F9 key.
        See Also:
        Constant Field Values
      • KEYCODE_F10

        public static final int KEYCODE_F10
        Key code constant: F10 key.
        See Also:
        Constant Field Values
      • KEYCODE_F11

        public static final int KEYCODE_F11
        Key code constant: F11 key.
        See Also:
        Constant Field Values
      • KEYCODE_F12

        public static final int KEYCODE_F12
        Key code constant: F12 key.
        See Also:
        Constant Field Values
      • KEYCODE_NUM_LOCK

        public static final int KEYCODE_NUM_LOCK
        Key code constant: Num Lock key. This is the Num Lock key; it is different from KEYCODE_NUM. This key alters the behavior of other keys on the numeric keypad.
        See Also:
        Constant Field Values
      • KEYCODE_NUMPAD_0

        public static final int KEYCODE_NUMPAD_0
        Key code constant: Numeric keypad '0' key.
        See Also:
        Constant Field Values
      • KEYCODE_NUMPAD_1

        public static final int KEYCODE_NUMPAD_1
        Key code constant: Numeric keypad '1' key.
        See Also:
        Constant Field Values
      • KEYCODE_NUMPAD_2

        public static final int KEYCODE_NUMPAD_2
        Key code constant: Numeric keypad '2' key.
        See Also:
        Constant Field Values
      • KEYCODE_NUMPAD_3

        public static final int KEYCODE_NUMPAD_3
        Key code constant: Numeric keypad '3' key.
        See Also:
        Constant Field Values
      • KEYCODE_NUMPAD_4

        public static final int KEYCODE_NUMPAD_4
        Key code constant: Numeric keypad '4' key.
        See Also:
        Constant Field Values
      • KEYCODE_NUMPAD_5

        public static final int KEYCODE_NUMPAD_5
        Key code constant: Numeric keypad '5' key.
        See Also:
        Constant Field Values
      • KEYCODE_NUMPAD_6

        public static final int KEYCODE_NUMPAD_6
        Key code constant: Numeric keypad '6' key.
        See Also:
        Constant Field Values
      • KEYCODE_NUMPAD_7

        public static final int KEYCODE_NUMPAD_7
        Key code constant: Numeric keypad '7' key.
        See Also:
        Constant Field Values
      • KEYCODE_NUMPAD_8

        public static final int KEYCODE_NUMPAD_8
        Key code constant: Numeric keypad '8' key.
        See Also:
        Constant Field Values
      • KEYCODE_NUMPAD_9

        public static final int KEYCODE_NUMPAD_9
        Key code constant: Numeric keypad '9' key.
        See Also:
        Constant Field Values
      • KEYCODE_NUMPAD_DIVIDE

        public static final int KEYCODE_NUMPAD_DIVIDE
        Key code constant: Numeric keypad '/' key (for division).
        See Also:
        Constant Field Values
      • KEYCODE_NUMPAD_MULTIPLY

        public static final int KEYCODE_NUMPAD_MULTIPLY
        Key code constant: Numeric keypad '*' key (for multiplication).
        See Also:
        Constant Field Values
      • KEYCODE_NUMPAD_SUBTRACT

        public static final int KEYCODE_NUMPAD_SUBTRACT
        Key code constant: Numeric keypad '-' key (for subtraction).
        See Also:
        Constant Field Values
      • KEYCODE_NUMPAD_ADD

        public static final int KEYCODE_NUMPAD_ADD
        Key code constant: Numeric keypad '+' key (for addition).
        See Also:
        Constant Field Values
      • KEYCODE_NUMPAD_DOT

        public static final int KEYCODE_NUMPAD_DOT
        Key code constant: Numeric keypad '.' key (for decimals or digit grouping).
        See Also:
        Constant Field Values
      • KEYCODE_NUMPAD_COMMA

        public static final int KEYCODE_NUMPAD_COMMA
        Key code constant: Numeric keypad ',' key (for decimals or digit grouping).
        See Also:
        Constant Field Values
      • KEYCODE_NUMPAD_ENTER

        public static final int KEYCODE_NUMPAD_ENTER
        Key code constant: Numeric keypad Enter key.
        See Also:
        Constant Field Values
      • KEYCODE_NUMPAD_EQUALS

        public static final int KEYCODE_NUMPAD_EQUALS
        Key code constant: Numeric keypad '=' key.
        See Also:
        Constant Field Values
      • KEYCODE_NUMPAD_LEFT_PAREN

        public static final int KEYCODE_NUMPAD_LEFT_PAREN
        Key code constant: Numeric keypad '(' key.
        See Also:
        Constant Field Values
      • KEYCODE_NUMPAD_RIGHT_PAREN

        public static final int KEYCODE_NUMPAD_RIGHT_PAREN
        Key code constant: Numeric keypad ')' key.
        See Also:
        Constant Field Values
      • KEYCODE_VOLUME_MUTE

        public static final int KEYCODE_VOLUME_MUTE
        Key code constant: Volume Mute key. Mutes the speaker, unlike KEYCODE_MUTE. This key should normally be implemented as a toggle such that the first press mutes the speaker and the second press restores the original volume.
        See Also:
        Constant Field Values
      • KEYCODE_INFO

        public static final int KEYCODE_INFO
        Key code constant: Info key. Common on TV remotes to show additional information related to what is currently being viewed.
        See Also:
        Constant Field Values
      • KEYCODE_CHANNEL_UP

        public static final int KEYCODE_CHANNEL_UP
        Key code constant: Channel up key. On TV remotes, increments the television channel.
        See Also:
        Constant Field Values
      • KEYCODE_CHANNEL_DOWN

        public static final int KEYCODE_CHANNEL_DOWN
        Key code constant: Channel down key. On TV remotes, decrements the television channel.
        See Also:
        Constant Field Values
      • KEYCODE_ZOOM_IN

        public static final int KEYCODE_ZOOM_IN
        Key code constant: Zoom in key.
        See Also:
        Constant Field Values
      • KEYCODE_ZOOM_OUT

        public static final int KEYCODE_ZOOM_OUT
        Key code constant: Zoom out key.
        See Also:
        Constant Field Values
      • KEYCODE_TV

        public static final int KEYCODE_TV
        Key code constant: TV key. On TV remotes, switches to viewing live TV.
        See Also:
        Constant Field Values
      • KEYCODE_WINDOW

        public static final int KEYCODE_WINDOW
        Key code constant: Window key. On TV remotes, toggles picture-in-picture mode or other windowing functions.
        See Also:
        Constant Field Values
      • KEYCODE_GUIDE

        public static final int KEYCODE_GUIDE
        Key code constant: Guide key. On TV remotes, shows a programming guide.
        See Also:
        Constant Field Values
      • KEYCODE_DVR

        public static final int KEYCODE_DVR
        Key code constant: DVR key. On some TV remotes, switches to a DVR mode for recorded shows.
        See Also:
        Constant Field Values
      • KEYCODE_BOOKMARK

        public static final int KEYCODE_BOOKMARK
        Key code constant: Bookmark key. On some TV remotes, bookmarks content or web pages.
        See Also:
        Constant Field Values
      • KEYCODE_CAPTIONS

        public static final int KEYCODE_CAPTIONS
        Key code constant: Toggle captions key. Switches the mode for closed-captioning text, for example during television shows.
        See Also:
        Constant Field Values
      • KEYCODE_SETTINGS

        public static final int KEYCODE_SETTINGS
        Key code constant: Settings key. Starts the system settings activity.
        See Also:
        Constant Field Values
      • KEYCODE_TV_POWER

        public static final int KEYCODE_TV_POWER
        Key code constant: TV power key. On TV remotes, toggles the power on a television screen.
        See Also:
        Constant Field Values
      • KEYCODE_TV_INPUT

        public static final int KEYCODE_TV_INPUT
        Key code constant: TV input key. On TV remotes, switches the input on a television screen.
        See Also:
        Constant Field Values
      • KEYCODE_STB_POWER

        public static final int KEYCODE_STB_POWER
        Key code constant: Set-top-box power key. On TV remotes, toggles the power on an external Set-top-box.
        See Also:
        Constant Field Values
      • KEYCODE_STB_INPUT

        public static final int KEYCODE_STB_INPUT
        Key code constant: Set-top-box input key. On TV remotes, switches the input mode on an external Set-top-box.
        See Also:
        Constant Field Values
      • KEYCODE_AVR_POWER

        public static final int KEYCODE_AVR_POWER
        Key code constant: A/V Receiver power key. On TV remotes, toggles the power on an external A/V Receiver.
        See Also:
        Constant Field Values
      • KEYCODE_AVR_INPUT

        public static final int KEYCODE_AVR_INPUT
        Key code constant: A/V Receiver input key. On TV remotes, switches the input mode on an external A/V Receiver.
        See Also:
        Constant Field Values
      • KEYCODE_PROG_RED

        public static final int KEYCODE_PROG_RED
        Key code constant: Red "programmable" key. On TV remotes, acts as a contextual/programmable key.
        See Also:
        Constant Field Values
      • KEYCODE_PROG_GREEN

        public static final int KEYCODE_PROG_GREEN
        Key code constant: Green "programmable" key. On TV remotes, actsas a contextual/programmable key.
        See Also:
        Constant Field Values
      • KEYCODE_PROG_YELLOW

        public static final int KEYCODE_PROG_YELLOW
        Key code constant: Yellow "programmable" key. On TV remotes, acts as a contextual/programmable key.
        See Also:
        Constant Field Values
      • KEYCODE_PROG_BLUE

        public static final int KEYCODE_PROG_BLUE
        Key code constant: Blue "programmable" key. On TV remotes, acts as a contextual/programmable key.
        See Also:
        Constant Field Values
      • KEYCODE_APP_SWITCH

        public static final int KEYCODE_APP_SWITCH
        Key code constant: App switch key. Should bring up the application switcher dialog.
        See Also:
        Constant Field Values
      • KEYCODE_BUTTON_1

        public static final int KEYCODE_BUTTON_1
        Key code constant: Generic Game Pad Button #1.
        See Also:
        Constant Field Values
      • KEYCODE_BUTTON_2

        public static final int KEYCODE_BUTTON_2
        Key code constant: Generic Game Pad Button #2.
        See Also:
        Constant Field Values
      • KEYCODE_BUTTON_3

        public static final int KEYCODE_BUTTON_3
        Key code constant: Generic Game Pad Button #3.
        See Also:
        Constant Field Values
      • KEYCODE_BUTTON_4

        public static final int KEYCODE_BUTTON_4
        Key code constant: Generic Game Pad Button #4.
        See Also:
        Constant Field Values
      • KEYCODE_BUTTON_5

        public static final int KEYCODE_BUTTON_5
        Key code constant: Generic Game Pad Button #5.
        See Also:
        Constant Field Values
      • KEYCODE_BUTTON_6

        public static final int KEYCODE_BUTTON_6
        Key code constant: Generic Game Pad Button #6.
        See Also:
        Constant Field Values
      • KEYCODE_BUTTON_7

        public static final int KEYCODE_BUTTON_7
        Key code constant: Generic Game Pad Button #7.
        See Also:
        Constant Field Values
      • KEYCODE_BUTTON_8

        public static final int KEYCODE_BUTTON_8
        Key code constant: Generic Game Pad Button #8.
        See Also:
        Constant Field Values
      • KEYCODE_BUTTON_9

        public static final int KEYCODE_BUTTON_9
        Key code constant: Generic Game Pad Button #9.
        See Also:
        Constant Field Values
      • KEYCODE_BUTTON_10

        public static final int KEYCODE_BUTTON_10
        Key code constant: Generic Game Pad Button #10.
        See Also:
        Constant Field Values
      • KEYCODE_BUTTON_11

        public static final int KEYCODE_BUTTON_11
        Key code constant: Generic Game Pad Button #11.
        See Also:
        Constant Field Values
      • KEYCODE_BUTTON_12

        public static final int KEYCODE_BUTTON_12
        Key code constant: Generic Game Pad Button #12.
        See Also:
        Constant Field Values
      • KEYCODE_BUTTON_13

        public static final int KEYCODE_BUTTON_13
        Key code constant: Generic Game Pad Button #13.
        See Also:
        Constant Field Values
      • KEYCODE_BUTTON_14

        public static final int KEYCODE_BUTTON_14
        Key code constant: Generic Game Pad Button #14.
        See Also:
        Constant Field Values
      • KEYCODE_BUTTON_15

        public static final int KEYCODE_BUTTON_15
        Key code constant: Generic Game Pad Button #15.
        See Also:
        Constant Field Values
      • KEYCODE_BUTTON_16

        public static final int KEYCODE_BUTTON_16
        Key code constant: Generic Game Pad Button #16.
        See Also:
        Constant Field Values
      • KEYCODE_LANGUAGE_SWITCH

        public static final int KEYCODE_LANGUAGE_SWITCH
        Key code constant: Language Switch key. Toggles the current input language such as switching between English and Japanese on a QWERTY keyboard. On some devices, the same function may be performed by pressing Shift+Spacebar.
        See Also:
        Constant Field Values
      • KEYCODE_MANNER_MODE

        public static final int KEYCODE_MANNER_MODE
        Key code constant: Manner Mode key. Toggles silent or vibrate mode on and off to make the device behave more politely in certain settings such as on a crowded train. On some devices, the key may only operate when long-pressed.
        See Also:
        Constant Field Values
      • KEYCODE_3D_MODE

        public static final int KEYCODE_3D_MODE
        Key code constant: 3D Mode key. Toggles the display between 2D and 3D mode.
        See Also:
        Constant Field Values
      • KEYCODE_CONTACTS

        public static final int KEYCODE_CONTACTS
        Key code constant: Contacts special function key. Used to launch an address book application.
        See Also:
        Constant Field Values
      • KEYCODE_CALENDAR

        public static final int KEYCODE_CALENDAR
        Key code constant: Calendar special function key. Used to launch a calendar application.
        See Also:
        Constant Field Values
      • KEYCODE_MUSIC

        public static final int KEYCODE_MUSIC
        Key code constant: Music special function key. Used to launch a music player application.
        See Also:
        Constant Field Values
      • KEYCODE_CALCULATOR

        public static final int KEYCODE_CALCULATOR
        Key code constant: Calculator special function key. Used to launch a calculator application.
        See Also:
        Constant Field Values
      • KEYCODE_ZENKAKU_HANKAKU

        public static final int KEYCODE_ZENKAKU_HANKAKU
        Key code constant: Japanese full-width / half-width key.
        See Also:
        Constant Field Values
      • KEYCODE_EISU

        public static final int KEYCODE_EISU
        Key code constant: Japanese alphanumeric key.
        See Also:
        Constant Field Values
      • KEYCODE_MUHENKAN

        public static final int KEYCODE_MUHENKAN
        Key code constant: Japanese non-conversion key.
        See Also:
        Constant Field Values
      • KEYCODE_HENKAN

        public static final int KEYCODE_HENKAN
        Key code constant: Japanese conversion key.
        See Also:
        Constant Field Values
      • KEYCODE_KATAKANA_HIRAGANA

        public static final int KEYCODE_KATAKANA_HIRAGANA
        Key code constant: Japanese katakana / hiragana key.
        See Also:
        Constant Field Values
      • KEYCODE_YEN

        public static final int KEYCODE_YEN
        Key code constant: Japanese Yen key.
        See Also:
        Constant Field Values
      • KEYCODE_RO

        public static final int KEYCODE_RO
        Key code constant: Japanese Ro key.
        See Also:
        Constant Field Values
      • KEYCODE_KANA

        public static final int KEYCODE_KANA
        Key code constant: Japanese kana key.
        See Also:
        Constant Field Values
      • KEYCODE_ASSIST

        public static final int KEYCODE_ASSIST
        Key code constant: Assist key. Launches the global assist activity. Not delivered to applications.
        See Also:
        Constant Field Values
      • ACTION_MULTIPLE

        public static final int ACTION_MULTIPLE
        getAction() value: multiple duplicate key events have occurred in a row, or a complex string is being delivered. If the key code is not {#link KEYCODE_UNKNOWN then the {#link getRepeatCount() method returns the number of times the given key code should be executed. Otherwise, if the key code is KEYCODE_UNKNOWN, then this is a sequence of characters as returned by getCharacters().
        See Also:
        Constant Field Values
      • META_CAP_LOCKED

        public static final int META_CAP_LOCKED
        SHIFT key locked in CAPS mode. Reserved for use by MetaKeyKeyListener for a published constant in its API.
        See Also:
        Constant Field Values
      • META_SELECTING

        public static final int META_SELECTING
        Text is in selection mode. Reserved for use by MetaKeyKeyListener for a private unpublished constant in its API that is currently being retained for legacy reasons.
        See Also:
        Constant Field Values
      • FLAG_WOKE_HERE

        public static final int FLAG_WOKE_HERE
        This mask is set if the device woke because of this key event.
        See Also:
        Constant Field Values
      • FLAG_SOFT_KEYBOARD

        public static final int FLAG_SOFT_KEYBOARD
        This mask is set if the key event was generated by a software keyboard.
        See Also:
        Constant Field Values
      • FLAG_KEEP_TOUCH_MODE

        public static final int FLAG_KEEP_TOUCH_MODE
        This mask is set if we don't want the key event to cause us to leave touch mode.
        See Also:
        Constant Field Values
      • FLAG_FROM_SYSTEM

        public static final int FLAG_FROM_SYSTEM
        This mask is set if an event was known to come from a trusted part of the system. That is, the event is known to come from the user, and could not have been spoofed by a third party component.
        See Also:
        Constant Field Values
      • FLAG_EDITOR_ACTION

        public static final int FLAG_EDITOR_ACTION
        This mask is used for compatibility, to identify enter keys that are coming from an IME whose enter key has been auto-labelled "next" or "done". This allows TextView to dispatch these as normal enter keys for old applications, but still do the appropriate action when receiving them.
        See Also:
        Constant Field Values
      • FLAG_CANCELED

        public static final int FLAG_CANCELED
        When associated with up key events, this indicates that the key press has been canceled. Typically this is used with virtual touch screen keys, where the user can slide from the virtual key area on to the display: in that case, the application will receive a canceled up event and should not perform the action normally associated with the key. Note that for this to work, the application can not perform an action for a key until it receives an up or the long press timeout has expired.
        See Also:
        Constant Field Values
      • FLAG_VIRTUAL_HARD_KEY

        public static final int FLAG_VIRTUAL_HARD_KEY
        This key event was generated by a virtual (on-screen) hard key area. Typically this is an area of the touchscreen, outside of the regular display, dedicated to "hardware" buttons.
        See Also:
        Constant Field Values
      • FLAG_LONG_PRESS

        public static final int FLAG_LONG_PRESS
        This flag is set for the first key repeat that occurs after the long press timeout.
        See Also:
        Constant Field Values
      • FLAG_CANCELED_LONG_PRESS

        public static final int FLAG_CANCELED_LONG_PRESS
        Set when a key event has FLAG_CANCELED set because a long press action was executed while it was down.
        See Also:
        Constant Field Values
      • FLAG_TRACKING

        public static final int FLAG_TRACKING
        Set for ACTION_UP when this event's key code is still being tracked from its initial down. That is, somebody requested that tracking started on the key down and a long press has not caused the tracking to be canceled.
        See Also:
        Constant Field Values
      • FLAG_FALLBACK

        public static final int FLAG_FALLBACK
        Set when a key event has been synthesized to implement default behavior for an event that the application did not handle. Fallback key events are generated by unhandled trackball motions (to emulate a directional keypad) and by certain unhandled key presses that are declared in the key map (such as special function numeric keypad keys when numlock is off).
        See Also:
        Constant Field Values
      • FLAG_START_TRACKING

        public static final int FLAG_START_TRACKING
        Private control to determine when an app is tracking a key sequence.
        See Also:
        Constant Field Values
      • FLAG_TAINTED

        public static final int FLAG_TAINTED
        Private flag that indicates when the system has detected that this key event may be inconsistent with respect to the sequence of previously delivered key events, such as when a key up event is sent but the key was not down.
        See Also:
        isTainted(), setTainted(boolean), Constant Field Values
    • Constructor Detail

      • KeyEvent

        public KeyEvent(int action,
                int code)
        Create a new key event.
        Parameters:
        action - Action code: either ACTION_DOWN, ACTION_UP, or ACTION_MULTIPLE.
        code - The key code.
      • KeyEvent

        public KeyEvent(long downTime,
                long eventTime,
                int action,
                int code,
                int repeat)
        Create a new key event.
        Parameters:
        downTime - The time (in SystemClock.uptimeMillis()) at which this key code originally went down.
        eventTime - The time (in SystemClock.uptimeMillis()) at which this event happened.
        action - Action code: either ACTION_DOWN, ACTION_UP, or ACTION_MULTIPLE.
        code - The key code.
        repeat - A repeat count for down events (> 0 if this is after the initial down) or event count for multiple events.
      • KeyEvent

        public KeyEvent(long downTime,
                long eventTime,
                int action,
                int code,
                int repeat,
                int metaState)
        Create a new key event.
        Parameters:
        downTime - The time (in SystemClock.uptimeMillis()) at which this key code originally went down.
        eventTime - The time (in SystemClock.uptimeMillis()) at which this event happened.
        action - Action code: either ACTION_DOWN, ACTION_UP, or ACTION_MULTIPLE.
        code - The key code.
        repeat - A repeat count for down events (> 0 if this is after the initial down) or event count for multiple events.
        metaState - Flags indicating which meta keys are currently pressed.
      • KeyEvent

        public KeyEvent(long downTime,
                long eventTime,
                int action,
                int code,
                int repeat,
                int metaState,
                int deviceId,
                int scancode)
        Create a new key event.
        Parameters:
        downTime - The time (in SystemClock.uptimeMillis()) at which this key code originally went down.
        eventTime - The time (in SystemClock.uptimeMillis()) at which this event happened.
        action - Action code: either ACTION_DOWN, ACTION_UP, or ACTION_MULTIPLE.
        code - The key code.
        repeat - A repeat count for down events (> 0 if this is after the initial down) or event count for multiple events.
        metaState - Flags indicating which meta keys are currently pressed.
        deviceId - The device ID that generated the key event.
        scancode - Raw device scan code of the event.
      • KeyEvent

        public KeyEvent(long downTime,
                long eventTime,
                int action,
                int code,
                int repeat,
                int metaState,
                int deviceId,
                int scancode,
                int flags)
        Create a new key event.
        Parameters:
        downTime - The time (in SystemClock.uptimeMillis()) at which this key code originally went down.
        eventTime - The time (in SystemClock.uptimeMillis()) at which this event happened.
        action - Action code: either ACTION_DOWN, ACTION_UP, or ACTION_MULTIPLE.
        code - The key code.
        repeat - A repeat count for down events (> 0 if this is after the initial down) or event count for multiple events.
        metaState - Flags indicating which meta keys are currently pressed.
        deviceId - The device ID that generated the key event.
        scancode - Raw device scan code of the event.
        flags - The flags for this key event
      • KeyEvent

        public KeyEvent(long downTime,
                long eventTime,
                int action,
                int code,
                int repeat,
                int metaState,
                int deviceId,
                int scancode,
                int flags,
                int source)
        Create a new key event.
        Parameters:
        downTime - The time (in SystemClock.uptimeMillis()) at which this key code originally went down.
        eventTime - The time (in SystemClock.uptimeMillis()) at which this event happened.
        action - Action code: either ACTION_DOWN, ACTION_UP, or ACTION_MULTIPLE.
        code - The key code.
        repeat - A repeat count for down events (> 0 if this is after the initial down) or event count for multiple events.
        metaState - Flags indicating which meta keys are currently pressed.
        deviceId - The device ID that generated the key event.
        scancode - Raw device scan code of the event.
        flags - The flags for this key event
        source - The input source such as InputDevice.SOURCE_KEYBOARD.
      • KeyEvent

        public KeyEvent(long time,
                String characters,
                int deviceId,
                int flags)
        Create a new key event for a string of characters. The key code, action, repeat count and source will automatically be set to KEYCODE_UNKNOWN, ACTION_MULTIPLE, 0, and InputDevice.SOURCE_KEYBOARD for you.
        Parameters:
        time - The time (in SystemClock.uptimeMillis()) at which this event occured.
        characters - The string of characters.
        deviceId - The device ID that generated the key event.
        flags - The flags for this key event
      • KeyEvent

        public KeyEvent(KeyEvent origEvent)
        Make an exact copy of an existing key event.
    • Method Detail

      • getMaxKeyCode

        public static int getMaxKeyCode()
        Returns the maximum keycode.
      • getDeadChar

        public static int getDeadChar(int accent,
                      int c)
        Get the character that is produced by putting accent on the character c. For example, getDeadChar('`', 'e') returns è.
      • obtain

        public static KeyEvent obtain(long downTime,
                      long eventTime,
                      int action,
                      int code,
                      int repeat,
                      int metaState,
                      int deviceId,
                      int scancode,
                      int flags,
                      int source,
                      String characters)
        Obtains a (potentially recycled) key event.
      • obtain

        public static KeyEvent obtain(KeyEvent other)
        Obtains a (potentially recycled) copy of another key event.
      • copy

        public KeyEvent copy()
        Description copied from class: InputEvent
        Copies the event.
        Specified by:
        copy in class InputEvent
        Returns:
        A deep copy of the event.
      • recycle

        public final void recycle()
        Recycles a key event. Key events should only be recycled if they are owned by the system since user code expects them to be essentially immutable, "tracking" notwithstanding.
        Overrides:
        recycle in class InputEvent
      • recycleIfNeededAfterDispatch

        public final void recycleIfNeededAfterDispatch()
        Description copied from class: InputEvent
        Conditionally recycled the event if it is appropriate to do so after dispatching the event to an application. If the event is a MotionEvent then it is recycled. If the event is a KeyEvent then it is NOT recycled, because applications expect key events to be immutable so once the event has been dispatched to the application we can no longer recycle it.
        Overrides:
        recycleIfNeededAfterDispatch in class InputEvent
      • changeTimeRepeat

        public static KeyEvent changeTimeRepeat(KeyEvent event,
                                long eventTime,
                                int newRepeat)
        Create a new key event that is the same as the given one, but whose event time and repeat count are replaced with the given value.
        Parameters:
        event - The existing event to be copied. This is not modified.
        eventTime - The new event time (in SystemClock.uptimeMillis()) of the event.
        newRepeat - The new repeat count of the event.
      • changeTimeRepeat

        public static KeyEvent changeTimeRepeat(KeyEvent event,
                                long eventTime,
                                int newRepeat,
                                int newFlags)
        Create a new key event that is the same as the given one, but whose event time and repeat count are replaced with the given value.
        Parameters:
        event - The existing event to be copied. This is not modified.
        eventTime - The new event time (in SystemClock.uptimeMillis()) of the event.
        newRepeat - The new repeat count of the event.
        newFlags - New flags for the event, replacing the entire value in the original event.
      • changeAction

        public static KeyEvent changeAction(KeyEvent event,
                            int action)
        Create a new key event that is the same as the given one, but whose action is replaced with the given value.
        Parameters:
        event - The existing event to be copied. This is not modified.
        action - The new action code of the event.
      • changeFlags

        public static KeyEvent changeFlags(KeyEvent event,
                           int flags)
        Create a new key event that is the same as the given one, but whose flags are replaced with the given value.
        Parameters:
        event - The existing event to be copied. This is not modified.
        flags - The new flags constant.
      • isTainted

        public final boolean isTainted()
        Description copied from class: InputEvent
        Gets a private flag that indicates when the system has detected that this input event may be inconsistent with respect to the sequence of previously delivered input events, such as when a key up event is sent but the key was not down or when a pointer move event is sent but the pointer is not down.
        Specified by:
        isTainted in class InputEvent
        Returns:
        True if this event is tainted.
      • setTainted

        public final void setTainted(boolean tainted)
        Description copied from class: InputEvent
        Sets a private flag that indicates when the system has detected that this input event may be inconsistent with respect to the sequence of previously delivered input events, such as when a key up event is sent but the key was not down or when a pointer move event is sent but the pointer is not down.
        Specified by:
        setTainted in class InputEvent
        Parameters:
        tainted - True if this event is tainted.
      • isDown

        @Deprecated
        public final boolean isDown()
        Deprecated.
        Don't use in new code, instead explicitly check getAction().
        Returns:
        If the action is ACTION_DOWN, returns true; else false.
      • isSystem

        public final boolean isSystem()
        Is this a system key? System keys can not be used for menu shortcuts. TODO: this information should come from a table somewhere. TODO: should the dpad keys be here? arguably, because they also shouldn't be menu shortcuts
      • hasDefaultAction

        public final boolean hasDefaultAction()
      • isGamepadButton

        public static final boolean isGamepadButton(int keyCode)
        Returns true if the specified keycode is a gamepad button.
        Returns:
        True if the keycode is a gamepad button, such as KEYCODE_BUTTON_A.
      • getDeviceId

        public final int getDeviceId()
        Gets the id for the device that this event came from. An id of zero indicates that the event didn't come from a physical device and maps to the default keymap. The other numbers are arbitrary and you shouldn't depend on the values.
        Specified by:
        getDeviceId in class InputEvent
        Returns:
        The device id.
        See Also:
        InputDevice.getDevice(int)
      • setSource

        public final void setSource(int source)
        Modifies the source of the event.
        Specified by:
        setSource in class InputEvent
        Parameters:
        source - The new source.
      • getFlags

        public final int getFlags()
        Returns the flags for this key event.
        See Also:
        FLAG_WOKE_HERE
      • normalizeMetaState

        public static int normalizeMetaState(int metaState)
        Normalizes the specified meta state.

        The meta state is normalized such that if either the left or right modifier meta state bits are set then the result will also include the universal bit for that modifier.

        If the specified meta state contains META_ALT_LEFT_ON then the result will also contain META_ALT_ON in addition to META_ALT_LEFT_ON and the other bits that were specified in the input. The same is process is performed for shift, control and meta.

        If the specified meta state contains synthetic meta states defined by MetaKeyKeyListener, then those states are translated here and the original synthetic meta states are removed from the result. MetaKeyKeyListener.META_CAP_LOCKED is translated to META_CAPS_LOCK_ON. MetaKeyKeyListener.META_ALT_LOCKED is translated to META_ALT_ON. MetaKeyKeyListener.META_SYM_LOCKED is translated to META_SYM_ON.

        Undefined meta state bits are removed.

        Parameters:
        metaState - The meta state.
        Returns:
        The normalized meta state.
      • metaStateHasModifiers

        public static boolean metaStateHasModifiers(int metaState,
                                    int modifiers)
        Returns true if only the specified modifier keys are pressed according to the specified meta state. Returns false if a different combination of modifier keys are pressed.

        For the purposes of this function, KEYCODE_CAPS_LOCK, KEYCODE_SCROLL_LOCK, and KEYCODE_NUM_LOCK are not considered modifier keys. Consequently, this function ignores META_CAPS_LOCK_ON, META_SCROLL_LOCK_ON and META_NUM_LOCK_ON.

        If the specified modifier mask includes directional modifiers, such as META_SHIFT_LEFT_ON, then this method ensures that the modifier is pressed on that side. If the specified modifier mask includes non-directional modifiers, such as META_SHIFT_ON, then this method ensures that the modifier is pressed on either side. If the specified modifier mask includes both directional and non-directional modifiers for the same type of key, such as META_SHIFT_ON and META_SHIFT_LEFT_ON, then this method throws an illegal argument exception.

        Parameters:
        metaState - The meta state to consider.
        modifiers - The meta state of the modifier keys to check. May be a combination of modifier meta states as defined by getModifierMetaStateMask(). May be 0 to ensure that no modifier keys are pressed.
        Returns:
        True if only the specified modifier keys are pressed.
        Throws:
        IllegalArgumentException - if the modifiers parameter contains invalid modifiers
        See Also:
        hasModifiers(int)
      • hasModifiers

        public final boolean hasModifiers(int modifiers)
        Returns true if only the specified modifiers keys are pressed. Returns false if a different combination of modifier keys are pressed.

        For the purposes of this function, KEYCODE_CAPS_LOCK, KEYCODE_SCROLL_LOCK, and KEYCODE_NUM_LOCK are not considered modifier keys. Consequently, this function ignores META_CAPS_LOCK_ON, META_SCROLL_LOCK_ON and META_NUM_LOCK_ON.

        If the specified modifier mask includes directional modifiers, such as META_SHIFT_LEFT_ON, then this method ensures that the modifier is pressed on that side. If the specified modifier mask includes non-directional modifiers, such as META_SHIFT_ON, then this method ensures that the modifier is pressed on either side. If the specified modifier mask includes both directional and non-directional modifiers for the same type of key, such as META_SHIFT_ON and META_SHIFT_LEFT_ON, then this method throws an illegal argument exception.

        Parameters:
        modifiers - The meta state of the modifier keys to check. May be a combination of modifier meta states as defined by getModifierMetaStateMask(). May be 0 to ensure that no modifier keys are pressed.
        Returns:
        True if only the specified modifier keys are pressed.
        Throws:
        IllegalArgumentException - if the modifiers parameter contains invalid modifiers
        See Also:
        metaStateHasModifiers(int, int)
      • isSymPressed

        public final boolean isSymPressed()

        Returns the pressed state of the SYM meta key.

        Returns:
        true if the SYM key is pressed, false otherwise
        See Also:
        KEYCODE_SYM, META_SYM_ON
      • isFunctionPressed

        public final boolean isFunctionPressed()

        Returns the pressed state of the FUNCTION meta key.

        Returns:
        true if the FUNCTION key is pressed, false otherwise
        See Also:
        KEYCODE_FUNCTION, META_FUNCTION_ON
      • isCapsLockOn

        public final boolean isCapsLockOn()

        Returns the locked state of the CAPS LOCK meta key.

        Returns:
        true if the CAPS LOCK key is on, false otherwise
        See Also:
        KEYCODE_CAPS_LOCK, META_CAPS_LOCK_ON
      • isNumLockOn

        public final boolean isNumLockOn()

        Returns the locked state of the NUM LOCK meta key.

        Returns:
        true if the NUM LOCK key is on, false otherwise
        See Also:
        KEYCODE_NUM_LOCK, META_NUM_LOCK_ON
      • isScrollLockOn

        public final boolean isScrollLockOn()

        Returns the locked state of the SCROLL LOCK meta key.

        Returns:
        true if the SCROLL LOCK key is on, false otherwise
        See Also:
        KEYCODE_SCROLL_LOCK, META_SCROLL_LOCK_ON
      • getAction

        public final int getAction()
        Retrieve the action of this key event. May be either ACTION_DOWN, ACTION_UP, or ACTION_MULTIPLE.
        Returns:
        The event action: ACTION_DOWN, ACTION_UP, or ACTION_MULTIPLE.
      • isCanceled

        public final boolean isCanceled()
        For ACTION_UP events, indicates that the event has been canceled as per FLAG_CANCELED.
      • startTracking

        public final void startTracking()
        Call this during KeyEvent.Callback.onKeyDown(int, android.view.KeyEvent) to have the system track the key through its final up (possibly including a long press). Note that only one key can be tracked at a time -- if another key down event is received while a previous one is being tracked, tracking is stopped on the previous event.
      • isTracking

        public final boolean isTracking()
        For ACTION_UP events, indicates that the event is still being tracked from its initial down event as per FLAG_TRACKING.
      • isLongPress

        public final boolean isLongPress()
        For ACTION_DOWN events, indicates that the event has been canceled as per FLAG_LONG_PRESS.
      • getKeyCode

        public final int getKeyCode()
        Retrieve the key code of the key event. This is the physical key that was pressed, not the Unicode character.
        Returns:
        The key code of the event.
      • getCharacters

        public final String getCharacters()
        For the special case of a ACTION_MULTIPLE event with key code of KEYCODE_UNKNOWN, this is a raw string of characters associated with the event. In all other cases it is null.
        Returns:
        Returns a String of 1 or more characters associated with the event.
      • getScanCode

        public final int getScanCode()
        Retrieve the hardware key id of this key event. These values are not reliable and vary from device to device. Mostly this is here for debugging purposes.
      • getRepeatCount

        public final int getRepeatCount()
        Retrieve the repeat count of the event. For both key up and key down events, this is the number of times the key has repeated with the first down starting at 0 and counting up from there. For multiple key events, this is the number of down/up pairs that have occurred.
        Returns:
        The number of times the key has repeated.
      • getDownTime

        public final long getDownTime()
        Retrieve the time of the most recent key down event, in the SystemClock.uptimeMillis() time base. If this is a down event, this will be the same as getEventTime(). Note that when chording keys, this value is the down time of the most recently pressed key, which may not be the same physical key of this event.
        Returns:
        Returns the most recent key down time, in the SystemClock.uptimeMillis() time base
      • getEventTimeNano

        public final long getEventTimeNano()
        Retrieve the time this event occurred, in the SystemClock.uptimeMillis() time base but with nanosecond (instead of millisecond) precision.

        The value is in nanosecond precision but it may not have nanosecond accuracy.

        Specified by:
        getEventTimeNano in class InputEvent
        Returns:
        Returns the time this event occurred, in the SystemClock.uptimeMillis() time base but with nanosecond (instead of millisecond) precision.
      • getKeyCharacterMap

        public final KeyCharacterMap getKeyCharacterMap()
        Gets the KeyCharacterMap associated with the keyboard device.
        Returns:
        The associated key character map.
        Throws:
        {@link - KeyCharacterMap.UnavailableException} if the key character map could not be loaded because it was malformed or the default key character map is missing from the system.
        See Also:
        KeyCharacterMap.load(int)
      • getDisplayLabel

        public char getDisplayLabel()
        Gets the primary character for this key. In other words, the label that is physically printed on it.
        Returns:
        The display label character, or 0 if none (eg. for non-printing keys).
      • getUnicodeChar

        public int getUnicodeChar()
        Gets the Unicode character generated by the specified key and meta key state combination.

        Returns the Unicode character that the specified key would produce when the specified meta bits (see MetaKeyKeyListener) were active.

        Returns 0 if the key is not one that is used to type Unicode characters.

        If the return value has bit KeyCharacterMap.COMBINING_ACCENT set, the key is a "dead key" that should be combined with another to actually produce a character -- see KeyCharacterMap.getDeadChar(int, int) -- after masking with KeyCharacterMap.COMBINING_ACCENT_MASK.

        Returns:
        The associated character or combining accent, or 0 if none.
      • getUnicodeChar

        public int getUnicodeChar(int metaState)
        Gets the Unicode character generated by the specified key and meta key state combination.

        Returns the Unicode character that the specified key would produce when the specified meta bits (see MetaKeyKeyListener) were active.

        Returns 0 if the key is not one that is used to type Unicode characters.

        If the return value has bit KeyCharacterMap.COMBINING_ACCENT set, the key is a "dead key" that should be combined with another to actually produce a character -- see KeyCharacterMap.getDeadChar(int, int) -- after masking with KeyCharacterMap.COMBINING_ACCENT_MASK.

        Parameters:
        metaState - The meta key modifier state.
        Returns:
        The associated character or combining accent, or 0 if none.
      • getMatch

        public char getMatch(char[] chars)
        Gets the first character in the character array that can be generated by the specified key code.

        This is a convenience function that returns the same value as getMatch(chars, 0).

        Parameters:
        chars - The array of matching characters to consider.
        Returns:
        The matching associated character, or 0 if none.
      • getMatch

        public char getMatch(char[] chars,
                    int metaState)
        Gets the first character in the character array that can be generated by the specified key code. If there are multiple choices, prefers the one that would be generated with the specified meta key modifier state.
        Parameters:
        chars - The array of matching characters to consider.
        metaState - The preferred meta key modifier state.
        Returns:
        The matching associated character, or 0 if none.
      • getNumber

        public char getNumber()
        Gets the number or symbol associated with the key.

        The character value is returned, not the numeric value. If the key is not a number, but is a symbol, the symbol is retuned.

        This method is intended to to support dial pads and other numeric or symbolic entry on keyboards where certain keys serve dual function as alphabetic and symbolic keys. This method returns the number or symbol associated with the key independent of whether the user has pressed the required modifier.

        For example, on one particular keyboard the keys on the top QWERTY row generate numbers when ALT is pressed such that ALT-Q maps to '1'. So for that keyboard when getNumber() is called with KEYCODE_Q it returns '1' so that the user can type numbers without pressing ALT when it makes sense.

        Returns:
        The associated numeric or symbolic character, or 0 if none.
      • isPrintingKey

        public boolean isPrintingKey()
        Returns true if this key produces a glyph.
        Returns:
        True if the key is a printing key.
      • dispatch

        public final boolean dispatch(KeyEvent.Callback receiver,
                       KeyEvent.DispatcherState state,
                       Object target)
        Deliver this key event to a KeyEvent.Callback interface. If this is an ACTION_MULTIPLE event and it is not handled, then an attempt will be made to deliver a single normal event.
        Parameters:
        receiver - The Callback that will be given the event.
        state - State information retained across events.
        target - The target of the dispatch, for use in tracking.
        Returns:
        The return value from the Callback method that was called.
      • toString

        public String toString()
        Description copied from class: Object
        Returns a string containing a concise, human-readable description of this object. Subclasses are encouraged to override this method and provide an implementation that takes into account the object's type and data. The default implementation is equivalent to the following expression:
           getClass().getName() + '@' + Integer.toHexString(hashCode())

        See Writing a useful toString method if you intend implementing your own toString method.

        Overrides:
        toString in class Object
        Returns:
        a printable representation of this object.
      • actionToString

        public static String actionToString(int action)
        Returns a string that represents the symbolic name of the specified action such as "ACTION_DOWN", or an equivalent numeric constant such as "35" if unknown.
        Parameters:
        action - The action.
        Returns:
        The symbolic name of the specified action.
      • keyCodeToString

        public static String keyCodeToString(int keyCode)
        Returns a string that represents the symbolic name of the specified keycode such as "KEYCODE_A", "KEYCODE_DPAD_UP", or an equivalent numeric constant such as "1001" if unknown.
        Parameters:
        keyCode - The key code.
        Returns:
        The symbolic name of the specified keycode.
        See Also:
        KeyCharacterMap.getDisplayLabel(int)
      • keyCodeFromString

        public static int keyCodeFromString(String symbolicName)
        Gets a keycode by its symbolic name such as "KEYCODE_A" or an equivalent numeric constant such as "1001".
        Parameters:
        symbolicName - The symbolic name of the keycode.
        Returns:
        The keycode or KEYCODE_UNKNOWN if not found.
        See Also:
        #keycodeToString
      • metaStateToString

        public static String metaStateToString(int metaState)
        Returns a string that represents the symbolic name of the specified combined meta key modifier state flags such as "0", "META_SHIFT_ON", "META_ALT_ON|META_SHIFT_ON" or an equivalent numeric constant such as "0x10000000" if unknown.
        Parameters:
        metaState - The meta state.
        Returns:
        The symbolic name of the specified combined meta state flags.
      • createFromParcelBody

        public static KeyEvent createFromParcelBody(Parcel in)


Content

Android Reference

Java basics

Java Enterprise Edition (EE)

Java Standard Edition (SE)

SQL

HTML

PHP

CSS

Java Script

MYSQL

JQUERY

VBS

REGEX

C

C++

C#

Design patterns

RFC (standard status)

RFC (proposed standard status)

RFC (draft standard status)

RFC (informational status)

RFC (experimental status)

RFC (best current practice status)

RFC (historic status)

RFC (unknown status)

IT dictionary

License.
All information of this service is derived from the free sources and is provided solely in the form of quotations. This service provides information and interfaces solely for the familiarization (not ownership) and under the "as is" condition.
Copyright 2016 © ELTASK.COM. All rights reserved.
Site is optimized for mobile devices.
Downloads: 3380 / . Delta: 0.12968 с