JDK-8180411 : Holding down the A and S keys causes "key pressed" events to be suppressed on MacOS Sierra
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 8u131
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: os_x
  • CPU: x86
  • Submitted: 2017-05-14
  • Updated: 2017-05-16
  • Resolved: 2017-05-16
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :
java version "1.8.0_131"
Java(TM) SE Runtime Environment (build 1.8.0_131-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.131-b11, mixed mode)


ADDITIONAL OS VERSION INFORMATION :
MacOS Sierra v10.12.4

A DESCRIPTION OF THE PROBLEM :
I'm writing a game where the player uses the standard WASD for player movement.

But if you hold down either the A or the S keys, "key pressed" events are no longer dispatched. Note that "key released" events are still dispatched.

I can recover from this by holding down either W or D. But if I hold down A or S again, it reverts back to the behavior I just described.

This issue did not occur with El Capitan. It only started with Sierra.

As a workaround, I replaced WASD with TFGH. The game works fine now. So it's something specific about WASD.

Somebody reported this against the OpenJDK bug database, but from their java -version output, it's clear that they're using Oracle's JVM:

https://bugs.openjdk.java.net/browse/JDK-8167263

Additionally somebody reported this issue on Reddit:

https://www.reddit.com/r/mac/comments/56hbw9/mac_os_sierra_1012_java_keylistener_issue/

Finally there are a couple of StackOverflow questions describing the same thing:

http://stackoverflow.com/questions/43192166/on-mac-in-java-keypressed-event-doesnt-fire-for-certain-keys/43960171

http://stackoverflow.com/questions/39705742/java-keylistener-no-longer-triggers-keypress-event-after-a-letter-key-is-held-do


STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Write a short program to listen to KeyEvent using a KeyListener. Make it log keyPressed, keyTyped and keyReleased events to the console.
2. Try pressing (but don't hold these down) W, A, S, D.
3. Then try holding down either A or S. The keyPressed events won't happen anymore. But keyReleased will.
4. Try holding down either W or D. Now the keyPressed events will all show up again, at least til you hold down A or S again.


EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
No suppression of keyPressed events.
ACTUAL -
Suppression of keyPressed events.


ERROR MESSAGES/STACK TRACES THAT OCCUR :
No error messages or crash logs happen.

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
Try the source code here:

http://stackoverflow.com/questions/43192166/on-mac-in-java-keypressed-event-doesnt-fire-for-certain-keys/43960171

---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
I switched from WASD to TFGH. Not desirable though since games generally use WASD.



Comments
Closing this as duplicate of JDK-8167263, which is under investigation. Copied required information including test case and results to this report.
16-05-2017