Hi all, first post here. New game programmer in general.
I'm working on a chat bar currently for a simple game project, and have run into an issue with KeyEvent processing.
Here is a snippet of relevant code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| public void keyTyped(KeyEvent e) { switch(e.getKeyCode()) { case KeyEvent.VK_LEFT: if(textCursorIndex > 0) setTextCursorIndex(textCursorIndex-1); break; case KeyEvent.VK_RIGHT: if(textCursorIndex < text.length()) setTextCursorIndex(textCursorIndex+1); break; case KeyEvent.VK_BACK_SPACE: if(textCursorIndex > 0) { textCursorIndex--; removeChar(); } case KeyEvent.VK_DELETE: if(textCursorIndex < text.length()) { removeChar(); } break; default: insertChar(text, e.getKeyChar(), textCursorIndex); break; } } |
This works just fine on my Vaio, however, I am primarily working on an iMac with a nonstandard keyboard, and my "delete" key does not send a VK_DELETE or VK_BACKSPACE event. The value for e.getKeyCode() when I press "delete" during debugging is "0", which is shared with spacebar. If somebody could tell me how to account for nonstandard keyboards in key handling code, I would greatly appreciate it.
Thanks!