Class KeyHandler
Object
KeyHandler
Handles global key events and delegates actions to the owning EvoLudoWeb.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static KeyHandlerController that currently has priority (typically the popup lab).private final EvoLudoWebThe EvoLudoWeb instance that owns this controller.private booleanTracks whether the Alt modifier is currently pressed.private booleanTracks whether the Shift modifier is currently pressed.static final StringString value emitted when the Alt key is pressed.static final StringString value emitted when the Backspace key is pressed.static final StringString value emitted when the Delete key is pressed.static final StringString value emitted when the Enter key is pressed.static final StringString value emitted when the Escape key is pressed.static final StringString value emitted when the Shift key is pressed.private static final List<KeyHandler> All handlers that have requested global registration.private static booleanTracks whether the global JS listeners have been installed.private booleanIndicates whether this controller has been registered globally.private static intNumber of handlers that have requested registration.private intIndex of previously active view before switching to console view. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static voidInstalls JS listeners that route keyboard events to all controllers.private static booleandispatchKeyDown(String key) Dispatches keydown events first to the active controller, then to others.private static booleandispatchKeyUp(String key) Dispatches keyup events first to the active controller, then to others.private booleanHandles key events when the command line options field is active.private booleanHandles toggling the console view.private booleanHandles the Delete and Backspace key functionality.private booleanHandles the Escape key functionality.private booleanHandles exporting the current model state.private booleanHandles toggling fullscreen mode.private booleanhandleGlobalKeys(String key) Handles global key events.private booleanHandles numeric view switching for keys 1-9.voidHides the touch-activated Alt mode and restores the original labels.booleanisActive()Check whether this controller currently receives priority for key events.booleanDetermine whether the Alt modifier key is currently engaged.booleanDetermine whether the Shift modifier key is currently engaged.booleanProcesskeydownevents to allow for repeating keyboard shortcuts.booleanProcesskeyupevents to allow for non-repeating keyboard shortcuts.voidregister()Registers the handler and installs global listeners if needed.private static voidregisterGlobal(KeyHandler handler) Registers a handler for global key event handling.private static voidRemoves the JS listeners that were installed byaddGlobalKeyListeners().private static voidsetActive(KeyHandler handler) Sets the active handler that receives priority for key events.voidMarks Alt mode active for touch interactions so button labels update accordingly.voidUnregisters the handler and removes listeners when no handlers remain.private static voidunregisterGlobal(KeyHandler handler) Unregisters a handler from global key event handling.private voidUpdates the modifier key states when keys are released.
-
Field Details
-
gui
The EvoLudoWeb instance that owns this controller. -
isAltDown
private boolean isAltDownTracks whether the Alt modifier is currently pressed. -
isShiftDown
private boolean isShiftDownTracks whether the Shift modifier is currently pressed. -
KEY_ALT
-
KEY_SHIFT
-
KEY_ENTER
-
KEY_ESCAPE
String value emitted when the Escape key is pressed.- See Also:
-
KEY_BACKSPACE
String value emitted when the Backspace key is pressed.- See Also:
-
KEY_DELETE
String value emitted when the Delete key is pressed.- See Also:
-
active
Controller that currently has priority (typically the popup lab). -
keyHandlers
All handlers that have requested global registration. -
registrationCount
private static int registrationCountNumber of handlers that have requested registration. -
listenersInstalled
private static boolean listenersInstalledTracks whether the global JS listeners have been installed. -
registered
private boolean registeredIndicates whether this controller has been registered globally. -
toggleIdx
private int toggleIdxIndex of previously active view before switching to console view.
-
-
Constructor Details
-
KeyHandler
Initializes the key event handler.- Parameters:
gui- the owning EvoLudoWeb instance
-
-
Method Details
-
register
public void register()Registers the handler and installs global listeners if needed. -
unregister
public void unregister()Unregisters the handler and removes listeners when no handlers remain. -
setActive
Sets the active handler that receives priority for key events.- Parameters:
handler- the handler to set active
-
registerGlobal
Registers a handler for global key event handling.- Parameters:
handler- the handler to register
-
unregisterGlobal
Unregisters a handler from global key event handling.- Parameters:
handler- the handler to unregister
-
showAltModeFromTouch
public void showAltModeFromTouch()Marks Alt mode active for touch interactions so button labels update accordingly. -
hideAltModeFromTouch
public void hideAltModeFromTouch()Hides the touch-activated Alt mode and restores the original labels. -
dispatchKeyDown
Dispatches keydown events first to the active controller, then to others.- Parameters:
key- the key value reported by the browser event- Returns:
trueif any controller consumed the event
-
dispatchKeyUp
Dispatches keyup events first to the active controller, then to others.- Parameters:
key- the key value reported by the browser event- Returns:
trueif any controller consumed the event
-
onKeyDown
Processkeydownevents to allow for repeating keyboard shortcuts. Use for events where repeating does make sense, such as advancing a model by a single step or changing the speed of the model execution by adjusting the delay between subsequent updates. For non-repeating events, such starting or stopping the model or changing the view, seeonKeyUp(String). The set of keys handled byonKeyUpandonKeyDownshould be disjoint.Implementation Notes:
keydownevents are ignored if:- this EvoLudo model is not visible.
- in an ePub, except when on a standalone page.
keydownevents do not propagate further (stopPropagation()is always called).- returning
truealso prevents default behaviour (callspreventDefault()).
Global shortcuts provided for the following keys:
Alt- Toggles the mode for some buttons. For example to switch between
InitandReset. Shift- Toggles the mode for some keys, see
Enterbelow for an example. ArrowRight, n- Advance the model by a single step. Same as pressing the
Step-button. +, =- Increase the speed of the model execution. Decrease the delay between updates. Moves the speed-slider to the right.
-- Decrease the speed of the model execution. Increase the delay between updates. Moves the speed-slider to the right.
- Parameters:
key- the string value of the pressed key- Returns:
trueif key has been handled- See Also:
-
onKeyUp
Processkeyupevents to allow for non-repeating keyboard shortcuts. Use for events where repeating does not make sense, such as stopping a model or changing views. For repeating events, such as advancing the model by a single step, seeonKeyDown(String). The set of keys handled byonKeyUpandonKeyDownshould be disjoint.Implementation Notes:
keyupevents are ignored if:- this EvoLudo model is not visible.
- the command line options field has the focus. With
the exception of
Shift-Enterto apply the new settings to the model. - in an ePub, except when on a standalone page.
keyupevents do not propagate further (stopPropagation()is always called).- returning
truealso prevents default behaviour (callspreventDefault()).
keyupevents are ignored if:- this EvoLudo model is not visible.
- the command line options field has the focus. With
the
exception of
Shift-Enter, which applies the new settings to the model. - when shown in an ePub, except when on a standalone page.
keydownevent does not propagate further.- returning
truealso prevents default behaviour.
Global shortcuts provided for the following keys:
Alt- Toggles the mode for some buttons. For example to switch between
InitandReset. Shift- Toggles the mode for some keys, see
Enterbelow for an example. 0- Toggles the visibility of the field to view and modify parameter settings.
1-9- Quick view selector. Switches to data view with the selected index if it
exists.
1is the first view etc. Enter, Space- Starts (or stops) the current model. Note,
Shift-Enterapplies the new parameter settings if the field is visible and has the keyboard focus. Same as pressing theApply-button. Escape- Implements several functions depending on context:
- Ignored in ePub.
- Closes current EvoLudo simulation if running in a
EvoLudoTriggerpopup panel. - Stops any running model.
- Initializes a model that is not running. Note, resets the model if
Altis pressed.
Backspace, Delete- Stops running models and initializes (resets if
Altis pressed) stopped models. E- Export the current state of the model (as a modified
plist). Ignored if model is running and in ePubs. H- Show the help screen with brief descriptions of all parameters in the console view.
- Parameters:
key- the string value of the released key- Returns:
trueif key has been handled- See Also:
-
updateModifierStates
Updates the modifier key states when keys are released.- Parameters:
key- the released key
-
handleCLOActiveKeys
Handles key events when the command line options field is active.- Parameters:
key- the released key- Returns:
trueif key has been handled
-
handleGlobalKeys
Handles global key events.- Parameters:
key- the released key- Returns:
trueif key has been handled
-
handleNumericViewSwitch
Handles numeric view switching for keys 1-9.- Parameters:
key- the released key- Returns:
trueif key has been handled
-
handleConsoleToggle
private boolean handleConsoleToggle()Handles toggling the console view.- Returns:
trueif key has been handled
-
handleEscapeKey
private boolean handleEscapeKey()Handles the Escape key functionality.- Returns:
trueif key has been handled
-
handleDeleteKeys
private boolean handleDeleteKeys()Handles the Delete and Backspace key functionality.- Returns:
trueif key has been handled
-
handleExport
private boolean handleExport()Handles exporting the current model state.- Returns:
trueif key has been handled
-
handleFullscreen
private boolean handleFullscreen()Handles toggling fullscreen mode.- Returns:
trueif key has been handled
-
addGlobalKeyListeners
private static void addGlobalKeyListeners()Installs JS listeners that route keyboard events to all controllers. -
removeGlobalKeyListeners
private static void removeGlobalKeyListeners()Removes the JS listeners that were installed byaddGlobalKeyListeners(). -
isActive
public boolean isActive()Check whether this controller currently receives priority for key events.- Returns:
trueif this controller currently receives priority for key events.
-
isAltDown
public boolean isAltDown()Determine whether the Alt modifier key is currently engaged.- Returns:
trueif the Alt modifier is currently engaged.
-
isShiftDown
public boolean isShiftDown()Determine whether the Shift modifier key is currently engaged.- Returns:
trueif the Shift modifier is currently engaged.
-