简体   繁体   English

Java3D中的自定义KeyListener

[英]Custom KeyListener in Java3D

I've added Java3D's KeyNavigatorBehavior to a SimpleUniverse in my Java3D program. 我已经在Java3D程序的SimpleUniverse中添加了Java3D的KeyNavigatorBehavior。 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". 我知道KeyNavigatorBehavior会检测到按下向上,向下,向左和向右箭头的时间,但是我也想检测其他键,例如WASD,但是没有太多运气来搜索“自定义Java3D键导航器行为”。

I've looked at the KeyNavigatorBehavior source code, found here: 我查看了可在此处找到的KeyNavigatorBehavior源代码:

http://www.java2v.com/Open-Source/Java-Document/6.0-JDK-Modules/java-3d/org/jdesktop/j3dfly/utils/vpbehaviors/KeyNavigatorBehavior.java.htm 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: 并注意到可以在此处找到KeyNavigator类:

http://www.java2v.com/Open-Source/Java-Document/6.0-JDK-Modules/java-3d/com/sun/j3d/utils/behaviors/keyboard/KeyNavigator.java.htm 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. 不幸的是,该对象是没有getter或setter的私有类成员,因此我认为没有任何方法可以访问它。

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. 我也尝试过将KeyListener添加到SimpleUniverse.getCanvas()中,但这没有用,而且我认为这不是正确的方法。

I'm wondering if anyone could give me a suggestion on how I could add my own keys to be detected in Java3D. 我想知道是否有人可以建议我如何添加自己的密钥以在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! 谢谢您的帮助!

Actually, I found the problem, thanks to Monad Newb's comment. 实际上,由于Monad Newb的评论,我找到了问题。 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. 实际上,您可以只使用simpleUniverse.getCanvas()。addKeyListener()将按键侦听器添加到Java3D程序中,按键事件应该可以正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM