A much more elegant way to play with keyCodes which also reduces bug-probability (forgotten break:P) is this:
switch (keyCode) {
case 38: // Up
break;
case 40: // Down
break;
case 37: // Left
break;
case 39: // Right
break;
default:
System.out.println("case " + keyCode + ": // " + KeyEvent.getKeyText(keyCode) + "\nbreak;");
}
Example output:
case 112: // F1
break;
case 113: // F2
break;
case 69: // E
break;
case 10: // Enter
break;
case 18: // Alt
break;
case 115: // F4
break;
You might want to put that line into a method.
You could also be interested in this method (which uses reflection) that obtains the scancode, a keyboard language layout independent key value, but this only works on Windows. It's quite sad that we don't get simple "This is the hardware key, and that is the number that identifies it." information in Java. :(