Section 12.17 Key Event Handling

• Interface KeyListener (p. 494) is used to handle key events (p. 494) that are generated when keys on the keyboard are pressed and released. Method addKeyListener of class Component (p. 525) registers a KeyListener.

KeyEvent (p. 494) method getKeyCode (p. 528) gets the virtual key code (p. 528) of the pressed key. Class KeyEvent contains virtual key-code constants that represent every key on the keyboard.

KeyEvent method getKeyText (p. 528) returns a string containing the name of the pressed key.

KeyEvent method getKeyChar (p. 528) gets the Unicode value of the character typed.

KeyEvent method isActionKey (p. 528) determines whether the key in an event was an action key (p. 525).

InputEvent method ...

Get Java™ How To Program (Early Objects), Tenth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.