Class KeyPressedEvent


@Deprecated public class KeyPressedEvent extends KeyEvent
Deprecated.
Use KeyDownEvent instead. The browser keypress event is deprecated.
Event fired when a key is pressed (deprecated browser event).

This event corresponds to the browser's keypress event, which historically fired between keydown and keyup events for printable characters. However, this event type has been deprecated in modern browsers and is no longer recommended for use. Modern applications should use KeyDownEvent instead for detecting key presses. This class is maintained for backward compatibility with legacy code.

Features:

  • Historically fired for printable character keys
  • Provided character code information
  • Deprecated in favor of KeyDownEvent
  • Maintained for backward compatibility

Usage: While this event is still supported for backward compatibility, new code should use KeyDownEvent instead. KeyDownEvent provides more comprehensive key detection including special keys, modifier keys, and all printable characters.


 // Deprecated approach
 public void onEvent(KeyPressedEvent event) {
     // Handle key press
 }

 // Recommended modern approach
 public void onEvent(KeyDownEvent event) {
     int keyCode = event.getKeyCode();
     // Handle key down with full key support
 }
 
Since:
2007
Version:
1.0
Author:
Marvin P. Warble Jr.
See Also:
  • Constructor Details

    • KeyPressedEvent

      @Deprecated public KeyPressedEvent(String keyCode, String charCode, String which)
      Deprecated.
      Use KeyDownEvent constructor instead
      Constructs a new KeyPressedEvent with the specified key information.

      Creates a key pressed event with key code, character code, and which key information from the browser's keyboard event.

      Parameters:
      keyCode - the key code as a string (will be parsed to integer)
      charCode - the character code as a string (will be parsed to integer)
      which - the which key value as a string
  • Method Details

    • dispatchTo

      public void dispatchTo(KeyListener listener)
      Deprecated.
      Dispatches this event to the specified listener.

      This method implements the visitor pattern to deliver the event to the appropriate handler method on the KeyListener. It calls the listener's onEvent(KeyPressedEvent) method.

      Specified by:
      dispatchTo in class Event<KeyListener>
      Parameters:
      listener - the KeyListener that will handle this event