com.jme.input
Class KeyInput

java.lang.Object
  extended by com.jme.input.Input
      extended by com.jme.input.KeyInput
Direct Known Subclasses:
AWTKeyInput, DummyKeyInput, LWJGLKeyInput, SWTKeyInput

public abstract class KeyInput
extends Input

KeyInput provides an interface for dealing with keyboard input. There are public contstants for each key of the keyboard, which correspond to the LWJGL key bindings. This may require conversion by other subclasses for specific APIs.
The status of spcific keys can be queried via the isKeyDown(int) method. For each key that is pressed or released an event is generated which can be received by a KeyInputListener, these are subsribed via addListener(KeyInputListener). Handling of events is done inside the update() method.

Version:
$Id: KeyInput.java 4336 2009-05-03 20:57:01Z christoph.luder $
Author:
Mark Powell

Field Summary
static java.lang.String INPUT_AWT
           
static java.lang.String INPUT_LWJGL
           
static int KEY_0
          0 key.
static int KEY_1
          1 key.
static int KEY_2
          2 key.
static int KEY_3
          3 key.
static int KEY_4
          4 key.
static int KEY_5
          5 key.
static int KEY_6
          6 key.
static int KEY_7
          7 key.
static int KEY_8
          8 key.
static int KEY_9
          9 key.
static int KEY_A
          a key.
static int KEY_ADD
          + key (num pad).
static int KEY_APOSTROPHE
          ' key.
static int KEY_APPS
           
static int KEY_AT
          @ key (NEC PC98).
static int KEY_AX
          ax key (Japanese).
static int KEY_B
          b key.
static int KEY_BACK
          back key.
static int KEY_BACKSLASH
          \ key.
static int KEY_C
          c key.
static int KEY_CAPITAL
          caps lock key.
static int KEY_CIRCUMFLEX
          circum flex key (Japanese).
static int KEY_COLON
          : key (NEC PC98)
static int KEY_COMMA
          , key.
static int KEY_CONVERT
          convert key (Japanese).
static int KEY_D
          d key.
static int KEY_DECIMAL
          .
static int KEY_DELETE
          delete key.
static int KEY_DIVIDE
          / key (num pad).
static int KEY_DOWN
          down arrow key.
static int KEY_E
          e key.
static int KEY_END
          end key.
static int KEY_EQUALS
          = key.
static int KEY_ESCAPE
          escape key.
static int KEY_F
          f key.
static int KEY_F1
          F1 key.
static int KEY_F10
          F10 key.
static int KEY_F11
          F11 key.
static int KEY_F12
          F12 key.
static int KEY_F13
          F13 key.
static int KEY_F14
          F14 key.
static int KEY_F15
          F15 key.
static int KEY_F2
          F2 key.
static int KEY_F3
          F3 key.
static int KEY_F4
          F4 key.
static int KEY_F5
          F5 key.
static int KEY_F6
          F6 key.
static int KEY_F7
          F7 key.
static int KEY_F8
          F8 key.
static int KEY_F9
          F9 key.
static int KEY_G
          g key.
