what about the keylistener?

18 views
Skip to first unread message

Davide D'Angelo

unread,
Apr 8, 2019, 8:56:13 AM4/8/19
to PraxisLIVE software discussion group
Hi, I've found the only way to check keyboard event is the 'keyPressed' boolean and then look for 'key' or 'keycode', am I right?

I needed to look for a keyReleased boolean and to know which key is released, but is it possible?
I don't know if it's possible/doable to implement the KeyListener to a class...

Suggestions?

Neil C Smith

unread,
Apr 8, 2019, 10:33:02 AM4/8/19
to Praxis LIVE software discussion group
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

Spiderdab

unread,
Apr 8, 2019, 11:09:08 AM4/8/19
to praxi...@googlegroups.com
Many thanks for your fast answer! Going to try that tomorrow.

--
You received this message because you are subscribed to the Google Groups "PraxisLIVE software discussion group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to praxis-live...@googlegroups.com.
To post to this group, send an email to praxi...@googlegroups.com.
Visit this group at https://groups.google.com/group/praxis-live.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages