Record Class KeyStroke

java.lang.Object
java.lang.Record
com.botwithus.bot.api.input.KeyStroke
Record Components:
keyCode - Jagex key code, -32768..32767, or NO_KEY_CODE
keyChar - CP1252 character, 0..65535, or NO_KEY_CHAR

public record KeyStroke(int keyCode, int keyChar) extends Record
One key event delivered to a component's key (type-10) CS2 trigger — the argument the trigger's script reads as its key code and key character.

The engine delivers a real keystroke as two events: a key-down carrying the code with no character, then a character event carrying the character with no code. Input fields read the two halves differently, and a stroke that carries the wrong half does nothing:

  • a printable character is taken from the character half, so type it as character(char) ((-1, c)); a key-down alone appends nothing;
  • a control key is taken from the code half, so send ENTER, BACKSPACE or ESCAPE ((code, 0)); a character 13 alone does not submit.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final KeyStroke
    Deletes the character before the caret.
    static final int
    Jagex key code for Backspace.
    static final int
    Jagex key code for Enter.
    static final int
    Jagex key code for Escape.
    static final KeyStroke
    Submits an input field.
    static final KeyStroke
    Cancels an input dialog.
    static final int
    keyChar() of a stroke that carries only a key code.
    static final int
    keyCode() of a stroke that carries only a character.
  • Constructor Summary

    Constructors
    Constructor
    Description
    KeyStroke(int keyCode, int keyChar)
    Creates an instance of a KeyStroke record class.
  • Method Summary

    Modifier and Type
    Method
    Description
    static KeyStroke
    character(char c)
    A character event typing c: (-1, c).
    final boolean
    Indicates whether some other object is "equal to" this one.
    final int
    Returns a hash code value for this object.
    int
    Returns the value of the keyChar record component.
    int
    Returns the value of the keyCode record component.
    static int
    keyTriggerArg(int arg)
    The wire argument for a key trigger fired through GameAPI.fireComponentTrigger(int, int, int, int, int), which accepts two forms.
    int
    The trigger argument this stroke travels as: (keyCode << 16) | keyChar, the code sign-carried in the high half.
    final String
    Returns a string representation of this record class.

    Methods inherited from class Object

    getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • NO_KEY_CODE

      public static final int NO_KEY_CODE
      keyCode() of a stroke that carries only a character.
      See Also:
    • NO_KEY_CHAR

      public static final int NO_KEY_CHAR
      keyChar() of a stroke that carries only a key code.
      See Also:
    • CODE_ENTER

      public static final int CODE_ENTER
      Jagex key code for Enter.
      See Also:
    • CODE_BACKSPACE

      public static final int CODE_BACKSPACE
      Jagex key code for Backspace.
      See Also:
    • CODE_ESCAPE

      public static final int CODE_ESCAPE
      Jagex key code for Escape.
      See Also:
    • ENTER

      public static final KeyStroke ENTER
      Submits an input field.
    • BACKSPACE

      public static final KeyStroke BACKSPACE
      Deletes the character before the caret.
    • ESCAPE

      public static final KeyStroke ESCAPE
      Cancels an input dialog.
  • Constructor Details

    • KeyStroke

      public KeyStroke(int keyCode, int keyChar)
      Creates an instance of a KeyStroke record class.
      Parameters:
      keyCode - the value for the keyCode record component
      keyChar - the value for the keyChar record component
  • Method Details

    • character

      public static KeyStroke character(char c)
      A character event typing c: (-1, c). Printable ASCII only, because that is the range where a Java char and the CP1252 byte the game reads are the same number; build the record directly for anything else.
      Throws:
      IllegalArgumentException - when c is not printable ASCII
    • keyTriggerArg

      public static int keyTriggerArg(int arg)
      The wire argument for a key trigger fired through GameAPI.fireComponentTrigger(int, int, int, int, int), which accepts two forms. An arg whose high half is zero (0..0xFFFF) is a bare key code, as that method has always documented, and becomes a key-down (arg << 16) | 0. Any other arg is already packed() and passes through unchanged. The two cannot be confused: the engine never produces key code 0, and a character event carries NO_KEY_CODE, so its high half is 0xFFFF.
    • packed

      public int packed()
      The trigger argument this stroke travels as: (keyCode << 16) | keyChar, the code sign-carried in the high half.
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with the compare method from their corresponding wrapper classes.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • keyCode

      public int keyCode()
      Returns the value of the keyCode record component.
      Returns:
      the value of the keyCode record component
    • keyChar

      public int keyChar()
      Returns the value of the keyChar record component.
      Returns:
      the value of the keyChar record component