All Packages Class Hierarchy This Package Previous Next Index
java.lang.Object | +----cs005.event.KeyInteractor
This is the abstract class for all KeyInteractions. If you want to create an object that can handle a key press, you must subclass off of this class and fill in the keyPress and keyRelease methods (one of them can be empty). You should never call those methods yourself! They are called automatically when the key is pressed. When a KeyInteractor is created it is OFF. You need to turn it on before you can expect it to work.
The key you pass in is either the ascii value of the key you want to detect presses from, or the actual character you want to use. Remember, case matters. Also, for keys that do not have ascii values, consult the java.awt.event documentation. For example, passing in either 'd' or 100 would result in a KeyInteractor that called its methods when the d key was pressed (with no modifiers).
This will create a new interactor with the given character key.
This will create a new interactor with the given key.
This is the constructor to use if an App isn't being used.
This method is called whenever the Interactor's key is pressed.
This method is called whenever the Interactor's key is released.
This turns off the KeyInteractor.
This turns on the KeyInteractor.
public KeyInteractor(App app, int key)
This will create a new interactor with the given key. All KeyInteractors are created in the "off" state.
public KeyInteractor(App app, char key)
This will create a new interactor with the given character key. It can only be used for keys which have a character value, for example 'j' would be acceptable whereas 'return' would not be.
public KeyInteractor(KeyPressManager kpm, int key)
This is the constructor to use if an App isn't being used. However, you should really use the App we've made for you.
public void turnOff()
This turns off the KeyInteractor.
public void turnOn()
This turns on the KeyInteractor. You must call this method before the KeyInteractor will register keypresses!
public abstract void keyPress()
This method is called whenever the Interactor's key is pressed. You must fill in either this or keyRelease (or both) in a subclass for the Interactor to work properly. One of these methods may be empty.
public abstract void keyRelease()
This method is called whenever the Interactor's key is released. You must fill in either this or keyPress (or both) in a subclass for the Interactor to work properly. One of these methods may be empty.
All Packages Class Hierarchy This Package Previous Next Index