Class SequenceTrigger

All Implemented Interfaces:
Serializable

public class SequenceTrigger extends DomEventTrigger
Fires when a specific ordered sequence of keys is pressed on the host's root element — e.g. the konami code or a "hello" Easter egg. State is tracked client-side; only a complete match produces a server-side fire, so partial progress never crosses the network.

Example:


 new SequenceTrigger(layout, Key.KEY_H, Key.KEY_E, Key.KEY_L, Key.KEY_L,
         Key.KEY_O).triggers(action);
 

Listens on keydown. Each key in the sequence matches against event.key or event.code, so both event.key-named keys (e.g. Key.ENTER) and event.code-named keys (e.g. Key.KEY_S) work. Pressing a wrong key resets the position to 0; if that wrong key happens to match position 0 of the sequence, the position advances to 1 (so "abab" on a sequence configured as "abab" completes correctly). There is no timeout — a partial sequence persists across arbitrarily long gaps until either it completes or a non-matching key arrives.

Inherits DomEventTrigger.preventDefault() and DomEventTrigger.stopPropagation() from DomEventTrigger but does not apply them by default — sequences typically share keys with normal typing and should not swallow every keystroke.

For internal use only. May be renamed or removed in a future release.

See Also:
  • Constructor Details

    • SequenceTrigger

      public SequenceTrigger(Component host, Key... sequence)
      Creates a sequence trigger that fires when the given keys are pressed in order on keydown.
      Parameters:
      host - the component whose root element listens for the sequence, not null
      sequence - the keys to match, in order; must contain at least one key, none of the entries null
  • Method Details

    • appendInstallPrelude

      protected void appendInstallPrelude(StringBuilder prelude)
      Description copied from class: DomEventTrigger
      Hook for subclasses to inject JavaScript that runs once per install, before the const h = e => {...} wrapper is created. Use this to declare closure variables (e.g. let i = 0; for sequence tracking) that the wrapper body then captures by lexical scope.

      The prelude has access to the same captures as the rest of the install JS — $0 is the action, $1 is the event name, and any extras added via DomEventTrigger.appendHandlerBody(java.lang.StringBuilder, java.util.List<java.lang.Object>) appear at $2+. The base implementation is empty.

      Overrides:
      appendInstallPrelude in class DomEventTrigger
      Parameters:
      prelude - the prelude buffer; statements appended here run before the wrapper is created and remain in scope inside it
    • appendHandlerBody

      protected void appendHandlerBody(StringBuilder body, List<Object> extraCaptures)
      Description copied from class: DomEventTrigger
      Hook for subclasses to contribute statements to the wrapper handler body and extra captures referenced by those statements. The base implementation appends e.preventDefault(); and e.stopPropagation(); when the corresponding flags are set.

      Subclasses overriding this method typically prepend their own guard statements (and call super.appendHandlerBody afterwards) so the guard runs before preventDefault — preventing the default action on events the guard would have rejected would be wrong. Each entry added to extraCaptures is appended after the event name capture, so the first extra is referenced as $2 in the body, the next as $3, and so on.

      Overrides:
      appendHandlerBody in class DomEventTrigger
      Parameters:
      body - the wrapper body so far; statements appended here run inside the const h = e => { ... $0(e); } wrapper, in order, with the event available as e
      extraCaptures - mutable list of captures appended after the event-name capture ($1); the first capture added is $2, etc.