|
GTGE API | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.golden.gamedev.funbox.KeyCapture
public abstract class KeyCapture
KeyCapture
is a utility to capture key sequence combination,
usually used to turn on cheat mode.
Example how-to-use KeyCapture
class :
(print out a text whenever the user type 'HELLO' in right sequence)
BaseInput input; String key = "HELLO"; KeyCapture keycap = new KeyCapture(input, key, 1000) { public void keyCaptured() { // typing "HELLO" will print "hello world" to console System.out.println("hello world"); } }; public void update(long elapsedTime) { keycap.update(elapsedTime); }
Field Summary | |
---|---|
boolean |
DEBUG
Turn on this DEBUG variable to debug player input by print it to console. |
BaseInput |
input
BaseInput associated with this key capture. |
Constructor Summary | |
---|---|
KeyCapture(BaseInput input,
int[] key,
int delay)
Creates new KeyCapture with specified input, key, delay,
and listener. |
|
KeyCapture(BaseInput input,
String keyString,
int delay)
Creates new KeyCapture with specified input, key sequence in
string, delay, and listener. |
Method Summary | |
---|---|
int |
getDelayTime()
Returns the delay time each key typing allowed in milliseconds. |
int[] |
getKeySequence()
Returns the key sequence key code that will be captured. |
String |
getKeyString()
Returns the key sequence in string. |
int[] |
getModifiers()
The key modifiers associated with this key capture. |
boolean |
isActive()
Returns this key capture is active or not. |
abstract void |
keyCaptured()
Received key captured event when the key sequence combination is successfully captured. |
void |
refresh()
Refreshs captured key sequence. |
void |
setActive(boolean b)
Sets active state of this key capture. |
void |
setDelayTime(int i)
Sets the delay time each key typing allowed in milliseconds. |
void |
setKeySequence(int[] key)
Sets new key sequence key code. |
void |
setKeySequence(String st)
Parse String st into key sequence. |
void |
setModifiers(int i)
Sets key modifiers of this key capture. |
void |
setModifiers(int[] i)
Sets key modifiers of this key capture. |
String |
toString()
|
void |
update(long elapsedTime)
Updates key capture, this method need to be called in tight loop. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public BaseInput input
BaseInput
associated with this key capture.
public boolean DEBUG
Constructor Detail |
---|
public KeyCapture(BaseInput input, int[] key, int delay)
KeyCapture
with specified input, key, delay,
and listener.
input
- BaseInput
associated with this key capturekey
- array of key code (from KeyEvent
class) to
be captureddelay
- delay for each typing in millisecondspublic KeyCapture(BaseInput input, String keyString, int delay)
KeyCapture
with specified input, key sequence in
string, delay, and listener. The string will be parsed internally before
used.
input
- BaseInput
associated with this key capturekeyString
- string to be captureddelay
- delay for each typing in millisecondsMethod Detail |
---|
public int[] getKeySequence()
KeyEvent
public String getKeyString()
public void setKeySequence(int[] key)
key
- key sequence codeKeyEvent
public void setKeySequence(String st)
st
into key sequence. For example:
String key = "HYPERSPEED"; keyCapture.setKeySequence(key);
st
- String
to be parsed into key sequence
RuntimeException
- if the String st
can not be parsed.setKeySequence(int[])
public int[] getModifiers()
setModifiers(int)
,
setModifiers(int[])
public void setModifiers(int[] i)
i
- the key modifiersgetModifiers()
public void setModifiers(int i)
i
- the key modifiergetModifiers()
public abstract void keyCaptured()
public void refresh()
public void update(long elapsedTime)
public boolean isActive()
public void setActive(boolean b)
public int getDelayTime()
public void setDelayTime(int i)
public String toString()
toString
in class Object
|
GTGE API | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |