window w. jogl loses keyboard input

Using build 1.0 of Jogl (from April) under OS X with java 1.4.2_05

I have a Frame that I am adding a GLCanvas to, and I am not running in full screen mode. The odd bit is that my keyboard commands work fine until I switch to another window and switch back, resize the window, or click in the window. Then, keyboard events no longer reach my window.

Has anyone else seen this, or perhaps more importantly, does anyone know how to work around it?

thanks all!

//code from my Frame ctor

        addKeyListener(this);
        // get a GLCanvas
        GLCapabilities capabilities = new GLCapabilities();
        canvas = GLDrawableFactory.getFactory().createGLCanvas(capabilities);
        canvas.addGLEventListener(this);

BorderLayout.CENTER
// to make the canvas stretch to fill the container (ie, the frame)
add(canvas, BorderLayout.CENTER);

The GLCanvas gets the focus. Either forbid this behaviour by setting canvas.setFocusable(false) or add the KeyListener to the canvas as well.

canvas.setFocusable(false) worked like a charm. Many thanks.

Um… I have had trouble getting the GLCanvas to receive keyboard input when I attach the KeyListener to it. I’ve ONLY had success attaching a KeyListener to the frame which holds the GLCanvas.

Is this expected? Also, is this the best way (barring JInput, etc…) to get keyboard input if using JoGL for a game? I want to learn it doing things the RIGHT way!

Thanks!
–Lareon

PS: Is there some way to turn off key-repeating in Java? Or should I just code my programs ASSUMING that, if held in long enough, I will get multiple keyPressed() events?

Key repeat is a function of the operating system. You’d need to turn it off as part of either the BIOS on setup or using the O/S-specific controls. You need to code the Java APP to deal with the extra key repeats, or ideally work with keyReleased() and/or keyTyped() if at all possible.

I second adding your listeners to both canvas and frame.
It’s the only way I’ve made it work flawlessly on both Windows and OS X.