JTP
Class PlayerKeys

java.lang.Object
  extended by JTP.PlayerKeys

public class PlayerKeys
extends Object

Class for keeping track of which keys a player is holding down. Note: All methods in this class are synchronized.

Author:
V.Termanis

Field Summary
static int NONE
          Constand indicating no key is being held down.
 
Constructor Summary
PlayerKeys()
          Create a new PlayerKeys instance.
 
Method Summary
 int activeKey()
          Returns active key.
 void clear()
          Empties currently held down key cache.
 int getAndClearOneOffKey()
          Returns the currently set one-off key and clears it.
 boolean isRepeating()
          Indicates whether the keys are in repeat mode or not.
 boolean keyDown(int keyIndex)
          Registers a new key as being held down.
 boolean keyUp(int keyIndex)
          Unregisters key which from 'held down' list.
 boolean oneOffKeySet()
          Returns whether a one-off key is active.
 void setOneOffKey(int keyIndex)
          Sets a one-off key.
 void setRepeats(boolean on)
          Set whether any of the keys are in repeat mode or not.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NONE

public static final int NONE
Constand indicating no key is being held down.

See Also:
Constant Field Values
Constructor Detail

PlayerKeys

public PlayerKeys()
Create a new PlayerKeys instance.

Method Detail

activeKey

public int activeKey()
Returns active key.

Returns:
currently active key or NONE if no key is being held down.

setOneOffKey

public void setOneOffKey(int keyIndex)
Sets a one-off key.

Parameters:
keyIndex - code of one-off key
Throws:
IllegalArgumentException - if keyIndex != NONE.

oneOffKeySet

public boolean oneOffKeySet()
Returns whether a one-off key is active.

Returns:
true is a one-off key is set.

getAndClearOneOffKey

public int getAndClearOneOffKey()
Returns the currently set one-off key and clears it.

Returns:
the one-off key (could be NONE).

setRepeats

public void setRepeats(boolean on)
Set whether any of the keys are in repeat mode or not.

Parameters:
on - flags repeats as on or off.

isRepeating

public boolean isRepeating()
Indicates whether the keys are in repeat mode or not.

Returns:
true if repeats are on.

clear

public void clear()
Empties currently held down key cache. Note: This also includes the repeats flag and one-off key.


keyDown

public boolean keyDown(int keyIndex)
                throws IllegalArgumentException
Registers a new key as being held down.

Parameters:
keyIndex - code of newly pressed key
Returns:
true if this is a different key from the current one.
Throws:
IllegalArgumentException - if keyIndex < 0.

keyUp

public boolean keyUp(int keyIndex)
              throws IllegalArgumentException
Unregisters key which from 'held down' list. Note: Also turns off repeat mode and clears tigger key if necessary.

Parameters:
keyIndex - code of key to be released
Returns:
false if the key was not previously registered using keyDown method.
Throws:
IllegalArgumentException - if keyIndex < 0.