Java-Gaming.org Java4K winners: [ by our judges | by the community ]         
Featured games (67)
games approved by the League of Dukes
Games in Showcase (∞)
games submitted by our members



News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  Print  
  window w. jogl loses keyboard input  (Read 1200 times)
0 Members and 1 Guest are viewing this topic.
Offline oldmicah

JGO n00b
*

Posts: 2


Java games rock!


« on: 2004-10-10 11:23:05 »

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);
Online cylab

JGO Kernel
*****

Posts: 1940
Medals: 27



« Reply #1 on: 2004-10-10 13:19:49 »

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

Mathias - I Know What [you] Did Last Summer!
Offline oldmicah

JGO n00b
*

Posts: 2


Java games rock!


« Reply #2 on: 2004-10-10 20:20:20 »

canvas.setFocusable(false) worked like a charm.  Many thanks.
Games published by our own members! Go get 'em!
Offline Lareon

JGO n00b
*

Posts: 42


I program for fun... Isn't that weird?!?


« Reply #3 on: 2004-10-16 14:49:16 »

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?
Offline Mithrandir

Sr. Member
**

Posts: 463
Medals: 1


Cut from being on the bleeding edge too long


« Reply #4 on: 2004-10-16 15:57:06 »

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.

The site for 3D Graphics information http://www.j3d.org/
Aviatrix3D JOGL Scenegraph http://aviatrix3d.j3d.org/
Programming is essentially a markup language surrounding mathematical formulae and thus, should not be patentable.
Offline ozak

Full Member
**

Posts: 222


Java demon has no respect for bad code!!!


« Reply #5 on: 2004-12-07 01:35:35 »

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.

Want to do multiplayer? Why not try my free Socky socket server?
It's scriptable through JavaScript!
Check it out at http://www.furi.dk/socky
Pages: [1]
  Print  
 
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!
Page created in 0.118 seconds with 21 queries.