Home

KEYTYPED

KeyTyped is an event type in the Java AWT and Swing event model. It represents the typing of a character by the user and is delivered after a key has been pressed and released to produce a character. It is a higher-level event than keyPressed and keyReleased and is intended for text input.

In a KeyEvent, the keyCode is meaningful for KEY_PRESSED and KEY_RELEASED, but for KEY_TYPED the keyCode is

KEY_TYPED events are commonly used with text components and for simple input handling, such as filtering or

Notes and limitations: KEY_TYPED events are not generated for non-printing keys like arrow keys or Escape, and

VK_UNDEFINED.
The
actionable
data
in
a
KEY_TYPED
event
comes
from
getKeyChar(),
which
returns
the
Unicode
character
produced
by
the
input.
The
returned
character
reflects
modifiers
such
as
Shift,
and
may
include
diacritics
or
compose
characters
when
using
input
methods.
validating
characters
as
they
are
typed.
Listeners
implement
KeyListener
and
override
keyTyped(KeyEvent
e),
or
extend
KeyAdapter.
Within
the
handler,
developers
typically
retrieve
the
character
with
e.getKeyChar()
and
decide
whether
to
accept
it
or
perform
some
action.
their
behavior
can
be
influenced
by
platform
differences
and
input
methods
(IME).
For
robust
text
handling
in
Swing,
higher-level
approaches
such
as
DocumentListener,
input
verifiers,
or
document
filters
are
often
preferred
over
low-level
key
events,
since
they
respond
to
edits
in
the
document
rather
than
individual
keystrokes.