Class KeyUpEvent
This event is triggered when a user releases a previously pressed key on the keyboard. KeyUpEvent is the final event in the keyboard event sequence (keydown, keypress, keyup) and fires once per key release, regardless of how long the key was held down. This event is commonly used for detecting the end of a key press, implementing key combinations, and stopping continuous actions that began on key down.
Features:
- Fires when a key is released (final event in sequence)
- Fires once per key release (does not repeat)
- Provides key code, character code, and which key information
- Supports detection of all keys including non-printable keys
Usage: Handle this event through a KeyListener to respond to key releases. Common use cases include ending continuous actions (e.g., stopping movement when arrow key is released), implementing key combinations, and detecting complete key press cycles.
public class GameControlHandler implements KeyListener {
@Override
public void onEvent(KeyDownEvent event) {
int keyCode = event.getKeyCode();
if (keyCode == 32) { // Space key
startJumping();
}
}
@Override
public void onEvent(KeyUpEvent event) {
int keyCode = event.getKeyCode();
if (keyCode == 32) { // Space key released
stopJumping();
}
}
@Override
public void onEvent(KeyPressedEvent event) { }
}
- Since:
- 2007
- Version:
- 1.0
- Author:
- Marvin P. Warble Jr.
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionKeyUpEvent(String keyCode, String charCode, String which) Constructs a new KeyUpEvent with the specified key information. -
Method Summary
Modifier and TypeMethodDescriptionvoiddispatchTo(KeyListener listener) Dispatches this event to the specified listener.Methods inherited from class com.oorian.messaging.events.client.KeyEvent
getCharCode, getKeyCode, getWhichMethods inherited from class com.oorian.messaging.events.client.ClientEvent
getSource, getTarget, setSource, setTarget
-
Constructor Details
-
KeyUpEvent
Constructs a new KeyUpEvent with the specified key information.Creates a key up 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
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(KeyUpEvent) method.
- Specified by:
dispatchToin classEvent<KeyListener>- Parameters:
listener- the KeyListener that will handle this event
-