Package icyllis.modernui.view
Class KeyEvent
java.lang.Object
icyllis.modernui.view.InputEvent
icyllis.modernui.view.KeyEvent
Object that reports key events (keyboard etc.).
Modified for desktop application.
-
Nested Class Summary
-
Field Summary
Modifier and TypeFieldDescriptionstatic final int
getAction()
value: the key has been pressed down.static final int
getAction()
value: the key has been released.static final int
When associated with up key events, this indicates that the key press has been canceled.static final int
Set when a key event hasFLAG_CANCELED
set because a long press action was executed while it was down.static final int
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".static final int
Set when a key event has been synthesized to implement default behavior for an event that the application did not handle.static final int
This mask is set if an event was known to come from a trusted part of the system.static final int
This mask is set if we don't want the key event to cause us to leave touch mode.static final int
This flag is set for the first key repeat that occurs after the long press timeout.static final int
Signifies that the key is being predispatched.static final int
This mask is set if the key event was generated by a software keyboard.static final int
Private control to determine when an app is tracking a key sequence.static final int
Set forACTION_UP
when this event's key code is still being tracked from its initial down.static final int
This key event was generated by a virtual (on-screen) hard key area.static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
-
Method Summary
Modifier and TypeMethodDescriptionfinal void
cancel()
Marks the input event as being canceled.copy()
Copies the event.final int
Retrieve the action of this key event.long
Get the time in milliseconds that this event object is created in the GLFW time baselong
Get the precise time in nanoseconds that this event object is created in the GLFW time basefinal int
Retrieve the key code of the key event.final char
Returns the alphabetic character represented by the key.final int
Returns the state of the modifier keys.final int
Retrieve the repeat count of the event.final int
Retrieve the hardware key id of this key event.final boolean
hasModifiers
(int modifiers) Returns true if only the specified modifiers keys are pressed.final boolean
Returns true if no modifier keys are pressed.final boolean
Returns the pressed state of the ALT key.final boolean
ForACTION_UP
events, indicates that the event has been canceled as perFLAG_CANCELED
.final boolean
Returns the locked state of the CAPS LOCK key.final boolean
Returns the pressed state of the CTRL key.final boolean
ForACTION_DOWN
events, indicates that the event has been canceled as perFLAG_LONG_PRESS
.static boolean
isModifierKey
(int keyCode) Returns true if this key code is a modifier key.final boolean
Returns the locked state of the NUM LOCK key.final boolean
Returns the pressed state of the SHIFT key.final boolean
Returns the pressed state of the SUPER key (a.k.a.final boolean
ForACTION_UP
events, indicates that the event is still being tracked from its initial down event as perFLAG_TRACKING
.static KeyEvent
obtain
(long eventTime, int action, int code, int repeat, int modifiers, int scancode, int flags) void
recycle()
Recycles the event.final void
Call this duringinvalid reference
Callback#onKeyDown
-
Field Details
-
KEY_UNKNOWN
public static final int KEY_UNKNOWN- See Also:
-
KEY_SPACE
public static final int KEY_SPACE- See Also:
-
KEY_APOSTROPHE
public static final int KEY_APOSTROPHE- See Also:
-
KEY_COMMA
public static final int KEY_COMMA- See Also:
-
KEY_MINUS
public static final int KEY_MINUS- See Also:
-
KEY_PERIOD
public static final int KEY_PERIOD- See Also:
-
KEY_SLASH
public static final int KEY_SLASH- See Also:
-
KEY_0
public static final int KEY_0- See Also:
-
KEY_1
public static final int KEY_1- See Also:
-
KEY_2
public static final int KEY_2- See Also:
-
KEY_3
public static final int KEY_3- See Also:
-
KEY_4
public static final int KEY_4- See Also:
-
KEY_5
public static final int KEY_5- See Also:
-
KEY_6
public static final int KEY_6- See Also:
-
KEY_7
public static final int KEY_7- See Also:
-
KEY_8
public static final int KEY_8- See Also:
-
KEY_9
public static final int KEY_9- See Also:
-
KEY_SEMICOLON
public static final int KEY_SEMICOLON- See Also:
-
KEY_EQUAL
public static final int KEY_EQUAL- See Also:
-
KEY_A
public static final int KEY_A- See Also:
-
KEY_B
public static final int KEY_B- See Also:
-
KEY_C
public static final int KEY_C- See Also:
-
KEY_D
public static final int KEY_D- See Also:
-
KEY_E
public static final int KEY_E- See Also:
-
KEY_F
public static final int KEY_F- See Also:
-
KEY_G
public static final int KEY_G- See Also:
-
KEY_H
public static final int KEY_H- See Also:
-
KEY_I
public static final int KEY_I- See Also:
-
KEY_J
public static final int KEY_J- See Also:
-
KEY_K
public static final int KEY_K- See Also:
-
KEY_L
public static final int KEY_L- See Also:
-
KEY_M
public static final int KEY_M- See Also:
-
KEY_N
public static final int KEY_N- See Also:
-
KEY_O
public static final int KEY_O- See Also:
-
KEY_P
public static final int KEY_P- See Also:
-
KEY_Q
public static final int KEY_Q- See Also:
-
KEY_R
public static final int KEY_R- See Also:
-
KEY_S
public static final int KEY_S- See Also:
-
KEY_T
public static final int KEY_T- See Also:
-
KEY_U
public static final int KEY_U- See Also:
-
KEY_V
public static final int KEY_V- See Also:
-
KEY_W
public static final int KEY_W- See Also:
-
KEY_X
public static final int KEY_X- See Also:
-
KEY_Y
public static final int KEY_Y- See Also:
-
KEY_Z
public static final int KEY_Z- See Also:
-
KEY_LEFT_BRACKET
public static final int KEY_LEFT_BRACKET- See Also:
-
KEY_BACKSLASH
public static final int KEY_BACKSLASH- See Also:
-
KEY_RIGHT_BRACKET
public static final int KEY_RIGHT_BRACKET- See Also:
-
KEY_GRAVE_ACCENT
public static final int KEY_GRAVE_ACCENT- See Also:
-
KEY_WORLD_1
public static final int KEY_WORLD_1- See Also:
-
KEY_WORLD_2
public static final int KEY_WORLD_2- See Also:
-
KEY_ESCAPE
public static final int KEY_ESCAPE- See Also:
-
KEY_ENTER
public static final int KEY_ENTER- See Also:
-
KEY_TAB
public static final int KEY_TAB- See Also:
-
KEY_BACKSPACE
public static final int KEY_BACKSPACE- See Also:
-
KEY_INSERT
public static final int KEY_INSERT- See Also:
-
KEY_DELETE
public static final int KEY_DELETE- See Also:
-
KEY_RIGHT
public static final int KEY_RIGHT- See Also:
-
KEY_LEFT
public static final int KEY_LEFT- See Also:
-
KEY_DOWN
public static final int KEY_DOWN- See Also:
-
KEY_UP
public static final int KEY_UP- See Also:
-
KEY_PAGE_UP
public static final int KEY_PAGE_UP- See Also:
-
KEY_PAGE_DOWN
public static final int KEY_PAGE_DOWN- See Also:
-
KEY_HOME
public static final int KEY_HOME- See Also:
-
KEY_END
public static final int KEY_END- See Also:
-
KEY_CAPS_LOCK
public static final int KEY_CAPS_LOCK- See Also:
-
KEY_SCROLL_LOCK
public static final int KEY_SCROLL_LOCK- See Also:
-
KEY_NUM_LOCK
public static final int KEY_NUM_LOCK- See Also:
-
KEY_PRINT_SCREEN
public static final int KEY_PRINT_SCREEN- See Also:
-
KEY_PAUSE
public static final int KEY_PAUSE- See Also:
-
KEY_F1
public static final int KEY_F1- See Also:
-
KEY_F2
public static final int KEY_F2- See Also:
-
KEY_F3
public static final int KEY_F3- See Also:
-
KEY_F4
public static final int KEY_F4- See Also:
-
KEY_F5
public static final int KEY_F5- See Also:
-
KEY_F6
public static final int KEY_F6- See Also:
-
KEY_F7
public static final int KEY_F7- See Also:
-
KEY_F8
public static final int KEY_F8- See Also:
-
KEY_F9
public static final int KEY_F9- See Also:
-
KEY_F10
public static final int KEY_F10- See Also:
-
KEY_F11
public static final int KEY_F11- See Also:
-
KEY_F12
public static final int KEY_F12- See Also:
-
KEY_F13
public static final int KEY_F13- See Also:
-
KEY_F14
public static final int KEY_F14- See Also:
-
KEY_F15
public static final int KEY_F15- See Also:
-
KEY_F16
public static final int KEY_F16- See Also:
-
KEY_F17
public static final int KEY_F17- See Also:
-
KEY_F18
public static final int KEY_F18- See Also:
-
KEY_F19
public static final int KEY_F19- See Also:
-
KEY_F20
public static final int KEY_F20- See Also:
-
KEY_F21
public static final int KEY_F21- See Also:
-
KEY_F22
public static final int KEY_F22- See Also:
-
KEY_F23
public static final int KEY_F23- See Also:
-
KEY_F24
public static final int KEY_F24- See Also:
-
KEY_F25
public static final int KEY_F25- See Also:
-
KEY_KP_0
public static final int KEY_KP_0- See Also:
-
KEY_KP_1
public static final int KEY_KP_1- See Also:
-
KEY_KP_2
public static final int KEY_KP_2- See Also:
-
KEY_KP_3
public static final int KEY_KP_3- See Also:
-
KEY_KP_4
public static final int KEY_KP_4- See Also:
-
KEY_KP_5
public static final int KEY_KP_5- See Also:
-
KEY_KP_6
public static final int KEY_KP_6- See Also:
-
KEY_KP_7
public static final int KEY_KP_7- See Also:
-
KEY_KP_8
public static final int KEY_KP_8- See Also:
-
KEY_KP_9
public static final int KEY_KP_9- See Also:
-
KEY_KP_DECIMAL
public static final int KEY_KP_DECIMAL- See Also:
-
KEY_KP_DIVIDE
public static final int KEY_KP_DIVIDE- See Also:
-
KEY_KP_MULTIPLY
public static final int KEY_KP_MULTIPLY- See Also:
-
KEY_KP_SUBTRACT
public static final int KEY_KP_SUBTRACT- See Also:
-
KEY_KP_ADD
public static final int KEY_KP_ADD- See Also:
-
KEY_KP_ENTER
public static final int KEY_KP_ENTER- See Also:
-
KEY_KP_EQUAL
public static final int KEY_KP_EQUAL- See Also:
-
KEY_LEFT_SHIFT
public static final int KEY_LEFT_SHIFT- See Also:
-
KEY_LEFT_CONTROL
public static final int KEY_LEFT_CONTROL- See Also:
-
KEY_LEFT_ALT
public static final int KEY_LEFT_ALT- See Also:
-
KEY_LEFT_SUPER
public static final int KEY_LEFT_SUPER- See Also:
-
KEY_RIGHT_SHIFT
public static final int KEY_RIGHT_SHIFT- See Also:
-
KEY_RIGHT_CONTROL
public static final int KEY_RIGHT_CONTROL- See Also:
-
KEY_RIGHT_ALT
public static final int KEY_RIGHT_ALT- See Also:
-
KEY_RIGHT_SUPER
public static final int KEY_RIGHT_SUPER- See Also:
-
KEY_MENU
public static final int KEY_MENU- See Also:
-
META_SHIFT_ON
public static final int META_SHIFT_ON- See Also:
-
META_CTRL_ON
public static final int META_CTRL_ON -
META_ALT_ON
public static final int META_ALT_ON- See Also:
-
META_SUPER_ON
public static final int META_SUPER_ON- See Also:
-
FLAG_SOFT_KEYBOARD
public static final int FLAG_SOFT_KEYBOARDThis mask is set if the key event was generated by a software keyboard.- See Also:
-
FLAG_KEEP_TOUCH_MODE
public static final int FLAG_KEEP_TOUCH_MODEThis mask is set if we don't want the key event to cause us to leave touch mode.- See Also:
-
FLAG_FROM_SYSTEM
public static final int FLAG_FROM_SYSTEMThis 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:
-
FLAG_EDITOR_ACTION
public static final int FLAG_EDITOR_ACTIONThis 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:
-
FLAG_CANCELED
public static final int FLAG_CANCELEDWhen 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:
-
FLAG_VIRTUAL_HARD_KEY
public static final int FLAG_VIRTUAL_HARD_KEYThis 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:
-
FLAG_LONG_PRESS
public static final int FLAG_LONG_PRESSThis flag is set for the first key repeat that occurs after the long press timeout.- See Also:
-
FLAG_CANCELED_LONG_PRESS
public static final int FLAG_CANCELED_LONG_PRESSSet when a key event hasFLAG_CANCELED
set because a long press action was executed while it was down.- See Also:
-
FLAG_TRACKING
public static final int FLAG_TRACKINGSet forACTION_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:
-
FLAG_FALLBACK
public static final int FLAG_FALLBACKSet 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:
-
FLAG_PREDISPATCH
public static final int FLAG_PREDISPATCHSignifies that the key is being predispatched.- See Also:
-
FLAG_START_TRACKING
public static final int FLAG_START_TRACKINGPrivate control to determine when an app is tracking a key sequence.- See Also:
-
ACTION_DOWN
public static final int ACTION_DOWNgetAction()
value: the key has been pressed down.- See Also:
-
ACTION_UP
public static final int ACTION_UPgetAction()
value: the key has been released.- See Also:
-
-
Method Details
-
obtain
-
getAction
public final int getAction()Retrieve the action of this key event. May be eitherACTION_DOWN
orACTION_UP
.- Returns:
- The event action: ACTION_DOWN or ACTION_UP.
-
getKeyCode
public final int getKeyCode()Retrieve the key code of the key event.- Returns:
- The key code of 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. -
getRepeatCount
public final int getRepeatCount()Retrieve the repeat count of the event. For 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 key up events, this is always equal to zero. For multiple key events, this is the number of down/up pairs that have occurred.- Returns:
- The number of times the key has repeated.
-
getModifiers
public final int getModifiers()Returns the state of the modifier keys.- Returns:
- An integer in which each bit set to 1 represents a pressed modifier key.
-
hasNoModifiers
public final boolean hasNoModifiers()Returns true if no modifier keys are pressed.- Returns:
- True if no modifier keys are pressed.
-
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.If the specified modifier mask includes non-directional modifiers, such as
GLFW.GLFW_MOD_SHIFT
, then this method ensures that the modifier is pressed on either side.- Parameters:
modifiers
- The modifier keys to check. May be a combination of modifier keys. May be 0 to ensure that no modifier keys are pressed.- Returns:
- true if only the specified modifier keys are pressed.
-
isShiftPressed
public final boolean isShiftPressed()Returns the pressed state of the SHIFT key.- Returns:
- true if the SHIFT key is pressed, false otherwise
-
isCtrlPressed
public final boolean isCtrlPressed()Returns the pressed state of the CTRL key. If it's running on OSX, returns the pressed state of the SUPER key.- Returns:
- true if the CTRL key is pressed, false otherwise
-
isAltPressed
public final boolean isAltPressed()Returns the pressed state of the ALT key.- Returns:
- true if the ALT key is pressed, false otherwise
-
isSuperPressed
public final boolean isSuperPressed()Returns the pressed state of the SUPER key (a.k.a. META or WIN key).- Returns:
- true if the SUPER key is pressed, false otherwise
-
isCapsLockOn
public final boolean isCapsLockOn()Returns the locked state of the CAPS LOCK key.- Returns:
- true if the CAPS LOCK key is on, false otherwise
-
isNumLockOn
public final boolean isNumLockOn()Returns the locked state of the NUM LOCK key.- Returns:
- true if the NUM LOCK key is on, false otherwise
-
getMappedChar
public final char getMappedChar()Returns the alphabetic character represented by the key. You should check if this is a PRESS action.- Returns:
- the alphabetic character represented by the key
-
recycle
public void recycle()Recycles the event. This object should not be ever used after recycling.This method should only be called by system.
- Specified by:
recycle
in classInputEvent
-
copy
Description copied from class:InputEvent
Copies the event.- Specified by:
copy
in classInputEvent
- Returns:
- A deep copy of the event.
-
getEventTime
public long getEventTime()Description copied from class:InputEvent
Get the time in milliseconds that this event object is created in the GLFW time base- Specified by:
getEventTime
in classInputEvent
- Returns:
- the time this event occurred
-
getEventTimeNano
public long getEventTimeNano()Description copied from class:InputEvent
Get the precise time in nanoseconds that this event object is created in the GLFW time base- Specified by:
getEventTimeNano
in classInputEvent
- Returns:
- the time this event occurred
-
isCanceled
public final boolean isCanceled()ForACTION_UP
events, indicates that the event has been canceled as perFLAG_CANCELED
. -
cancel
public final void cancel()Description copied from class:InputEvent
Marks the input event as being canceled.- Specified by:
cancel
in classInputEvent
-
startTracking
public final void startTracking()Call this duringinvalid reference
Callback#onKeyDown
-
isTracking
public final boolean isTracking()ForACTION_UP
events, indicates that the event is still being tracked from its initial down event as perFLAG_TRACKING
. -
isLongPress
public final boolean isLongPress()ForACTION_DOWN
events, indicates that the event has been canceled as perFLAG_LONG_PRESS
. -
isModifierKey
public static boolean isModifierKey(int keyCode) Returns true if this key code is a modifier key.For the purposes of this function,
KEY_CAPS_LOCK
,KEY_SCROLL_LOCK
, andKEY_NUM_LOCK
are not considered modifier keys. Consequently, this function return false for those keys.- Returns:
- True if the key code is one of modifier keys.
-