[FIXED] Right shift key gets stuck being reported as "down"

Started by avm1979, October 19, 2013, 17:31:17

Previous topic - Next topic

avm1979

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:
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()
         });
	}
}


spasi


avm1979


spasi

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


FlukeFan

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

spasi

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

FlukeFan

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.

spasi

Quote from: FlukeFan on January 05, 2015, 16:33:56isKeyPressed still returns true for one of them (the right shift).

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

Quote from: FlukeFan on January 05, 2015, 16:33:56I'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.

spasi

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)

FlukeFan

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.

spasi

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.

FlukeFan

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

spasi

Quote from: FlukeFan on January 05, 2015, 19:26:52I 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.

FlukeFan

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:

        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