Slick Forums
http://slick.ninjacave.com/forum/

[BUG] hasFocus() and isKeyDown() issues
http://slick.ninjacave.com/forum/viewtopic.php?f=1&t=5342
Page 1 of 1

Author:  JoeK5142 [ Fri Aug 03, 2012 4:11 am ]
Post subject:  [BUG] hasFocus() and isKeyDown() issues

Hello all,

I have two issues right now. 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:
   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.

Author:  davedes [ Fri Aug 03, 2012 7:29 pm ]
Post subject:  Re: [BUG] hasFocus() and isKeyDown() issues

The first issue:
viewtopic.php?f=1&t=5260

The second issue sounds like another LWJGL bug, since hasFocus just calls Display.isActive.

So, in short... Neither of those are something we can fix on our end very easily.

Author:  tvg [ Tue Sep 18, 2012 1:46 pm ]
Post subject:  Re: [BUG] hasFocus() and isKeyDown() issues

I've found another issue that may be related to this. (Also, I think I already posted this here, but I can't find it anywhere. So forgive me, if I repost).

When I check input.isKeyDown on Shift or Ctrl keys, as soon as I press the key once, the isKeyDown method always returns true. This happens against the latest version of the dev branch. I verified the problem on a friends slick setup and he also could check, that the bug did not occur in the "stable" version published on the slick homepage.

This happens even if the window does not lose focus. I'm not sure which keys are all affected by this, I only found LCTRL, RCTRL, LSHIFT and RSHIFT are not working up until now.

Here is the test class I used to verify the problem outside of my project: http://pastebin.com/NUBZjAWK

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/