Request Focus to Fullscreen Game

hey.



I'm having a really specific problem. I'm running a StandardGame in fullscreen and as soon as there's an output to the console (a System.out.print), the game minimizes.



I figured that the problem is caused by the game's window never requesting focus. Because people do not interact with the game through the standard keyboard/mouse/joystick, the focus never actually moves to the game window.



Is there a function to request focus to the game window?



Thanks in advance.

Hmm…  I've never seen a problem quite like that.  I believe that input focus is gained by a fullscreen window as soon as the Keyboard or Mouse input is created.  Are you saying you don't even create either of those?  Also, you might consider redirecting standard output to a log file.

I'll give the log file a try on monday. But here's a few more details just to add to the strange results I get.



When I say the game doesn't use a keyboard and a mouse I mean the version that people will use in the end. I do use keyboard and mouse input for debugging. So I launch the game from the console, it starts in fullscreen, but as soon as there's an output to the console, the fullscreen minimize. Then, I can click to maximize it again, probably giving focus to it I assume, and from there the game runs fine in fullscreen with the output happening in the background.



What's weirder is that this happens on the iMac running Windows XP, but not on my Dell which is also running XP.



Then, I tried to spawn it from ant using javaw (instead of java) so that not output is seen in the console. Strangely enough, no ouput appears, but at the exact time when the output would have appeared if it was running the standard java, the fullscreen minimizes.



Bit confusing.

Guess I missed this one, which is a bummer since I have an answer; oh well I will post anyway… maybe it will help someone in the future.



Answer: use the Robot class to simulate a mouse click (which will give the Canvas focus):



        if( !hasFocus ){

            try{
                Robot robot = new Robot();

                robot.mousePress( InputEvent.BUTTON1_MASK );
                robot.mouseRelease( InputEvent.BUTTON1_MASK );
                hasFocus = true;
            } catch( Exception e ){
                e.printStackTrace();
                hasFocus = true;    // Prevent endless errors
            }

        }



This will work for fullscreen windows as is, however for windowed applications you will need to obtain the center point of the window [ start_X + (width/2), start_Y + (height/2) ]. 
(where start_ variables are the point at which the openGL window starts [top left corner], and width/height are the width/height of the opengl window)

(Not sure why there is no getCanvasTopLeftPoint() available in DisplaySystem, since there are getWidth and getHeight methods.  Maybe I am just not looking in the right spot...)

funny how when you write about bugs you figure out you've been looking at the wrong place all along.



thanks for pointing out the Robot class, that'll be useful later.



I found out that my problem was due to Windows' Infrared Monitor stealing the focus the first time a connection was made during the game. Once that's off, everything seems fine.



cheers