Java converting keycode to string or char

user2098268 picture user2098268 · Apr 13, 2013 · Viewed 17.8k times · Source

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?

Answer

bluevoid picture bluevoid · Apr 13, 2013

Cast it to Char.

Char c=(Char)keycode;