static int KEY_GRAVE
          ` key.
static int KEY_H
          h key.
static int KEY_HOME
          home key.
static int KEY_I
          i key.
static int KEY_INSERT
          insert key.
static int KEY_J
          j key.
static int KEY_K
          k key.
static int KEY_KANA
          kana key (Japanese).
static int KEY_KANJI
          kanji key (Japanese).
static int KEY_L
          l key.
static int KEY_LBRACKET
          [ key.
static int KEY_LCONTROL
          left control key.
static int KEY_LEFT
          left arrow key.
static int KEY_LMENU
          left alt key.
static int KEY_LMETA
           
static int KEY_LSHIFT
          left shift key.
static int KEY_LWIN
          The left windows key, mapped to KEY_LMETA
static int KEY_M
          m key.
static int KEY_MINUS
          - key.
static int KEY_MULTIPLY
          * key (on keypad).
static int KEY_N
          n key.
static int KEY_NEXT
          PgDn key.
static int KEY_NOCONVERT
          noconvert key (Japanese).
static int KEY_NUMLOCK
          NumLK key.
static int KEY_NUMPAD0
          0 key (num pad).
static int KEY_NUMPAD1
          1 key (num pad).
static int KEY_NUMPAD2
          2 key (num pad).
static int KEY_NUMPAD3
          3 key (num pad).
static int KEY_NUMPAD4
          4 key (num pad).
static int KEY_NUMPAD5
          5 key (num pad).
static int KEY_NUMPAD6
          6 key (num pad).
static int KEY_NUMPAD7
          7 key (num pad).
static int KEY_NUMPAD8
          8 key (num pad).
static int KEY_NUMPAD9
          9 key (num pad).
static int KEY_NUMPADCOMMA
          , key on num pad (NEC PC98).
static int KEY_NUMPADENTER
          Enter key (num pad).
static int KEY_NUMPADEQUALS
          = on num pad (NEC PC98).
static int KEY_O
          o key.
static int KEY_P
          p key.
static int KEY_PAUSE
          pause key.
static int KEY_PERIOD
          .
static int KEY_PGDN
          PgDn key.
static int KEY_PGUP
          PgUp key.
static int KEY_POWER
          power key.
static int KEY_PRIOR
          PgUp key.
static int KEY_Q
          q key.
static int KEY_R
          r key.
static int KEY_RBRACKET
          ] key.
static int KEY_RCONTROL
          right control key.
static int KEY_RETURN
          enter (main keyboard) key.
static int KEY_RIGHT
          right arrow key.
static int KEY_RMENU
          right alt key.
static int KEY_RMETA
           
static int KEY_RSHIFT
          right shift key.
static int KEY_RWIN
          The right windows key, mapped to KEY_RMETA
static int KEY_S
          s key.
static int KEY_SCROLL
          Scroll lock key.
static int KEY_SEMICOLON
          ; key.
static int KEY_SLASH
          / key (main keyboard).
static int KEY_SLEEP
          sleep key.
static int KEY_SPACE
          space key.
static int KEY_STOP
          stop key (NEC PC98).
static int KEY_SUBTRACT
          - key (num pad).
static int KEY_SYSRQ
          SysRq key.
static int KEY_T
          t key.
static int KEY_TAB
          tab key.
static int KEY_U
          u key.
static int KEY_UNDERLINE
          _ key (NEC PC98).
static int KEY_UNLABELED
          (J3100).
static int KEY_UP
          up arrow key.
static int KEY_V
          v key.
static int KEY_W
          w key.
static int KEY_X
          x key.
static int KEY_Y
          y key.
static int KEY_YEN
          yen key (Japanese).
static int KEY_Z
          z key.
protected  java.util.List<KeyInputListener> listeners
          list of event listeners.
 
Constructor Summary
KeyInput()
           
 
Method Summary
 void addListener(KeyInputListener listener)
          Subscribe a listener to receive mouse events.
abstract  void clear()
           
abstract  void clearKey(int keycode)
           
 boolean containsListener(KeyInputListener listener)
          Check if a listener is already added to this KeyInput
protected abstract  void destroy()
          destroy frees the keyboard for use by other applications.
static void destroyIfInitalized()
          Destroy the input if it was initialized.
static KeyInput get()
           
abstract  int getKeyIndex(java.lang.String name)
          The reverse of getKeyName, returns the value of the key given the name
abstract  java.lang.String getKeyName(int key)
          getKeyName returns the string prepresentation of a key code.
 java.util.List<KeyInputListener> getListeners()
          Get all added key listeners
static java.lang.Class<?> getProvider()
          Query current provider for input.
 boolean isControlDown()
           
static boolean isInited()
          isInited returns true if the key class is not setup already (ie.
abstract  boolean isKeyDown(int key)
          isKeyDown returns true if the given key is pressed.
 boolean isShiftDown()
           
 void removeListener(KeyInputListener listener)
          Unsubscribe a listener.
 void removeListeners()
          Remove all listeners and disable event generation.
static void setProvider(java.lang.Class value)
          Change the provider used for keyboard input.
static void setProvider(java.lang.String value)
          Change the provider used for keyboard input.
abstract  void update()
          Updates the current state of the keyboard, holding information about what keys are pressed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

KEY_ESCAPE

public static final int KEY_ESCAPE
escape key.

See Also:
Constant Field Values

KEY_1

public static final int KEY_1
1 key.

See Also:
Constant Field Values

KEY_2

public static final int KEY_2
2 key.

See Also:
Constant Field Values

KEY_3

public static final int KEY_3
3 key.

See Also:
Constant Field Values

KEY_4

public static final int KEY_4
4 key.

See Also:
Constant Field Values

KEY_5

public static final int KEY_5
5 key.

See Also:
Constant Field Values

KEY_6

public static final int KEY_6
6 key.

See Also:
Constant Field Values

KEY_7

public static final int KEY_7
7 key.

See Also:
Constant Field Values

KEY_8

public static final int KEY_8
8 key.

See Also:
Constant Field Values

KEY_9

public static final int KEY_9
9 key.

See Also:
Constant Field Values

KEY_0

public static final int KEY_0
0 key.

See Also:
Constant Field Values

KEY_MINUS

public static final int KEY_MINUS
- key.

See Also:
Constant Field Values

KEY_EQUALS

public static final int KEY_EQUALS
= key.

See Also:
Constant Field Values

KEY_BACK

public static final int KEY_BACK
back key.

See Also:
Constant Field Values

KEY_TAB

public static final int KEY_TAB
tab key.

See Also:
Constant Field Values

KEY_Q

public static final int KEY_Q
q key.

See Also:
Constant Field Values

KEY_W

public static final int KEY_W
w key.

See Also:
Constant Field Values

KEY_E

public static final int KEY_E
e key.

See Also:
Constant Field Values

KEY_R

public static final int KEY_R
r key.

See Also:
Constant Field Values

KEY_T

public static final int KEY_T
t key.

See Also:
Constant Field Values

KEY_Y

public static final int KEY_Y
y key.

See Also:
Constant Field Values

KEY_U

public static final int KEY_U
u key.

See Also:
Constant Field Values

KEY_I

public static final int KEY_I
i key.

See Also:
Constant Field Values

KEY_O

public static final int KEY_O
o key.

See Also:
Constant Field Values

KEY_P

public static final int KEY_P
p key.

See Also:
Constant Field Values

KEY_LBRACKET

public static final int KEY_LBRACKET
[ key.

See Also:
Constant Field Values

KEY_RBRACKET

public static final int KEY_RBRACKET
] key.

See Also:
Constant Field Values

KEY_RETURN

public static final int KEY_RETURN
enter (main keyboard) key.

See Also:
Constant Field Values

KEY_LCONTROL

public static final int KEY_LCONTROL
left control key.

See Also:
Constant Field Values

KEY_A

public static final int KEY_A
a key.

See Also:
Constant Field Values

KEY_S

public static final int KEY_S
s key.

See Also:
Constant Field Values

KEY_D

public static final int KEY_D
d key.

See Also:
Constant Field Values

KEY_F

public static final int KEY_F
f key.

See Also:
Constant Field Values

KEY_G

public static final int KEY_G
g key.

See Also:
Constant Field Values

KEY_H

public static final int KEY_H
h key.

See Also:
Constant Field Values

KEY_J

public static final int KEY_J
j key.

See Also:
Constant Field Values

KEY_K

public static final int KEY_K
k key.

See Also:
Constant Field Values

KEY_L

public static final int KEY_L
l key.

See Also:
Constant Field Values

KEY_SEMICOLON

public static final int KEY_SEMICOLON
; key.

See Also:
Constant Field Values

KEY_APOSTROPHE

public static final int KEY_APOSTROPHE
' key.

See Also:
Constant Field Values

KEY_GRAVE

public static final int KEY_GRAVE
` key.

