LWJGL Forum

Please login or register.

Login with username, password and session length
Pages: [1] 2

Author Topic: [FIXED] Right shift key gets stuck being reported as "down"  (Read 9873 times)

avm1979

  • Regular nerd
  • **
  • Offline Offline
  • Posts: 98

If you press one of the shift keys (left or right, doesn't matter), hold it down, then press the other shift key so that both are down at the same time, and then release them in any order, Keyboard.isKeyDown(Keyboard.KEY_RSHIFT) will continue to return true. A "key up" event will also not be generated for the right shift key.

It can be "unstuck" by pressing and releasing the right shift key again.


This is on Windows 7 with LWJGL version 2.8.4.


Minimal test case:
Code: [Select]
import org.lwjgl.input.Keyboard;
import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
import org.lwjgl.opengl.PixelFormat;

public class ShiftTest {

public static final int SCREEN_WIDTH = 640;
public static final int SCREEN_HEIGHT = 480;

public static void main(String[] args) throws Exception {
setDisplayMode();
Display.setTitle("Shift Test");
Display.setFullscreen(false);
Display.setVSyncEnabled(true);
Display.create(new PixelFormat(32, 0, 24, 8, 0));
Mouse.setGrabbed(false);

while (true) {

boolean lShiftDown = Keyboard.isKeyDown(Keyboard.KEY_LSHIFT);
boolean rShiftDown = Keyboard.isKeyDown(Keyboard.KEY_RSHIFT);

System.out.println(String.format("LShift: %b\tRShift: %b", lShiftDown, rShiftDown));

if (Display.isCloseRequested() || Keyboard.isKeyDown(Keyboard.KEY_ESCAPE)) {
break;
}
Display.update();

}
}

private static void setDisplayMode() throws Exception
{
DisplayMode[] dm = org.lwjgl.util.Display.getAvailableDisplayModes(SCREEN_WIDTH, SCREEN_HEIGHT, -1, -1, -1, -1, 60, 60);
org.lwjgl.util.Display.setDisplayMode(dm, new String[] {
"width=" + SCREEN_WIDTH,
"height=" + SCREEN_HEIGHT,
"freq=" + 60,
"bpp=" + org.lwjgl.opengl.Display.getDisplayMode().getBitsPerPixel()
         });
}
}
Logged

spasi

  • Administrator
  • Nerdus Imperius
  • *****
  • Offline Offline
  • Posts: 1782
Re: [BUG] Right shift key gets stuck being reported as "down"
« Reply #1 on: October 19, 2013, 20:35:21 »

Have you tried the latest LWJGL version?
Logged

avm1979

  • Regular nerd
  • **
  • Offline Offline
  • Posts: 98
Re: [BUG] Right shift key gets stuck being reported as "down"
« Reply #2 on: October 20, 2013, 00:52:19 »

Just tried it with 2.9.0; same behavior.
Logged

spasi

  • Administrator
  • Nerdus Imperius
  • *****
  • Offline Offline
  • Posts: 1782
Re: [BUG] Right shift key gets stuck being reported as "down"
« Reply #3 on: October 20, 2013, 12:33:45 »

Thanks for the bug report, this should be fixed in the next build.
Logged

avm1979

  • Regular nerd
  • **
  • Offline Offline
  • Posts: 98
Re: [BUG] Right shift key gets stuck being reported as "down"
« Reply #4 on: October 20, 2013, 19:36:37 »

Cool, thank you!
Logged

FlukeFan

  • Newbie
  • *
  • Offline Offline
  • Posts: 8
Re: [FIXED] Right shift key gets stuck being reported as "down"
« Reply #5 on: January 05, 2015, 16:19:07 »

Hi,

This appears to still be happening with the 2.9.2 release.  I don't see a mention of this in the github issues - was an issue raised?

Cheers,
    Richard
Logged

spasi

  • Administrator
  • Nerdus Imperius
  • *****
  • Offline Offline
  • Posts: 1782
Re: [FIXED] Right shift key gets stuck being reported as "down"
« Reply #6 on: January 05, 2015, 16:30:43 »

I'm not seeing any problem with the OP's code. What behavior are you seeing exactly?
Logged

FlukeFan

  • Newbie
  • *
  • Offline Offline
  • Posts: 8
Re: [FIXED] Right shift key gets stuck being reported as "down"
« Reply #7 on: January 05, 2015, 16:33:56 »

I'm seeing that when both shift keys are pressed, and released at the same time, isKeyPressed still returns true for one of them (the right shift).

I'm also not seeing the issue that was created to track this, so I'm not sure how to track down what the fix was.

Thanks.
Logged

spasi

  • Administrator
  • Nerdus Imperius
  • *****
  • Offline Offline
  • Posts: 1782
Re: [FIXED] Right shift key gets stuck being reported as "down"
« Reply #8 on: January 05, 2015, 17:00:26 »

isKeyPressed still returns true for one of them (the right shift).

There is no isKeyPressed method, do you mean Keyboard.isKeyDown?

I'm also not seeing the issue that was created to track this, so I'm not sure how to track down what the fix was.

There was no issue iirc. There were two commits that fixed the problem: first, second.
Logged

spasi

  • Administrator
  • Nerdus Imperius
  • *****
  • Offline Offline
  • Posts: 1782
Re: [FIXED] Right shift key gets stuck being reported as "down"
« Reply #9 on: January 05, 2015, 17:04:21 »

If you're sure this is still happening on 2.9.2, could you please share some code that reproduces the problem? Also details on your system might be helpful (OS and Java version, etc)
Logged

FlukeFan

  • Newbie
  • *
  • Offline Offline
  • Posts: 8
Re: [FIXED] Right shift key gets stuck being reported as "down"
« Reply #10 on: January 05, 2015, 17:51:44 »

Thanks for pointing me to the commits related to this - it looks like the underlying OS isn't being very helpful here.

I've put together a sample (based on the one above) using lwjgl 2.9.2:  https://github.com/FlukeFan/LwjglShiftTest/blob/master/LwjglShiftTest/src/LwjglShiftTest.java

I'm using Windows 7 64-bit.
I'm using Eclipse 4.4.1 and Java 1.7.

The example code displays some text corresponding to whether each of the shift keys is up/down.  If I try pressing/releasing both shift keys together (it sometimes takes a few goes) then the Keyboard class is reporting the right-shift is down when both shift keys are up.
Logged

spasi

  • Administrator
  • Nerdus Imperius
  • *****
  • Offline Offline
  • Posts: 1782
Re: [FIXED] Right shift key gets stuck being reported as "down"
« Reply #11 on: January 05, 2015, 18:19:47 »

Thank you FlukeFan, I have reverted the second commit and it should be fine now. It was a minor optimization that made the workaround fail when the keyboard wasn't polled fast enough.
Logged

FlukeFan

  • Newbie
  • *
  • Offline Offline
  • Posts: 8
Re: [FIXED] Right shift key gets stuck being reported as "down"
« Reply #12 on: January 05, 2015, 19:26:52 »

Hi,

Thanks for such a quick update.

I tried recompiling LWJGL (but without the natives).  I dropped that into my test harness, but I'm still seeing the same behaviour.

Do I have to recompile the natives too?

Cheers,
    Richard
Logged

spasi

  • Administrator
  • Nerdus Imperius
  • *****
  • Offline Offline
  • Posts: 1782
Re: [FIXED] Right shift key gets stuck being reported as "down"
« Reply #13 on: January 05, 2015, 19:54:10 »

I tried recompiling LWJGL (but without the natives).  I dropped that into my test harness, but I'm still seeing the same behaviour.

Do I have to recompile the natives too?

No, only Java code changed. Could you please make sure that your test uses the latest commit? I cannot reproduce the issue anymore, with either the original test I was using or your code above.
Logged

FlukeFan

  • Newbie
  • *
  • Offline Offline
  • Posts: 8
Re: [FIXED] Right shift key gets stuck being reported as "down"
« Reply #14 on: January 05, 2015, 20:50:59 »

Hi,

Thanks for looking again.

I've checked and re-checked.  I added the following code at line 77 of WindowsKeyboard.java to check it was definitely going through that code, and my test harness promptly blew up when I pressed both shift keys:

Code: [Select]
        if (isKeyDown(Keyboard.KEY_LSHIFT) && isKeyDown(Keyboard.KEY_RSHIFT))
          throw new RuntimeException("blew up here!");

I took the code out again, recreated the jars (using 'ant jars'), and my test harness goes back to displaying the problem.

Note, I do have to try quite a few times to reproduce the problem - I think the 'release' of the two shift keys needs to be almost simultaneous.

Let me know if there's anything else I can do to try and help.

Cheers,
    Richard
Logged
Pages: [1] 2