I'm writing a simulation of an old machine in Java and I'd like my keyboard handling to treat the left- and right-SHIFT keys independently.
I have a standard AWT KeyListener
registered and process the KeyPressed()
and KeyReleased()
methods. Here's the problem:
1) Press Left-SHIFT
-> get KeyPressed() for VK_SHIFT with location=LEFT ... good!
2) Keep Left-SHIFT held down, press Right-SHIFT too
-> get KeyPressed() for VK_SHIFT with location=RIGHT ... good!
3) Release Right-SHIFT (left-SHIFT still held down)
-> get ... absolutely nothing ... bad!
4) Release Left-SHIFT
-> get KeyReleased() for VK_SHIFT with location=LEFT ... good.
So, I have lost the KeyReleased()
information for right-SHIFT. This fails in this way when running on Windows, but works correctly (I see all events) on Linux. Any ideas? Is this just a Windows anomaly I have to live with. Curiously it doesn't fail like this with the two Ctrl keys—I see all events as I'd hope.
It is easy to reproduce this behaviour using the standard Sun KeyEventDemo.java
program.