Search code examples
javastringkeyeventkeycode

Java converting keycode to string or char


I want to turn keyevent keycode value into a string or a char value. Either one would do.

For example, when I press 'SPACE', which 'lets say' has a keycode 20, and I want to convert that value to a char or a string. Is there any standard way of doing so, or I have to write a bunch of 'if' statements for every key on the keyboard?


Solution

  • Cast it to Char.

    Char c=(Char)keycode;