Using keyPressed() in custom Keyboard handler class (Eclipse)
in
Integration and Hardware
•
11 months ago
Hi!
Is it possible to use the keyPressed function outside of the main PApplet class in Eclipse? I would like to have a class that I can reuse for keyboard controls but I can't seem to get it to work...
I am sorry if this has been asked before but I couldn't find any answer to adress this issue on the forum.
Basically it would be something like that I can have outside the setup() and draw() methods main class:
import processing.core.PApplet;
public class Keyboard extends PApplet {
Main p;
public Keyboard(Main p) {
this.p = p;
}
public void run() {
keyPressed();
}
public void keyPressed() {
// Enable PDF File Export
if (key == 's' || key == 'S') {
p.saveFlag = !p.saveFlag;
if (p.saveFlag) {
println("Saving ENABLED");
} else {
println("Saving Disabled");
}
}
// Print Timestamp
if (key == 't' || key == 'T') {
println(p.timestamp());
}
// Reset Sketch
if (key == 'r' || key == 'R') {
p.reset();
}
// Exit Sketch
if (key == 'q' || key == 'Q') {
exit();
}
// Increase Seed Value
if (key == CODED) {
if (keyCode == LEFT) {
p.seed--;
p.reset();
} else if (keyCode == RIGHT) {
p.seed++;
p.reset();
}
}
}
}
1