0

I'm trying to find some way to get the char or its key through an ActionEvent's KeyEvent. I don't even know in which class I could find such a method.

Actually I have some old code containing hundred of lines of code, where we could map keycodes to characters, but it's a real pain, since different devices and languages mean special cases. I really want to avoid that.

Regards.

mdelolmo
  • 6,417
  • 3
  • 40
  • 58

1 Answers1

1

Just cast the keyCode integer to a char to get the actual character value. For a keypad you will always get numbers and for a qwerty device you will get letters.

Shai Almog
  • 51,749
  • 5
  • 35
  • 65
  • That's interesting, but in our case, the ActionEvent returns always `keyEvent=-1` , whatever key we pressed. At least this is what the Netbeans debugger shows, running the WTK2.5.2_01 emulator. – mdelolmo Aug 25 '11 at 11:22
  • Since my comment it's about a different issue, I'll accept your answer, Shai – mdelolmo Aug 25 '11 at 20:21
  • The keyCode is -1 if you receive the action event via a command since the command code is agnostic and doesn't "know" if an action was initiated due to a key or a pointer event (nor should it). The key code would be valid for a keyEvent registered via a listener to the form or similar events. – Shai Almog Aug 28 '11 at 05:08