Hello Guest

[BUG] hasFocus() and isKeyDown() issues

  • 1 Replies
  • 7796 Views
[BUG] hasFocus() and isKeyDown() issues
« on: August 04, 2012, 08:02:50 »
Hello all,

I'm using Slick2d and LWJGL to write a game.  I have two issues right now, and I was told that they are both related to LWJGL on the Slick2D forum, so I've come here for assistance. The first is that isKeyDown() will return true if the game window loses focus while they key in question is down, even after returning to the game and no longer holding the key down. In my particular case, this makes it so that if the game is alt+tabbed out of and brought back up, pressing enter will switch between fullscreen and windowed mode (when it should be alt+enter). They alt key returns to normal functionality afterwards.

The second issue stems from trying to fix the first. I was attempting to check the container with hasFocus(), then destroy() and create() the Keyboard once it came back into focus. This only seemed to work in windowed mode. When investigating, I found that hasFocus() always returns true in fullscreen mode, whether alt+tabbed or not.

Here are the relevant areas of the update() function:

Code:
 
Code: [Select]
public void update(GameContainer container, int delta) throws SlickException
   {   
      if(!container.hasFocus())
      {
         System.out.println("Container does not have focus"); //Does not print when alt+tabbed in fullscreen, does in windowed
      }
      Input input = container.getInput();   
      input.enableKeyRepeat();
     
         
      if(input.isKeyPressed(Input.KEY_ENTER))
      {
         if(input.isKeyDown(Input.KEY_LALT) || input.isKeyDown(Input.KEY_RALT))
         {
            Vars.fullscreen = !Vars.fullscreen;
            container.setFullscreen(Vars.fullscreen);
         }
      }
...


If anyone can help me with these issues, it'd be greatly appreciated. Either getting hasFocus() to work properly with fullscreen enabled or forcing a key release on LALT and RALT could help, but I haven't been able to figure out how to do these things.

Thanks for reading.

*

Offline kappa

  • *****
  • 1319
Re: [BUG] hasFocus() and isKeyDown() issues
« Reply #1 on: August 04, 2012, 11:55:16 »
The first issue already has a bug report found here including a possible fix/patch on that thread.