5

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.

mKorbel
  • 109,525
  • 20
  • 134
  • 319
tjb300
  • 105
  • 5
  • My guess is "Windows anomaly". There could be a registry setting that affects this; when I got my desktop, the two Alt keys were behaving differently and I had a good reason for wanting them to be the same, and I found I could fix the registry to make it work. Yours is a different problem, though. – ajb Feb 12 '14 at 20:36
  • 2
    @ajb, It's also possible this is a quirk of the physical keyboard in question; Keyboard manufacturers do quite interesting things with the way keys are wired which makes key combinations not always work as expected. The keyboard might not send the "key released" signal because the manufacturer figured "hey, left is still down, why would we bother sending the release signal?" http://blogs.msdn.com/b/shawnhar/archive/2007/03/28/keyboards-suck.aspx – Brian S Feb 12 '14 at 20:53

1 Answers1

0

try the following: 1.Run the same program on some other xp/win7/win8. 2.Run the same program with completely different sets of keyboards. this might solve the issue

Saurabh Jain
  • 1,600
  • 1
  • 20
  • 30