Question

I've added Java3D's KeyNavigatorBehavior to a SimpleUniverse in my Java3D program. I know the KeyNavigatorBehavior detects when the up, down, left, and right arrows are pressed, but I would also like to detect other keys, such as WASD, but haven't had much luck googling "custom Java3D key navigator behavior".

I've looked at the KeyNavigatorBehavior source code, found here:

http://www.java2v.com/Open-Source/Java-Document/6.0-JDK-Modules/java-3d/org/jdesktop/j3dfly/utils/vpbehaviors/KeyNavigatorBehavior.java.htm

and noticed that the KeyNavigator class, found here:

http://www.java2v.com/Open-Source/Java-Document/6.0-JDK-Modules/java-3d/com/sun/j3d/utils/behaviors/keyboard/KeyNavigator.java.htm

seems to handle the key events. Unfortunately, the object is a private class member without a getter or setter, so I don't think there's any way I can access it.

I've also tried adding a KeyListener to the SimpleUniverse.getCanvas(), but that did not work, and I don't think it is the correct method.

I'm wondering if anyone could give me a suggestion on how I could add my own keys to be detected in Java3D.

(I realize that I could copy and paste the source code and make whatever changes I need, but I'm hoping that there might be a better and less painful alternative.)

Thanks for the help!

Was it helpful?

Solution

Actually, I found the problem, thanks to Monad Newb's comment. You can actually just use simpleUniverse.getCanvas().addKeyListener() to add a key listener to your Java3D program, and the key events should work just fine.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top