This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

keyCode versus scancode  RSS feed

Joe Vahabzadeh
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I've come across something of an interesting problem.

I'm working with Swing, and getting KeyEvents, dealing primarily with keyPressed and keyReleased events, though not using keyTyped at this time for any purpose.

Here's the thing: Java's got its own keyCode values that you can retrieve from any keyPressed or keyReleased event. Is there a way to get the original scan code?

I assume that the way Java works is that it gets a scan code native to the hardware, and translates it through some means to one of the various KeyEvent.VK_... values.

Unfortunately, there's some weird flaws. For example, on a Japanese keyboard, the key right next to the right-SHIFT key (forward slash) and the key right next to the Backspace key (Yen symbol) both have the same keyCode in a keyPressed or keyReleased event. However, the scan codes that were generated at the hardware/BIOS level are different. Is there any way that I can get Java to give me that original code? I need to be able to differentiate between these two WITHOUT looking at a keyTyped event.

Is what I'm asking possible? If not, is there any other way to differentiate between those two keys that generate the same scan-code without looking at the keyTyped event?

Thanks in advance.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!