keyTyped、keyPressed、keyRelease的区别

keyPressed(): when the key goes down
keyReleased(): when the key comes up
keyTyped(): when the unicode character represented by this key is sent by the keyboard to system input.
KeyPressed是键被按下,KeyReleased是键被弹起,这两个都是更底层一些的事件。
KeyTyped是指有字符被输入,比如按住shift,再按A键,如果当时Caps Lock不亮,就产生一个输入大写A的事件。

If you want to get a immediate response, whether or not a character, use keyPressed().

If you want to get a single command, whether or not a character, you’d better use keyReleased().

If you want to input only a character and hit again and again while holding the key, then you use keyTyped().

KEY_TYPED
public static final int KEY_TYPED
The “key typed” event. This event is generated when a character is entered. In the simplest case, it is produced by a single key press. Often, however, characters are produced by series of key presses, and the mapping from key pressed events to key typed events may be many-to-one or many-to-many.


KEY_PRESSED
public static final int KEY_PRESSED
The “key pressed” event. This event is generated when a key is pushed down.


KEY_RELEASED
public static final int KEY_RELEASED
The “key released” event. This event is generated when a key is let up.