Win a copy of The Way of the Web Tester: A Beginner's Guide to Automating Tests this week in the Testing forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

keyCode versus scancode

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