With a little difficulty. The event listener methods aren't mapped by
default because it's awkward to work around when Processing fires
them. In Processing you can draw in these methods, but the events are
fired when drawing is set to the main screen PApplet, not to the
node's graphic context. One day I'll figure out the right approach to
enable these.
Now, you can access the underlying PApplet and register these methods
in the same way that a library would. Just don't try and call any
drawing methods in the listener. This uses Ref to handle registration
for you across code changes. And make sure you put the import lines
above the locked grey Class Declaration section. This is in a
video:gl:p2d or video:gl:p3d.
`````
import processing.core.PApplet;
import processing.event.KeyEvent;
@Inject Ref<PApplet> p5;
@Override
public void setup() {
p5.init(() -> find(PApplet.class).get())
.apply(p -> p.registerMethod("keyEvent", this))
.onReset(p -> p.unregisterMethod("keyEvent", this));
}
@Override
public void draw() {
}
public void keyEvent(KeyEvent event) {
switch(event.getAction()) {
case KeyEvent.PRESS :
log(INFO, "Key pressed : " + event.getKey());
break;
case KeyEvent.RELEASE :
log(INFO, "Key released : " + event.getKey());
}
}
`````
Hope that helps.
Best wishes,
Neil
--
Neil C Smith
Artist & Technologist
www.neilcsmith.net
PraxisLIVE - hybrid visual live programming
for creatives, for programmers, for students, for tinkerers
www.praxislive.org