See Also:
Constant Field Values

KEY_LSHIFT

public static final int KEY_LSHIFT
left shift key.

See Also:
Constant Field Values

KEY_BACKSLASH

public static final int KEY_BACKSLASH
\ key.

See Also:
Constant Field Values

KEY_Z

public static final int KEY_Z
z key.

See Also:
Constant Field Values

KEY_X

public static final int KEY_X
x key.

See Also:
Constant Field Values

KEY_C

public static final int KEY_C
c key.

See Also:
Constant Field Values

KEY_V

public static final int KEY_V
v key.

See Also:
Constant Field Values

KEY_B

public static final int KEY_B
b key.

See Also:
Constant Field Values

KEY_N

public static final int KEY_N
n key.

See Also:
Constant Field Values

KEY_M

public static final int KEY_M
m key.

See Also:
Constant Field Values

KEY_COMMA

public static final int KEY_COMMA
, key.

See Also:
Constant Field Values

KEY_PERIOD

public static final int KEY_PERIOD
. key (main keyboard).

See Also:
Constant Field Values

KEY_SLASH

public static final int KEY_SLASH
/ key (main keyboard).

See Also:
Constant Field Values

KEY_RSHIFT

public static final int KEY_RSHIFT
right shift key.

See Also:
Constant Field Values

