I have a simple keyboard input class that allows me to handle multiple simultaneous key presses:
import java.util.*;
private HashSet<Integer> keySet = new HashSet<Integer>();
public void keyPressed() {
keySet.add(keyCode);
}
public void keyReleased() {
keySet.remove(keyCode);
}
public boolean isKeyDown(int pKey) {
return keySet.contains(pKey);
}
This currently resides in a tab (thus as a static (inner) class, if I understand the environment correctly). As you can see, I'm using various key input functions such as keyPressed(). The problem is that I cannot use these functions in any other tab, since it is considered a duplicate method.
Ultimately, I'd like to be able to register multiple event handlers (and I don't want to work outside of Processing's built-in event handling, since apparently it does some fancy things such as event caching between draw calls, etc).
One solution is to wrap the tabbed file into its own class, rename the keyPressed() etc functions so that they are not overriding PApplet's built-in functions (i.e. onKeyPressed), then call those renamed functions from within the main tab's keyPressed() method - i.e.:
{inside main tab}
KeyboardInput kb = new KeyboardInput();
...
public void keyPressed(){
kb.onKeyPressed();
..other stuff..
}
But this is kinda messy, as not only do I need to keep an instance around, but I need to remember to manually hook these things in whenever I'm using this keyboard class in another project. Ideally, somewhere inside of the keyboard input class I'd like to have it register its methods as event handlers which will be automatically called by processing.