Reputation: 28905
How can I convert KeyEvent.VK_SPACE
(which is an integer) to an actual space?
String space = convertKeyEvent(KeyEvent.VK_SPACE);
System.out.println("Space=" + space + ".");
This should output
Space= .
And although this example uses Space, it should be a general converter for other characters as well, such as VK_0.
WHAT I HAVE TRIED
Note that this DOES NOT work:
String space = KeyEvent.getKeyText(KeyEvent.VK_SPACE);
System.out.println("Space=" + space + ".");
In Eclipse, this outputs:
Space=?.
Upvotes: 1
Views: 3555
Reputation: 2575
well - uh - did you once look at the actual value of VK_SPACE
? It is 0x20 - that is the actual ASCII-value of space - that should give you some hint ;)
try:
char space = (char)VK_SPACE;
Upvotes: 2
Reputation: 297
public static String convert(int keyEvent){
if(keyEvent == 32){
return " ";
}
return null;
}
public static void main(String [] arg){
System.out.println("Space=" + convert(KeyEvent.VK_SPACE) + ".");
}
Upvotes: 0