| 
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objecthmi.util.KeyState
public class KeyState
KeyState is a KeyListener, that keeps track of the current key states So, it converts the Java event based interface for the keyboard into a state based interface. The current state of keys is available in the form of a public array "keyDown": keyDown[keycode] is true as long as that key is down, i.e. pressed and not yet released. Note that several keys can be down at the same time. Also, it records the state for "raw" key codes, i.e. a modifier key like the SHIFT key means that keyDown[KeyEvent.VK_SHIFT] is true, but does not modify the key code for other keys. Only keycodes in the range 0 .. KEYCODES are recorded. In practice, this includes all keys on a standard keyboard, but it does not include all Unicode keys. In addition to keyDown, there is an int array keyLocation, which records the keyboard location of a key, while it is down. (Distinguishes between KEY_LOCATION_LEFT , KEY_LOCATION_RIGHT, KEY_LOCATION_NUMPAD etc).
| Field Summary | |
|---|---|
static int | 
KEYCODES
 | 
private  boolean[] | 
keyDown
 | 
private  int[] | 
keyLocation
 | 
| Constructor Summary | |
|---|---|
KeyState()
create a new KeyState.  | 
|
KeyState(Component c)
creates a KeyState that listens to Component c for KeyEvents  | 
|
| Method Summary | |
|---|---|
 void | 
focusGained(FocusEvent e)
 | 
 void | 
focusLost(FocusEvent e)
 | 
 boolean | 
isKeyDown(int keyCode)
returns the current value of keyDown[keyCode]  | 
 void | 
keyPressed(KeyEvent evt)
keyPressed handler from the KeyListener interface for this tracker.  | 
 void | 
keyReleased(KeyEvent evt)
keyReleased handler from the KeyListener interface for this tracker.  | 
 void | 
keyTyped(KeyEvent evt)
keyTyped handler from the KeyListener interface: ignored.  | 
 String | 
locationString(int location)
produces a descriptive String for a key location: Left, Right, Numpad, S(tandard), or U(nknown).  | 
private  void | 
reset()
 | 
| Methods inherited from class java.lang.Object | 
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait | 
| Field Detail | 
|---|
public static final int KEYCODES
private boolean[] keyDown
private int[] keyLocation
| Constructor Detail | 
|---|
public KeyState()
public KeyState(Component c)
| Method Detail | 
|---|
public final void keyPressed(KeyEvent evt)
keyPressed in interface KeyListenerpublic final void keyReleased(KeyEvent evt)
keyReleased in interface KeyListenerpublic final void keyTyped(KeyEvent evt)
keyTyped in interface KeyListenerpublic boolean isKeyDown(int keyCode)
public String locationString(int location)
private void reset()
public void focusGained(FocusEvent e)
focusGained in interface FocusListenerpublic void focusLost(FocusEvent e)
focusLost in interface FocusListener
  | 
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||