Class NativeKeyEvent
- All Implemented Interfaces:
Serializable
This low-level event is generated by the native system when a key is pressed or released
independent of Java component focus. The event is passed to every
NativeKeyListener object which has been registered to receive
global key events using the GlobalScreen.addNativeKeyListener(NativeKeyListener) method.
Each NativeKeyListener object will receive a
NativeKeyEvent when the event occurs.
All NativeKeyEvent objects are dependent on the native platform and keyboard layout.
NATIVE_KEY_PRESSED and NATIVE_KEY_RELEASED events are generated for
every key code received by the native system. The key being pressed or released is indicated by
the getKeyCode method, which returns a virtual key code or
VC_UNDEFINED. Please note that getKeyChar() for events of type
NATIVE_KEY_PRESSED and NATIVE_KEY_RELEASED will always return
CHAR_UNDEFINED.
NATIVE_KEY_TYPED events are produced for NATIVE_KEY_PRESSED
events that produce valid Unicode characters for the current keyboard layout. The getKeyChar() method always returns a valid Unicode character for this type of event. Please
note that getKeyCode() will always return VC_UNDEFINED for
NATIVE_KEY_TYPED events.
Virtual key codes only represent the physical key that has been pressed and should not be
mistaken with the character mapped to that key by the operating system.
NATIVE_KEY_PRESSED and NATIVE_KEY_RELEASED events should only be used
to determin phisical key state, while NATIVE_KEY_TYPED events can be used to
determine the Unicode representation of the NativeKeyEvent.
- Since:
- 1.0
- Version:
- 2.0
- Author:
- Alexander Barker (alex@1stleg.com)
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final charThis is used to indicate that the keyChar is undefined.static final intstatic final intstatic final intstatic final intstatic final intstatic final intThe first number in the range of ID's used for native key events.static final intThe last number in the range of ID's used for native key events.static final intThe "native key pressed" event ID.static final intThe "native key released" event ID.static final intThe "native key typed" event ID.static final intstatic final intConstants for the 0 through 9 keys.static final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intConstants for the A through Z keys.static final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intConstants for the F1 through F24 function keys.static final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intEdit Key Zonestatic final intstatic final intstatic final intstatic final intJapanese Language Keysstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intBegin Numeric Zonestatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intMedia and Extra Keysstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intModifier and Control Keysstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intSun keyboardsstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intThis value is used to indicate that the keyCode is unknown.static final intstatic final intBegin Cursor Key Zonestatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intFields inherited from class com.github.kwhat.jnativehook.NativeInputEvent
ALT_L_MASK, ALT_MASK, ALT_R_MASK, BUTTON1_MASK, BUTTON2_MASK, BUTTON3_MASK, BUTTON4_MASK, BUTTON5_MASK, CAPS_LOCK_MASK, CTRL_L_MASK, CTRL_MASK, CTRL_R_MASK, META_L_MASK, META_MASK, META_R_MASK, NUM_LOCK_MASK, SCROLL_LOCK_MASK, SHIFT_L_MASK, SHIFT_MASK, SHIFT_R_MASKFields inherited from class java.util.EventObject
source -
Constructor Summary
ConstructorsConstructorDescriptionNativeKeyEvent(int id, int modifiers, int rawCode, int keyCode, char keyChar) Instantiates a new native key event.NativeKeyEvent(int id, int modifiers, int rawCode, int keyCode, char keyChar, int keyLocation) Instantiates a new native key event. -
Method Summary
Modifier and TypeMethodDescriptioncharReturns the native Unicode character associated with this event.intReturns the keyCode associated with this event.intReturns the location of the virtual key for this event.static StringgetKeyText(int keyCode) Returns a String describing the keyCode, such as "HOME", "F1" or "A".intReturns the native code associated with the native key in this event.booleanReturns whether the key in this event is an "action" key.Returns a parameter string identifying this event.voidsetKeyChar(char keyChar) Set the keyChar value in this event.voidsetKeyCode(int keyCode) Set the keyCode value in this event.voidsetRawCode(int rawCode) Set the rawCode value in this event.Methods inherited from class com.github.kwhat.jnativehook.NativeInputEvent
getID, getModifiers, getModifiersText, getWhen, setModifiersMethods inherited from class java.util.EventObject
getSource, toString
-
Field Details
-
NATIVE_KEY_FIRST
public static final int NATIVE_KEY_FIRSTThe first number in the range of ID's used for native key events.- See Also:
-
NATIVE_KEY_LAST
public static final int NATIVE_KEY_LASTThe last number in the range of ID's used for native key events.- See Also:
-
NATIVE_KEY_TYPED
public static final int NATIVE_KEY_TYPEDThe "native key typed" event ID.- See Also:
-
NATIVE_KEY_PRESSED
public static final int NATIVE_KEY_PRESSEDThe "native key pressed" event ID.- See Also:
-
NATIVE_KEY_RELEASED
public static final int NATIVE_KEY_RELEASEDThe "native key released" event ID.- See Also:
-
KEY_LOCATION_UNKNOWN
public static final int KEY_LOCATION_UNKNOWN- See Also:
-
KEY_LOCATION_STANDARD
public static final int KEY_LOCATION_STANDARD- See Also:
-
KEY_LOCATION_LEFT
public static final int KEY_LOCATION_LEFT- See Also:
-
KEY_LOCATION_RIGHT
public static final int KEY_LOCATION_RIGHT- See Also:
-
KEY_LOCATION_NUMPAD
public static final int KEY_LOCATION_NUMPAD- See Also:
-
VC_ESCAPE
public static final int VC_ESCAPE- See Also:
-
VC_F1
public static final int VC_F1Constants for the F1 through F24 function keys.- See Also:
-
VC_F2
public static final int VC_F2- See Also:
-
VC_F3
public static final int VC_F3- See Also:
-
VC_F4
public static final int VC_F4- See Also:
-
VC_F5
public static final int VC_F5- See Also:
-
VC_F6
public static final int VC_F6- See Also:
-
VC_F7
public static final int VC_F7- See Also:
-
VC_F8
public static final int VC_F8- See Also:
-
VC_F9
public static final int VC_F9- See Also:
-
VC_F10
public static final int VC_F10- See Also:
-
VC_F11
public static final int VC_F11- See Also:
-
VC_F12
public static final int VC_F12- See Also:
-
VC_F13
public static final int VC_F13- See Also:
-
VC_F14
public static final int VC_F14- See Also:
-
VC_F15
public static final int VC_F15- See Also:
-
VC_F16
public static final int VC_F16- See Also:
-
VC_F17
public static final int VC_F17- See Also:
-
VC_F18
public static final int VC_F18- See Also:
-
VC_F19
public static final int VC_F19- See Also:
-
VC_F20
public static final int VC_F20- See Also:
-
VC_F21
public static final int VC_F21- See Also:
-
VC_F22
public static final int VC_F22- See Also:
-
VC_F23
public static final int VC_F23- See Also:
-
VC_F24
public static final int VC_F24- See Also:
-
VC_BACKQUOTE
public static final int VC_BACKQUOTE- See Also:
-
VC_1
public static final int VC_1Constants for the 0 through 9 keys.- See Also:
-
VC_2
public static final int VC_2- See Also:
-
VC_3
public static final int VC_3- See Also:
-
VC_4
public static final int VC_4- See Also:
-
VC_5
public static final int VC_5- See Also:
-
VC_6
public static final int VC_6- See Also:
-
VC_7
public static final int VC_7- See Also:
-
VC_8
public static final int VC_8- See Also:
-
VC_9
public static final int VC_9- See Also:
-
VC_0
public static final int VC_0- See Also:
-
VC_MINUS
public static final int VC_MINUS- See Also:
-
VC_EQUALS
public static final int VC_EQUALS- See Also:
-
VC_BACKSPACE
public static final int VC_BACKSPACE- See Also:
-
VC_TAB
public static final int VC_TAB- See Also:
-
VC_CAPS_LOCK
public static final int VC_CAPS_LOCK- See Also:
-
VC_A
public static final int VC_AConstants for the A through Z keys.- See Also:
-
VC_B
public static final int VC_B- See Also:
-
VC_C
public static final int VC_C- See Also:
-
VC_D
public static final int VC_D- See Also:
-
VC_E
public static final int VC_E- See Also:
-
VC_F
public static final int VC_F- See Also:
-
VC_G
public static final int VC_G- See Also:
-
VC_H
public static final int VC_H- See Also:
-
VC_I
public static final int VC_I- See Also:
-
VC_J
public static final int VC_J- See Also:
-
VC_K
public static final int VC_K- See Also:
-
VC_L
public static final int VC_L- See Also:
-
VC_M
public static final int VC_M- See Also:
-
VC_N
public static final int VC_N- See Also:
-
VC_O
public static final int VC_O- See Also:
-
VC_P
public static final int VC_P- See Also:
-
VC_Q
public static final int VC_Q- See Also:
-
VC_R
public static final int VC_R- See Also:
-
VC_S
public static final int VC_S- See Also:
-
VC_T
public static final int VC_T- See Also:
-
VC_U
public static final int VC_U- See Also:
-
VC_V
public static final int VC_V- See Also:
-
VC_W
public static final int VC_W- See Also:
-
VC_X
public static final int VC_X- See Also:
-
VC_Y
public static final int VC_Y- See Also:
-
VC_Z
public static final int VC_Z- See Also:
-
VC_OPEN_BRACKET
public static final int VC_OPEN_BRACKET- See Also:
-
VC_CLOSE_BRACKET
public static final int VC_CLOSE_BRACKET- See Also:
-
VC_BACK_SLASH
public static final int VC_BACK_SLASH- See Also:
-
VC_SEMICOLON
public static final int VC_SEMICOLON- See Also:
-
VC_QUOTE
public static final int VC_QUOTE- See Also:
-
VC_ENTER
public static final int VC_ENTER- See Also:
-
VC_COMMA
public static final int VC_COMMA- See Also:
-
VC_PERIOD
public static final int VC_PERIOD- See Also:
-
VC_SLASH
public static final int VC_SLASH- See Also:
-
VC_SPACE
public static final int VC_SPACE- See Also:
-
VC_PRINTSCREEN
public static final int VC_PRINTSCREEN- See Also:
-
VC_SCROLL_LOCK
public static final int VC_SCROLL_LOCK- See Also:
-
VC_PAUSE
public static final int VC_PAUSE- See Also:
-
VC_INSERT
public static final int VC_INSERTEdit Key Zone- See Also:
-
VC_DELETE
public static final int VC_DELETE- See Also:
-
VC_HOME
public static final int VC_HOME- See Also:
-
VC_END
public static final int VC_END- See Also:
-
VC_PAGE_UP
public static final int VC_PAGE_UP- See Also:
-
VC_PAGE_DOWN
public static final int VC_PAGE_DOWN- See Also:
-
VC_UP
public static final int VC_UPBegin Cursor Key Zone- See Also:
-
VC_LEFT
public static final int VC_LEFT- See Also:
-
VC_CLEAR
public static final int VC_CLEAR- See Also:
-
VC_RIGHT
public static final int VC_RIGHT- See Also:
-
VC_DOWN
public static final int VC_DOWN- See Also:
-
VC_NUM_LOCK
public static final int VC_NUM_LOCKBegin Numeric Zone- See Also:
-
VC_SEPARATOR
public static final int VC_SEPARATOR- See Also:
-
VC_SHIFT
public static final int VC_SHIFTModifier and Control Keys- See Also:
-
VC_CONTROL
public static final int VC_CONTROL- See Also:
-
VC_ALT
public static final int VC_ALT- See Also:
-
VC_META
public static final int VC_META- See Also:
-
VC_CONTEXT_MENU
public static final int VC_CONTEXT_MENU- See Also:
-
VC_POWER
public static final int VC_POWERMedia and Extra Keys- See Also:
-
VC_SLEEP
public static final int VC_SLEEP- See Also:
-
VC_WAKE
public static final int VC_WAKE- See Also:
-
VC_MEDIA_PLAY
public static final int VC_MEDIA_PLAY- See Also:
-
VC_MEDIA_STOP
public static final int VC_MEDIA_STOP- See Also:
-
VC_MEDIA_PREVIOUS
public static final int VC_MEDIA_PREVIOUS- See Also:
-
VC_MEDIA_NEXT
public static final int VC_MEDIA_NEXT- See Also:
-
VC_MEDIA_SELECT
public static final int VC_MEDIA_SELECT- See Also:
-
VC_MEDIA_EJECT
public static final int VC_MEDIA_EJECT- See Also:
-
VC_VOLUME_MUTE
public static final int VC_VOLUME_MUTE- See Also:
-
VC_VOLUME_UP
public static final int VC_VOLUME_UP- See Also:
-
VC_VOLUME_DOWN
public static final int VC_VOLUME_DOWN- See Also:
-
VC_APP_MAIL
public static final int VC_APP_MAIL- See Also:
-
VC_APP_CALCULATOR
public static final int VC_APP_CALCULATOR- See Also:
-
VC_APP_MUSIC
public static final int VC_APP_MUSIC- See Also:
-
VC_APP_PICTURES
public static final int VC_APP_PICTURES- See Also:
-
VC_BROWSER_SEARCH
public static final int VC_BROWSER_SEARCH- See Also:
-
VC_BROWSER_HOME
public static final int VC_BROWSER_HOME- See Also:
-
VC_BROWSER_BACK
public static final int VC_BROWSER_BACK- See Also:
-
VC_BROWSER_FORWARD
public static final int VC_BROWSER_FORWARD- See Also:
-
VC_BROWSER_STOP
public static final int VC_BROWSER_STOP- See Also:
-
VC_BROWSER_REFRESH
public static final int VC_BROWSER_REFRESH- See Also:
-
VC_BROWSER_FAVORITES
public static final int VC_BROWSER_FAVORITES- See Also:
-
VC_KATAKANA
public static final int VC_KATAKANAJapanese Language Keys- See Also:
-
VC_UNDERSCORE
public static final int VC_UNDERSCORE- See Also:
-
VC_FURIGANA
public static final int VC_FURIGANA- See Also:
-
VC_KANJI
public static final int VC_KANJI- See Also:
-
VC_HIRAGANA
public static final int VC_HIRAGANA- See Also:
-
VC_YEN
public static final int VC_YEN- See Also:
-
VC_SUN_HELP
public static final int VC_SUN_HELPSun keyboards- See Also:
-
VC_SUN_STOP
public static final int VC_SUN_STOP- See Also:
-
VC_SUN_PROPS
public static final int VC_SUN_PROPS- See Also:
-
VC_SUN_FRONT
public static final int VC_SUN_FRONT- See Also:
-
VC_SUN_OPEN
public static final int VC_SUN_OPEN- See Also:
-
VC_SUN_FIND
public static final int VC_SUN_FIND- See Also:
-
VC_SUN_AGAIN
public static final int VC_SUN_AGAIN- See Also:
-
VC_SUN_UNDO
public static final int VC_SUN_UNDO- See Also:
-
VC_SUN_COPY
public static final int VC_SUN_COPY- See Also:
-
VC_SUN_INSERT
public static final int VC_SUN_INSERT- See Also:
-
VC_SUN_CUT
public static final int VC_SUN_CUT- See Also:
-
VC_UNDEFINED
public static final int VC_UNDEFINEDThis value is used to indicate that the keyCode is unknown.- See Also:
-
CHAR_UNDEFINED
public static final char CHAR_UNDEFINEDThis is used to indicate that the keyChar is undefined.- See Also:
-
-
Constructor Details
-
NativeKeyEvent
public NativeKeyEvent(int id, int modifiers, int rawCode, int keyCode, char keyChar, int keyLocation) Instantiates a new native key event.Note that passing in an invalid ID results in unspecified behavior.
- Parameters:
id- an integer that identifies the native event type.modifiers- the modifier mask for the native event.NativeInputEvent_MASK modifiers should be used as they are not compatible with AWT'sInputEvent_DOWN_MASK or the older _MASK modifiers.rawCode- the hardware code associated with the native key in this event.keyCode- the virtual key code generated by this event, or VC_UNDEFINED (for a key-typed event)keyChar- the Unicode character generated by this event, or CHAR_UNDEFINED (for key-pressed and key-released events which do not map to a valid Unicode character).keyLocation- the location ID of the key generating this event.- Since:
- 1.1
-
NativeKeyEvent
public NativeKeyEvent(int id, int modifiers, int rawCode, int keyCode, char keyChar) Instantiates a new native key event.Note that passing in an invalid ID results in unspecified behavior.
- Parameters:
id- an integer that identifies the native event type.modifiers- the modifier mask for the native event.NativeInputEvent_MASK modifiers should be used as they are not compatible with AWT'sInputEvent_DOWN_MASK or the older _MASK modifiers.rawCode- the hardware code associated with the native key in this event.keyCode- the virtual key code generated by this event, or VC_UNDEFINED (for a key-typed event)keyChar- the Unicode character generated by this event, or CHAR_UNDEFINED (for key-pressed and key-released events which do not map to a valid Unicode character).- Since:
- 1.1
-
-
Method Details
-
getRawCode
public int getRawCode()Returns the native code associated with the native key in this event. This is an arbitrary number between 0 and 255 (inclusive) used by the operating system to represent a physical key on the keyboard. This code does not necessarily represent the native key's scan code or ASCII representation. To maintain platform independence, you should not rely on the consistency of this value from platform to platform.- Returns:
- the native key code for this event.
-
setRawCode
public void setRawCode(int rawCode) Set the rawCode value in this event. For more information on what this value represents, please seegetRawCode().- Parameters:
rawCode- the native key code for this event.
-
getKeyCode
public int getKeyCode()Returns the keyCode associated with this event. Note, this method will always returnVC_UNDEFINEDfor theNATIVE_KEY_TYPEDevent types.- Returns:
- the native virtual key code.
-
setKeyCode
public void setKeyCode(int keyCode) Set the keyCode value in this event.- Parameters:
keyCode- the native virtual key code.
-
getKeyChar
public char getKeyChar()Returns the native Unicode character associated with this event. Note, this method will always returnCHAR_UNDEFINEDforNATIVE_KEY_PRESSEDandNATIVE_KEY_RELEASEDevent types.- Returns:
- the Unicode character defined for this key event. If no valid Unicode character
exists for this key event,
CHAR_UNDEFINEDis returned.
-
setKeyChar
public void setKeyChar(char keyChar) Set the keyChar value in this event. For example, theNATIVE_KEY_TYPEDevent for Shift + "a" returns the Unicode value 'A'.- Parameters:
keyChar- the keyboard character associated with this event.
-
getKeyLocation
public int getKeyLocation()Returns the location of the virtual key for this event.- Returns:
- the location of the virtual key that was pressed or released.
-
getKeyText
Returns a String describing the keyCode, such as "HOME", "F1" or "A". These strings can be localized by changing the awt.properties file.- Parameters:
keyCode- the native virtual key code generated by this event- Returns:
- a string containing a text description for a physical key, identified by its keyCode.
-
isActionKey
public boolean isActionKey()Returns whether the key in this event is an "action" key. Typically, an action key does not fire a Unicode character and is not a modifier key.- Returns:
trueif the key is an "action" key,falseotherwise.- Since:
- 1.1
-
paramString
Returns a parameter string identifying this event. This method is useful for event logging and debugging.- Overrides:
paramStringin classNativeInputEvent- Returns:
- a string identifying the event and its attributes.
-