KEY_MULTIPLY

public static final int KEY_MULTIPLY
* key (on keypad).

See Also:
Constant Field Values

KEY_LMENU

public static final int KEY_LMENU
left alt key.

See Also:
Constant Field Values

KEY_SPACE

public static final int KEY_SPACE
space key.

See Also:
Constant Field Values

KEY_CAPITAL

public static final int KEY_CAPITAL
caps lock key.

See Also:
Constant Field Values

KEY_F1

public static final int KEY_F1
F1 key.

See Also:
Constant Field Values

KEY_F2

public static final int KEY_F2
F2 key.

See Also:
Constant Field Values

KEY_F3

public static final int KEY_F3
F3 key.

See Also:
Constant Field Values

KEY_F4

public static final int KEY_F4
F4 key.

See Also:
Constant Field Values

KEY_F5

public static final int KEY_F5
F5 key.

See Also:
Constant Field Values

KEY_F6

public static final int KEY_F6
F6 key.

See Also:
Constant Field Values

KEY_F7

public static final int KEY_F7
F7 key.

See Also:
Constant Field Values

KEY_F8

public static final int KEY_F8
F8 key.

See Also:
Constant Field Values

KEY_F9

public static final int KEY_F9
F9 key.

See Also:
Constant Field Values

KEY_F10

public static final int KEY_F10
F10 key.

See Also:
Constant Field Values

KEY_NUMLOCK

public static final int KEY_NUMLOCK
NumLK key.

See Also:
Constant Field Values

KEY_SCROLL

public static final int KEY_SCROLL
Scroll lock key.

See Also:
Constant Field Values

KEY_NUMPAD7

public static final int KEY_NUMPAD7
7 key (num pad).

See Also:
Constant Field Values

KEY_NUMPAD8

public static final int KEY_NUMPAD8
8 key (num pad).

See Also:
Constant Field Values

KEY_NUMPAD9

public static final int KEY_NUMPAD9
9 key (num pad).

See Also:
Constant Field Values

KEY_SUBTRACT

public static final int KEY_SUBTRACT
- key (num pad).

See Also:
Constant Field Values

KEY_NUMPAD4

public static final int KEY_NUMPAD4
4 key (num pad).

See Also:
Constant Field Values

KEY_NUMPAD5

public static final int KEY_NUMPAD5
5 key (num pad).

See Also:
Constant Field Values

KEY_NUMPAD6

public static final int KEY_NUMPAD6
6 key (num pad).

See Also:
Constant Field Values

KEY_ADD

public static final int KEY_ADD
+ key (num pad).

See Also:
Constant Field Values

KEY_NUMPAD1

public static final int KEY_NUMPAD1
1 key (num pad).

See Also:
Constant Field Values

KEY_NUMPAD2

