edu.neu.ccs.gui
Class KeyPressReleaseListener

java.lang.Object
  extended byedu.neu.ccs.gui.KeyPressReleaseListener
All Implemented Interfaces:
EventListener, KeyListener

public class KeyPressReleaseListener
extends Object
implements KeyListener

The class KeyPressReleaseListener implements a KeyListener that tracks the pressed-released state of keyboard keys. It is possible to track all key codes from the Java class KeyEvent or to supply a list of which particular key codes to track.

This class makes a best effort to track multiple simultaneous key press situations. We know however that in some cases the hardware does not deliver the required information to Java if "too many" keys are pressed. Let us explain.

We have run experiments using a laptop with an external USB keyboard attached. Here are some of the problems encountered.

The bottom line is that software cannot process what the hardware and operating system refuse to deliver as proper and timely events.

Despite these significant issues, we felt that KeyPressReleaseListener is a valuable class for certain student software projects so we have decided to include it in JPT as is.

Since:
2.5.0
Version:
2.5.0

Field Summary
private  BooleanStateArray bsa
          The structure to maintain the pressed-released state.
 
Constructor Summary
KeyPressReleaseListener()
          Initializes the internal state structure with all key codes from the KeyEvent class.
KeyPressReleaseListener(int[] list)
          Initializes the internal state structure with the given list of key codes which should be a subset of the KeyEvent class key codes.
 
Method Summary
 boolean getState(int keycode)
          Returns the boolean state of the given key where true = pressed and false = released.
 void keyPressed(KeyEvent e)
          Stores the event key code state as true.
 void keyReleased(KeyEvent e)
          Stores the event key code state as false.
 void keyTyped(KeyEvent e)
          Does nothing.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

bsa

private BooleanStateArray bsa
The structure to maintain the pressed-released state.

Constructor Detail

KeyPressReleaseListener

public KeyPressReleaseListener()
Initializes the internal state structure with all key codes from the KeyEvent class.


KeyPressReleaseListener

public KeyPressReleaseListener(int[] list)
Initializes the internal state structure with the given list of key codes which should be a subset of the KeyEvent class key codes.

Parameters:
list - the list of key codes to track
Method Detail

keyPressed

public void keyPressed(KeyEvent e)
Stores the event key code state as true.

Specified by:
keyPressed in interface KeyListener
Parameters:
e - the KeyEvent sent to this listener

keyReleased

public void keyReleased(KeyEvent e)
Stores the event key code state as false.

Specified by:
keyReleased in interface KeyListener
Parameters:
e - the KeyEvent sent to this listener

keyTyped

public void keyTyped(KeyEvent e)
Does nothing.

Specified by:
keyTyped in interface KeyListener

getState

public boolean getState(int keycode)

Returns the boolean state of the given key where true = pressed and false = released.

Returns false if the key was not given in the list provided to the constructor since that key is not being tracked.

Parameters:
keycode - the keycode whose pressed-released state is being queried