Package org.lwjgl.input
Class Keyboard
- java.lang.Object
-
- org.lwjgl.input.Keyboard
-
public class Keyboard extends Object
A raw Keyboard interface. This can be used to poll the current state of the keys, or read all the keyboard presses / releases since the last read.- Version:
- $Revision$ $Id$
- Author:
- cix_foo
, elias_naur , Brian Matzon
-
-
Field Summary
Fields Modifier and Type Field Description static intCHAR_NONEThe special character meaning that no character was translated for the event.static intEVENT_SIZEInternal use - event size in bytesstatic intKEY_0static intKEY_1static intKEY_2static intKEY_3static intKEY_4static intKEY_5static intKEY_6static intKEY_7static intKEY_8static intKEY_9static intKEY_Astatic intKEY_ADDstatic intKEY_APOSTROPHEstatic intKEY_APPSstatic intKEY_ATstatic intKEY_AXstatic intKEY_Bstatic intKEY_BACKstatic intKEY_BACKSLASHstatic intKEY_Cstatic intKEY_CAPITALstatic intKEY_CIRCUMFLEXstatic intKEY_CLEARstatic intKEY_COLONstatic intKEY_COMMAstatic intKEY_CONVERTstatic intKEY_Dstatic intKEY_DECIMALstatic intKEY_DELETEstatic intKEY_DIVIDEstatic intKEY_DOWNstatic intKEY_Estatic intKEY_ENDstatic intKEY_EQUALSstatic intKEY_ESCAPEstatic intKEY_Fstatic intKEY_F1static intKEY_F10static intKEY_F11static intKEY_F12static intKEY_F13static intKEY_F14static intKEY_F15static intKEY_F16static intKEY_F17static intKEY_F18static intKEY_F19static intKEY_F2static intKEY_F3static intKEY_F4static intKEY_F5static intKEY_F6static intKEY_F7static intKEY_F8static intKEY_F9static intKEY_FUNCTIONstatic intKEY_Gstatic intKEY_GRAVEstatic intKEY_Hstatic intKEY_HOMEstatic intKEY_Istatic intKEY_INSERTstatic intKEY_Jstatic intKEY_Kstatic intKEY_KANAstatic intKEY_KANJIstatic intKEY_Lstatic intKEY_LBRACKETstatic intKEY_LCONTROLstatic intKEY_LEFTstatic intKEY_LMENUstatic intKEY_LMETAstatic intKEY_LSHIFTstatic intKEY_LWINDeprecated.Use KEY_LMETA insteadstatic intKEY_Mstatic intKEY_MINUSstatic intKEY_MULTIPLYstatic intKEY_Nstatic intKEY_NEXTstatic intKEY_NOCONVERTstatic intKEY_NONEThe special keycode meaning that only the translated character is valid.static intKEY_NUMLOCKstatic intKEY_NUMPAD0static intKEY_NUMPAD1static intKEY_NUMPAD2static intKEY_NUMPAD3static intKEY_NUMPAD4static intKEY_NUMPAD5static intKEY_NUMPAD6static intKEY_NUMPAD7static intKEY_NUMPAD8static intKEY_NUMPAD9static intKEY_NUMPADCOMMAstatic intKEY_NUMPADENTERstatic intKEY_NUMPADEQUALSstatic intKEY_Ostatic intKEY_Pstatic intKEY_PAUSEstatic intKEY_PERIODstatic intKEY_POWERstatic intKEY_PRIORstatic intKEY_Qstatic intKEY_Rstatic intKEY_RBRACKETstatic intKEY_RCONTROLstatic intKEY_RETURNstatic intKEY_RIGHTstatic intKEY_RMENUstatic intKEY_RMETAstatic intKEY_RSHIFTstatic intKEY_RWINDeprecated.Use KEY_RMETA insteadstatic intKEY_Sstatic intKEY_SCROLLstatic intKEY_SECTIONstatic intKEY_SEMICOLONstatic intKEY_SLASHstatic intKEY_SLEEPstatic intKEY_SPACEstatic intKEY_STOPstatic intKEY_SUBTRACTstatic intKEY_SYSRQstatic intKEY_Tstatic intKEY_TABstatic intKEY_Ustatic intKEY_UNDERLINEstatic intKEY_UNLABELEDstatic intKEY_UPstatic intKEY_Vstatic intKEY_Wstatic intKEY_Xstatic intKEY_Ystatic intKEY_YENstatic intKEY_Zstatic intKEYBOARD_SIZE
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static booleanareRepeatEventsEnabled()Check whether repeat events are currently reported or not.static voidcreate()"Create" the keyboard.static voiddestroy()"Destroy" the keyboardstatic voidenableRepeatEvents(boolean enable)Controls whether repeat events are reported or not.static chargetEventCharacter()static intgetEventKey()Please note that the key code returned is NOT valid against the current keyboard layout.static booleangetEventKeyState()Gets the state of the key that generated the current eventstatic longgetEventNanoseconds()Gets the time in nanoseconds of the current event.static intgetKeyCount()static intgetKeyIndex(String keyName)Get's a key's index.static StringgetKeyName(int key)Gets a key's namestatic intgetNumKeyboardEvents()Gets the number of keyboard events waiting after doing a buffer enabled poll().static booleanisCreated()static booleanisKeyDown(int key)Checks to see if a key is down.static booleanisRepeatEvent()static booleannext()Gets the next keyboard event.static voidpoll()Polls the keyboard for its current state.
-
-
-
Field Detail
-
EVENT_SIZE
public static final int EVENT_SIZE
Internal use - event size in bytes- See Also:
- Constant Field Values
-
CHAR_NONE
public static final int CHAR_NONE
The special character meaning that no character was translated for the event.- See Also:
- Constant Field Values
-
KEY_NONE
public static final int KEY_NONE
The special keycode meaning that only the translated character is valid.- See Also:
- Constant Field Values
-
KEY_ESCAPE
public static final int KEY_ESCAPE
- See Also:
- Constant Field Values
-
KEY_1
public static final int KEY_1
- See Also:
- Constant Field Values
-
KEY_2
public static final int KEY_2
- See Also:
- Constant Field Values
-
KEY_3
public static final int KEY_3
- See Also:
- Constant Field Values
-
KEY_4
public static final int KEY_4
- See Also:
- Constant Field Values
-
KEY_5
public static final int KEY_5
- See Also:
- Constant Field Values
-
KEY_6
public static final int KEY_6
- See Also:
- Constant Field Values
-
KEY_7
public static final int KEY_7
- See Also:
- Constant Field Values
-
KEY_8
public static final int KEY_8
- See Also:
- Constant Field Values
-
KEY_9
public static final int KEY_9
- See Also:
- Constant Field Values
-
KEY_0
public static final int KEY_0
- See Also:
- Constant Field Values
-
KEY_MINUS
public static final int KEY_MINUS
- See Also:
- Constant Field Values
-
KEY_EQUALS
public static final int KEY_EQUALS
- See Also:
- Constant Field Values
-
KEY_BACK
public static final int KEY_BACK
- See Also:
- Constant Field Values
-
KEY_TAB
public static final int KEY_TAB
- See Also:
- Constant Field Values
-
KEY_Q
public static final int KEY_Q
- See Also:
- Constant Field Values
-
KEY_W
public static final int KEY_W
- See Also:
- Constant Field Values
-
KEY_E
public static final int KEY_E
- See Also:
- Constant Field Values
-
KEY_R
public static final int KEY_R
- See Also:
- Constant Field Values
-
KEY_T
public static final int KEY_T
- See Also:
- Constant Field Values
-
KEY_Y
public static final int KEY_Y
- See Also:
- Constant Field Values
-
KEY_U
public static final int KEY_U
- See Also:
- Constant Field Values
-
KEY_I
public static final int KEY_I
- See Also:
- Constant Field Values
-
KEY_O
public static final int KEY_O
- See Also:
- Constant Field Values
-
KEY_P
public static final int KEY_P
- See Also:
- Constant Field Values
-
KEY_LBRACKET
public static final int KEY_LBRACKET
- See Also:
- Constant Field Values
-
KEY_RBRACKET
public static final int KEY_RBRACKET
- See Also:
- Constant Field Values
-
KEY_RETURN
public static final int KEY_RETURN
- See Also:
- Constant Field Values
-
KEY_LCONTROL
public static final int KEY_LCONTROL
- See Also:
- Constant Field Values
-
KEY_A
public static final int KEY_A
- See Also:
- Constant Field Values
-
KEY_S
public static final int KEY_S
- See Also:
- Constant Field Values
-
KEY_D
public static final int KEY_D
- See Also:
- Constant Field Values
-
KEY_F
public static final int KEY_F
- See Also:
- Constant Field Values
-
KEY_G
public static final int KEY_G
- See Also:
- Constant Field Values
-
KEY_H
public static final int KEY_H
- See Also:
- Constant Field Values
-
KEY_J
public static final int KEY_J
- See Also:
- Constant Field Values
-
KEY_K
public static final int KEY_K
- See Also:
- Constant Field Values
-
KEY_L
public static final int KEY_L
- See Also:
- Constant Field Values
-
KEY_SEMICOLON
public static final int KEY_SEMICOLON
- See Also:
- Constant Field Values
-
KEY_APOSTROPHE
public static final int KEY_APOSTROPHE
- See Also:
- Constant Field Values
-
KEY_GRAVE
public static final int KEY_GRAVE
- See Also:
- Constant Field Values
-
KEY_LSHIFT
public static final int KEY_LSHIFT
- See Also:
- Constant Field Values
-
KEY_BACKSLASH
public static final int KEY_BACKSLASH
- See Also:
- Constant Field Values
-
KEY_Z
public static final int KEY_Z
- See Also:
- Constant Field Values
-
KEY_X
public static final int KEY_X
- See Also:
- Constant Field Values
-
KEY_C
public static final int KEY_C
- See Also:
- Constant Field Values
-
KEY_V
public static final int KEY_V
- See Also:
- Constant Field Values
-
KEY_B
public static final int KEY_B
- See Also:
- Constant Field Values
-
KEY_N
public static final int KEY_N
- See Also:
- Constant Field Values
-
KEY_M
public static final int KEY_M
- See Also:
- Constant Field Values
-
KEY_COMMA
public static final int KEY_COMMA
- See Also:
- Constant Field Values
-
KEY_PERIOD
public static final int KEY_PERIOD
- See Also:
- Constant Field Values
-
KEY_SLASH
public static final int KEY_SLASH
- See Also:
- Constant Field Values
-
KEY_RSHIFT
public static final int KEY_RSHIFT
- See Also:
- Constant Field Values
-
KEY_MULTIPLY
public static final int KEY_MULTIPLY
- See Also:
- Constant Field Values
-
KEY_LMENU
public static final int KEY_LMENU
- See Also:
- Constant Field Values
-
KEY_SPACE
public static final int KEY_SPACE
- See Also:
- Constant Field Values
-
KEY_CAPITAL
public static final int KEY_CAPITAL
- See Also:
- Constant Field Values
-
KEY_F1
public static final int KEY_F1
- See Also:
- Constant Field Values
-
KEY_F2
public static final int KEY_F2
- See Also:
- Constant Field Values
-
KEY_F3
public static final int KEY_F3
- See Also:
- Constant Field Values
-
KEY_F4
public static final int KEY_F4
- See Also:
- Constant Field Values
-
KEY_F5
public static final int KEY_F5
- See Also:
- Constant Field Values
-
KEY_F6
public static final int KEY_F6
- See Also:
- Constant Field Values
-
KEY_F7
public static final int KEY_F7
- See Also:
- Constant Field Values
-
KEY_F8
public static final int KEY_F8
- See Also:
- Constant Field Values
-
KEY_F9
public static final int KEY_F9
- See Also:
- Constant Field Values
-
KEY_F10
public static final int KEY_F10
- See Also:
- Constant Field Values
-
KEY_NUMLOCK
public static final int KEY_NUMLOCK
- See Also:
- Constant Field Values
-
KEY_SCROLL
public static final int KEY_SCROLL
- See Also:
- Constant Field Values
-
KEY_NUMPAD7
public static final int KEY_NUMPAD7
- See Also:
- Constant Field Values
-
KEY_NUMPAD8
public static final int KEY_NUMPAD8
- See Also:
- Constant Field Values
-
KEY_NUMPAD9
public static final int KEY_NUMPAD9
- See Also:
- Constant Field Values
-
KEY_SUBTRACT
public static final int KEY_SUBTRACT
- See Also:
- Constant Field Values
-
KEY_NUMPAD4
public static final int KEY_NUMPAD4
- See Also:
- Constant Field Values
-
KEY_NUMPAD5
public static final int KEY_NUMPAD5
- See Also:
- Constant Field Values
-
KEY_NUMPAD6
public static final int KEY_NUMPAD6
- See Also:
- Constant Field Values
-
KEY_ADD
public static final int KEY_ADD
- See Also:
- Constant Field Values
-
KEY_NUMPAD1
public static final int KEY_NUMPAD1
- See Also:
- Constant Field Values
-
KEY_NUMPAD2
public static final int KEY_NUMPAD2
- See Also:
- Constant Field Values
-
KEY_NUMPAD3
public static final int KEY_NUMPAD3
- See Also:
- Constant Field Values
-
KEY_NUMPAD0
public static final int KEY_NUMPAD0
- See Also:
- Constant Field Values
-
KEY_DECIMAL
public static final int KEY_DECIMAL
- See Also:
- Constant Field Values
-
KEY_F11
public static final int KEY_F11
- See Also:
- Constant Field Values
-
KEY_F12
public static final int KEY_F12
- See Also:
- Constant Field Values
-
KEY_F13
public static final int KEY_F13
- See Also:
- Constant Field Values
-
KEY_F14
public static final int KEY_F14
- See Also:
- Constant Field Values
-
KEY_F15
public static final int KEY_F15
- See Also:
- Constant Field Values
-
KEY_F16
public static final int KEY_F16
- See Also:
- Constant Field Values
-
KEY_F17
public static final int KEY_F17
- See Also:
- Constant Field Values
-
KEY_F18
public static final int KEY_F18
- See Also:
- Constant Field Values
-
KEY_KANA
public static final int KEY_KANA
- See Also:
- Constant Field Values
-
KEY_F19
public static final int KEY_F19
- See Also:
- Constant Field Values
-
KEY_CONVERT
public static final int KEY_CONVERT
- See Also:
- Constant Field Values
-
KEY_NOCONVERT
public static final int KEY_NOCONVERT
- See Also:
- Constant Field Values
-
KEY_YEN
public static final int KEY_YEN
- See Also:
- Constant Field Values
-
KEY_NUMPADEQUALS
public static final int KEY_NUMPADEQUALS
- See Also:
- Constant Field Values
-
KEY_CIRCUMFLEX
public static final int KEY_CIRCUMFLEX
- See Also:
- Constant Field Values
-
KEY_AT
public static final int KEY_AT
- See Also:
- Constant Field Values
-
KEY_COLON
public static final int KEY_COLON
- See Also:
- Constant Field Values
-
KEY_UNDERLINE
public static final int KEY_UNDERLINE
- See Also:
- Constant Field Values
-
KEY_KANJI
public static final int KEY_KANJI
- See Also:
- Constant Field Values
-
KEY_STOP
public static final int KEY_STOP
- See Also:
- Constant Field Values
-
KEY_AX
public static final int KEY_AX
- See Also:
- Constant Field Values
-
KEY_UNLABELED
public static final int KEY_UNLABELED
- See Also:
- Constant Field Values
-
KEY_NUMPADENTER
public static final int KEY_NUMPADENTER
- See Also:
- Constant Field Values
-
KEY_RCONTROL
public static final int KEY_RCONTROL
- See Also:
- Constant Field Values
-
KEY_SECTION
public static final int KEY_SECTION
- See Also:
- Constant Field Values
-
KEY_NUMPADCOMMA
public static final int KEY_NUMPADCOMMA
- See Also:
- Constant Field Values
-
KEY_DIVIDE
public static final int KEY_DIVIDE
- See Also:
- Constant Field Values
-
KEY_SYSRQ
public static final int KEY_SYSRQ
- See Also:
- Constant Field Values
-
KEY_RMENU
public static final int KEY_RMENU
- See Also:
- Constant Field Values
-
KEY_FUNCTION
public static final int KEY_FUNCTION
- See Also:
- Constant Field Values
-
KEY_PAUSE
public static final int KEY_PAUSE
- See Also:
- Constant Field Values
-
KEY_HOME
public static final int KEY_HOME
- See Also:
- Constant Field Values
-
KEY_UP
public static final int KEY_UP
- See Also:
- Constant Field Values
-
KEY_PRIOR
public static final int KEY_PRIOR
- See Also:
- Constant Field Values
-
KEY_LEFT
public static final int KEY_LEFT
- See Also:
- Constant Field Values
-
KEY_RIGHT
public static final int KEY_RIGHT
- See Also:
- Constant Field Values
-
KEY_END
public static final int KEY_END
- See Also:
- Constant Field Values
-
KEY_DOWN
public static final int KEY_DOWN
- See Also:
- Constant Field Values
-
KEY_NEXT
public static final int KEY_NEXT
- See Also:
- Constant Field Values
-
KEY_INSERT
public static final int KEY_INSERT
- See Also:
- Constant Field Values
-
KEY_DELETE
public static final int KEY_DELETE
- See Also:
- Constant Field Values
-
KEY_CLEAR
public static final int KEY_CLEAR
- See Also:
- Constant Field Values
-
KEY_LMETA
public static final int KEY_LMETA
- See Also:
- Constant Field Values
-
KEY_LWIN
public static final int KEY_LWIN
Deprecated.Use KEY_LMETA insteadThe left windows key, mapped to KEY_LMETA- See Also:
- Constant Field Values
-
KEY_RMETA
public static final int KEY_RMETA
- See Also:
- Constant Field Values
-
KEY_RWIN
public static final int KEY_RWIN
Deprecated.Use KEY_RMETA insteadThe right windows key, mapped to KEY_RMETA- See Also:
- Constant Field Values
-
KEY_APPS
public static final int KEY_APPS
- See Also:
- Constant Field Values
-
KEY_POWER
public static final int KEY_POWER
- See Also:
- Constant Field Values
-
KEY_SLEEP
public static final int KEY_SLEEP
- See Also:
- Constant Field Values
-
KEYBOARD_SIZE
public static final int KEYBOARD_SIZE
- See Also:
- Constant Field Values
-
-
Method Detail
-
create
public static void create() throws LWJGLException"Create" the keyboard. The display must first have been created. The reason for this is so the keyboard has a window to "focus" in.- Throws:
LWJGLException- if the keyboard could not be created for any reason
-
isCreated
public static boolean isCreated()
- Returns:
- true if the keyboard has been created
-
destroy
public static void destroy()
"Destroy" the keyboard
-
poll
public static void poll()
Polls the keyboard for its current state. Access the polled values using theisKeyDownmethod. By using this method, it is possible to "miss" keyboard keys if you don't poll fast enough. To use buffered values, you have to callnextfor each event you want to read. You can query which key caused the event by usinggetEventKey. To get the state of that key, for that event, usegetEventKeyState- finally usegetEventCharacterto get the character for that event. NOTE: This method does not query the operating system for new events. To do that, Display.processMessages() (or Display.update()) must be called first.
-
isKeyDown
public static boolean isKeyDown(int key)
Checks to see if a key is down.- Parameters:
key- Keycode to check- Returns:
- true if the key is down according to the last poll()
-
getKeyName
public static String getKeyName(int key)
Gets a key's name- Parameters:
key- The key- Returns:
- a String with the key's human readable name in it or null if the key is unnamed
-
getKeyIndex
public static int getKeyIndex(String keyName)
Get's a key's index. If the key is unrecognised then KEY_NONE is returned.- Parameters:
keyName- The key name
-
getNumKeyboardEvents
public static int getNumKeyboardEvents()
Gets the number of keyboard events waiting after doing a buffer enabled poll().- Returns:
- the number of keyboard events
-
next
public static boolean next()
Gets the next keyboard event. You can query which key caused the event by usinggetEventKey. To get the state of that key, for that event, usegetEventKeyState- finally usegetEventCharacterto get the character for that event.- Returns:
- true if a keyboard event was read, false otherwise
- See Also:
getEventKey(),getEventKeyState(),getEventCharacter()
-
enableRepeatEvents
public static void enableRepeatEvents(boolean enable)
Controls whether repeat events are reported or not. If repeat events are enabled, key down events are reported when a key is pressed and held for a OS dependent amount of time. To distinguish a repeat event from a normal event, use isRepeatEvent().- See Also:
getEventKey()
-
areRepeatEventsEnabled
public static boolean areRepeatEventsEnabled()
Check whether repeat events are currently reported or not.- Returns:
- true is repeat events are reported, false if not.
- See Also:
getEventKey()
-
getKeyCount
public static int getKeyCount()
- Returns:
- Number of keys on this keyboard
-
getEventCharacter
public static char getEventCharacter()
- Returns:
- The character from the current event
-
getEventKey
public static int getEventKey()
Please note that the key code returned is NOT valid against the current keyboard layout. To get the actual character pressed call getEventCharacter- Returns:
- The key from the current event
-
getEventKeyState
public static boolean getEventKeyState()
Gets the state of the key that generated the current event- Returns:
- True if key was down, or false if released
-
getEventNanoseconds
public static long getEventNanoseconds()
Gets the time in nanoseconds of the current event. Only useful for relative comparisons with other Keyboard events, as the absolute time has no defined origin.- Returns:
- The time in nanoseconds of the current event
-
isRepeatEvent
public static boolean isRepeatEvent()
- Returns:
- true if the current event is a repeat event, false if the current event is not a repeat even or if repeat events are disabled.
- See Also:
enableRepeatEvents(boolean)
-
-