public static final int KEY_NUMPAD2
2 key (num pad).

See Also:
Constant Field Values

KEY_NUMPAD3

public static final int KEY_NUMPAD3
3 key (num pad).

See Also:
Constant Field Values

KEY_NUMPAD0

public static final int KEY_NUMPAD0
0 key (num pad).

See Also:
Constant Field Values

KEY_DECIMAL

public static final int KEY_DECIMAL
. key (num pad).

See Also:
Constant Field Values

KEY_F11

public static final int KEY_F11
F11 key.

See Also:
Constant Field Values

KEY_F12

public static final int KEY_F12
F12 key.

See Also:
Constant Field Values

KEY_F13

public static final int KEY_F13
F13 key.

See Also:
Constant Field Values

KEY_F14

public static final int KEY_F14
F14 key.

See Also:
Constant Field Values

KEY_F15

public static final int KEY_F15
F15 key.

See Also:
Constant Field Values

KEY_KANA

public static final int KEY_KANA
kana key (Japanese).

See Also:
Constant Field Values

KEY_CONVERT

public static final int KEY_CONVERT
convert key (Japanese).

See Also:
Constant Field Values

KEY_NOCONVERT

public static final int KEY_NOCONVERT
noconvert key (Japanese).

See Also:
Constant Field Values

KEY_YEN

public static final int KEY_YEN
yen key (Japanese).

See Also:
Constant Field Values

KEY_NUMPADEQUALS

public static final int KEY_NUMPADEQUALS
= on num pad (NEC PC98).

See Also:
Constant Field Values

KEY_CIRCUMFLEX

public static final int KEY_CIRCUMFLEX
circum flex key (Japanese).

See Also:
Constant Field Values

KEY_AT

public static final int KEY_AT
@ key (NEC PC98).

See Also:
Constant Field Values

KEY_COLON

public static final int KEY_COLON
: key (NEC PC98)

See Also:
Constant Field Values

KEY_UNDERLINE

public static final int KEY_UNDERLINE
_ key (NEC PC98).

See Also:
Constant Field Values

KEY_KANJI

public static final int KEY_KANJI
kanji key (Japanese).

See Also:
Constant Field Values

KEY_STOP

public static final int KEY_STOP
stop key (NEC PC98).

See Also:
Constant Field Values

KEY_AX

public static final int KEY_AX
ax key (Japanese).

See Also:
Constant Field Values

KEY_UNLABELED

public static final int KEY_UNLABELED
(J3100).

See Also:
Constant Field Values

KEY_NUMPADENTER

public static final int KEY_NUMPADENTER
Enter key (num pad).

See Also:
Constant Field Values

KEY_RCONTROL

public static final int KEY_RCONTROL
right control key.

See Also:
Constant Field Values

KEY_NUMPADCOMMA

public static final int KEY_NUMPADCOMMA
, key on num pad (NEC PC98).

See Also:
Constant Field Values

KEY_DIVIDE

public static final int KEY_DIVIDE
/ key (num pad).

See Also:
Constant Field Values

KEY_SYSRQ

public static final int KEY_SYSRQ
SysRq key.

See Also:
Constant Field Values

KEY_RMENU

public static final int KEY_RMENU
right alt key.

See Also:
Constant Field Values

KEY_PAUSE

public static final int KEY_PAUSE
pause key.

See Also:
Constant Field Values

KEY_HOME

public static final int KEY_HOME
home key.

See Also:
Constant Field Values

KEY_UP

public static final int KEY_UP
up arrow key.

See Also:
Constant Field Values

KEY_PRIOR

public static final int KEY_PRIOR
PgUp key.

See Also:
Constant Field Values

KEY_PGUP

public static final int KEY_PGUP
PgUp key.

See Also:
Constant Field Values

KEY_LEFT

public static final int KEY_LEFT
left arrow key.

See Also:
Constant Field Values

KEY_RIGHT

public static final int KEY_RIGHT
right arrow key.

See Also:
Constant Field Values

KEY_END

public static final int KEY_END
end key.

See Also:
Constant Field Values

KEY_DOWN

public static final int KEY_DOWN
down arrow key.

See Also:
Constant Field Values

KEY_NEXT

public static final int KEY_NEXT
PgDn key.

See Also:
Constant Field Values

KEY_PGDN

public static final int KEY_PGDN
PgDn key.

See Also:
Constant Field Values

KEY_INSERT

public static final int KEY_INSERT
insert key.

See Also:
Constant Field Values

KEY_DELETE

public static final int KEY_DELETE
delete key.

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
The 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
The 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
power key.

See Also:
Constant Field Values

KEY_SLEEP

public static final int KEY_SLEEP
sleep key.

See Also:
Constant Field Values

listeners

protected java.util.List<KeyInputListener> listeners
list of event listeners.


INPUT_LWJGL

public static final java.lang.String INPUT_LWJGL

INPUT_AWT

public static final java.lang.String INPUT_AWT
See Also:
Constant Field Values
Constructor Detail

KeyInput

public KeyInput()
Method Detail

get

public static KeyInput get()
Returns:
the input instance, implementation is determined by querying getProvider()

getProvider

public static java.lang.Class<?> getProvider()
Query current provider for input.

Returns:
currently selected provider

setProvider

public static void setProvider(java.lang.String value)
Change the provider used for keyboard input. Default is INPUT_LWJGL.

Parameters:
value - new provider class name
Throws:
java.lang.IllegalStateException - if called after first call of get(). Note that get is called when creating the DisplaySystem.
java.lang.IllegalArgumentException - if the specified class cannot be found using Class.forName(String)

setProvider

public static void setProvider(java.lang.Class value)
Change the provider used for keyboard input. Default is InputSystem.INPUT_SYSTEM_LWJGL.

Parameters:
value - new provider
Throws:
java.lang.IllegalStateException - if called after first call of get(). Note that get is called when creating the DisplaySystem.

isKeyDown

public abstract boolean isKeyDown(int key)
isKeyDown returns true if the given key is pressed. False otherwise.

Parameters:
key - the keycode to check for.
Returns:
true if the key is pressed, false otherwise.

isInited

public static boolean isInited()
isInited returns true if the key class is not setup already (ie. .get() was not yet called).

Returns:
true if it is initialized and ready for use, false otherwise.

getKeyName

public abstract java.lang.String getKeyName(int key)
getKeyName returns the string prepresentation of a key code.

Parameters:
key - the key code to check.
Returns:
the string representation of a key code.

getKeyIndex

public abstract int getKeyIndex(java.lang.String name)
The reverse of getKeyName, returns the value of the key given the name

Parameters:
name -
Returns:
the value of the key

update

public abstract void update()
Updates the current state of the keyboard, holding information about what keys are pressed. Invokes event listeners synchronously.

Specified by:
update in class Input

destroy

protected abstract void destroy()
destroy frees the keyboard for use by other applications. Destroy is protected now - please is destroyIfInitalized().


addListener

public void addListener(KeyInputListener listener)
Subscribe a listener to receive mouse events. Enable event generation.

Parameters:
listener - to be subscribed

removeListener

public void removeListener(KeyInputListener listener)
Unsubscribe a listener. Disable event generation if no more listeners.

Parameters:
listener - to be unsubcribed
See Also:
addListener(KeyInputListener)

removeListeners

public void removeListeners()
Remove all listeners and disable event generation.


containsListener

public boolean containsListener(KeyInputListener listener)
Check if a listener is already added to this KeyInput

Parameters:
listener - listener to check for
Returns:
true if listener is contained in the listener list

getListeners

public java.util.List<KeyInputListener> getListeners()
Get all added key listeners

Returns:
ArrayList of listeners added to this KeyInput

destroyIfInitalized

public static void destroyIfInitalized()
Destroy the input if it was initialized.


isShiftDown

public boolean isShiftDown()

isControlDown

public boolean isControlDown()

clear

public abstract void clear()

clearKey

public abstract void clearKey(int keycode)