Java3D Adding KeyListener to Canvas. Key Dont Fire.

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

Java3D Adding KeyListener to Canvas. Key Dont Fire.

Andrew
Hiah.

For a school project, a professor of mine is requiring that we use Java3D to create an application. I'm creating a small minigolf game, and want to use keyboard inputs to shoot the ball around; I've run into an issue though. When I add a KeyListener to the Canvas3D object, some keys stop responding. I am not sure what's causing this. To debug, I've created a simple KeyListener implementation, where I only print the key being pressed and nothing more. When I run the application, I press Q. The console prints Q. I press Q again, the console no longer prints Q. I press Space, it prints. I press Q again, still nothing. I press E, nothing. I press Control, it prints. Some keys print, some do not.

I am not sure what version of Java3D we're using, he included the jar files on his own website.
j3dcore.jar
j3dutils.jar
jog amp-fat.jar
vecmath.jar

They're from 2017.
Reply | Threaded
Open this post in threaded view
|

Re: Java3D Adding KeyListener to Canvas. Key Dont Fire.

Andrew
I should also point out that this problem does not seem to appear while using Windows. Only mac.
Reply | Threaded
Open this post in threaded view
|

Re: Java3D Adding KeyListener to Canvas. Key Dont Fire.

philjord
Hi Andrew,
Thanks for raising this issue. I'm based on windows and don't have access to a MacOS device, so I'm going to be much less useful to you than I'd like to be.

Firstly if you can post the sample code that shows the problem that will help me to focus on the right areas when trying to track this down.

Next there hasn't been any change to the key listener code in Java3D for many years so I'm going to assume the specific version you've been given won't be the problem, I'll be working on these jars
https://github.com/hharrison/java3d-core/releases/tag/1.6.0 
(and the source code for those jars java3d, linked there)

Finally the key listeners for Canvas3D are inherited from Component, and not touched in anyway (which you can verify by looking at the source of Canvas3D) though it forwards events from it's EventCatcher to the behaviour scheduler so java3d behaviors can trigger on AWTEvents

Please note in Canvas3D this comment:
 /**
     * This method overrides AWT's handleEvent class...
     */
    void sendEventToBehaviorScheduler(AWTEvent evt) {

Is over 15 years old and was only accurate in the Java 1.1 event model, so I should probably update it one day.

In order to investigate key events outside of Canvas3D could you set up the same tests with a simple JPanel and key listener with the rest of the test setup unchanged and confirm they are responding when you expect them to?

Once you've confirmed that (and provided a simple test code for me) I'll work out the next steps

Thanks,
Phil.
Reply | Threaded
Open this post in threaded view
|

Re: Java3D Adding KeyListener to Canvas. Key Dont Fire.

gouessej
Administrator
Hello

Maybe it's not a Java3D problem. Please post a SSCCE. If I were you, I would try to reproduce this bug in a program written in Java and using only AWT and Swing without Java3D.

By the way, just to exclude any risk of conflicts, please follow my instructions with the version of Java3D you have to use for your project.
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: Java3D Adding KeyListener to Canvas. Key Dont Fire.

Andrew
Here is a small program showing the problem:
https://pastebin.com/LyZdZseb

Works perfectly on windows. On Mac key events seem to break once A or D register a “held down” event on the OS. Quick key taps doesn’t seem to break it。
Reply | Threaded
Open this post in threaded view
|

Re: Java3D Adding KeyListener to Canvas. Key Dont Fire.

Andrew
Furthermore, this does not happen with creating a simple Java awt/swing application. Only when I use the Canvas3D object. I've created tons of Swing/awt applications over the years on my current machine (macos), never ran into any problems.
Reply | Threaded
Open this post in threaded view
|

Re: Java3D Adding KeyListener to Canvas. Key Dont Fire.

gouessej
Administrator
Thank you for checking that. Is it reproducible under GNU Linux too?
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: Java3D Adding KeyListener to Canvas. Key Dont Fire.

Andrew
I don't have Linux. I don't know.
Reply | Threaded
Open this post in threaded view
|

Re: Java3D Adding KeyListener to Canvas. Key Dont Fire.

philjord
A google search turned up this forum post
https://community.oracle.com/thread/4115318

It seems to be right up the alley of what we are talking about, key repeats for the a key seem to stop being passed through, in some manner related to the the European accented characters pop up option.

Obviously I notice that the d key is not listed as a special, however random testing might have got one of the affected key to stop input and seemed like any key does it perhaps and you've tested with a vanilla JPanel and you don't get the issue.

The post doesn't say what version of jdk he is using, but suggests that doesn't affect anything.

Is your version on MacOS 10.13?

Can you run your test program but put system out into the key typed and key released methods to see if they are still triggered what key pressed stops being called?

Could you retest to see if only the set of characters z, c, n, a, s, e, y, u, i, o are causing the issue. So run the app and only hold down the d key and nothing else and see what the behavior is?

If this path yields no good results the next step is to modify the Canvas3D class and remove anything that refers to KeyEvent and AWTEvent, this is a bigger piece of work so I think it's worthwhile thoroughly thrashing these OS version based ideas first.

Thanks,
Phil.