GTGE API

com.golden.gamedev.funbox
Class KeyCapture

java.lang.Object
  extended by com.golden.gamedev.funbox.KeyCapture

public abstract class KeyCapture
extends Object

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

input

public BaseInput input
BaseInput associated with this key capture.


DEBUG

public boolean DEBUG
Turn on this DEBUG variable to debug player input by print it to console.

Constructor Detail

KeyCapture

public KeyCapture(BaseInput input,
                  int[] key,
                  int delay)
Creates new KeyCapture with specified input, key, delay, and listener.

Parameters:
input - BaseInput associated with this key capture
key - array of key code (from KeyEvent class) to be captured
delay - delay for each typing in milliseconds

KeyCapture

public KeyCapture(BaseInput input,
                  String keyString,
                  int delay)
Creates new KeyCapture with specified input, key sequence in string, delay, and listener. The string will be parsed internally before used.

Parameters:
input - BaseInput associated with this key capture
keyString - string to be captured
delay - delay for each typing in milliseconds
Method Detail

getKeySequence

public int[] getKeySequence()
Returns the key sequence key code that will be captured.

See Also:
KeyEvent

getKeyString

public String getKeyString()
Returns the key sequence in string.


setKeySequence

public void setKeySequence(int[] key)
Sets new key sequence key code.

Parameters:
key - key sequence code
See Also:
KeyEvent

setKeySequence

public void setKeySequence(String st)
Parse String st into key sequence.

For example:

     String key = "HYPERSPEED";
     keyCapture.setKeySequence(key);
 

Parameters:
st - String to be parsed into key sequence
Throws:
RuntimeException - if the String st can not be parsed.
See Also:
setKeySequence(int[])

getModifiers

public int[] getModifiers()
The key modifiers associated with this key capture. Key modifiers is the key that must be always pressed while typing the key sequence combination.

See Also:
setModifiers(int), setModifiers(int[])

setModifiers

public void setModifiers(int[] i)
Sets key modifiers of this key capture. Key modifiers is the key that must be always pressed while typing the key sequence combination.

Parameters:
i - the key modifiers
See Also:
getModifiers()

setModifiers

public void setModifiers(int i)
Sets key modifiers of this key capture. Key modifiers is the key that must be always pressed while typing the key sequence combination.

Parameters:
i - the key modifier
See Also:
getModifiers()

keyCaptured

public abstract void keyCaptured()
Received key captured event when the key sequence combination is successfully captured.


refresh

public void refresh()
Refreshs captured key sequence.


update

public void update(long elapsedTime)
Updates key capture, this method need to be called in tight loop.


isActive

public boolean isActive()
Returns this key capture is active or not.


setActive

public void setActive(boolean b)
Sets active state of this key capture.


getDelayTime

public int getDelayTime()
Returns the delay time each key typing allowed in milliseconds.


setDelayTime

public void setDelayTime(int i)
Sets the delay time each key typing allowed in milliseconds.


toString

public String toString()
Overrides:
toString in class Object

GTGE API

Copyright © 2003-2005 Golden T Studios. All rights reserved. Use is subject to license terms.
GoldenStudios.or.id