Class Keyboard


  • public class Keyboard
    extends java.lang.Object
    Utility class that provides methods for simulating keyboard events.
    • Constructor Summary

      Constructors 
      Constructor Description
      Keyboard()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void eraseUntil​(java.util.function.Supplier<java.lang.Boolean> supplier, int timeout)
      Erases text until the given condition is met or the timeout is reached.
      static void holdKeyCodeUntil​(int keyCode, java.util.function.Supplier<java.lang.Boolean> supplier, int timeout)
      Holds the specified key code until the supplier condition is met or the timeout is reached.
      static void pressBackspace()
      Presses the Backspace key on the keyboard.
      static void pressEnter()
      Presses the enter key.
      static void pressEscape()
      Presses the escape key on the keyboard.
      static void pressKeyCodeUntil​(int keyCode, java.util.function.Supplier<java.lang.Boolean> supplier, int timeout)
      Presses a specified key code until a condition provided by the supplier is met, with a specified timeout.
      static void pressSpace()
      Presses the space key on the keyboard.
      static void sendFKey​(FKeys fKey)
      Sends a function key event to the client.
      static void sendKey​(char character)
      Sends the given character as a key press event with a delay of 0 milliseconds.
      static void sendKey​(char character, int keyPressModifier)
      Sends a key press, key typed, and key release event corresponding to a given character and key press modifier.
      static void sendKeyEvent​(java.awt.AWTEvent event)
      Passes a key event to the client.
      static void setInputText​(java.lang.String text, boolean enter)
      Sets the input text in the Runescape client and optionally sends an Enter key press.
      static void type​(java.lang.String text, boolean enter)
      Types the given text with the option to press the enter key afterwards.
      static void type​(java.lang.String text, boolean enter, int delay)
      Types the specified text, followed by pressing the enter key if specified, with the given delay.
      static void type​(java.lang.String text, boolean enter, java.util.function.IntSupplier delaySupplier)
      Types the given text, with optional delay between each character and the option to press enter afterwards.
      static void typeUntil​(java.lang.String text, boolean enter, java.util.function.Supplier<java.lang.Boolean> supplier, int timeout)
      Types the specified text until the given condition is met or a timeout occurs.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Keyboard

        public Keyboard()
    • Method Detail

      • sendKeyEvent

        public static void sendKeyEvent​(java.awt.AWTEvent event)
        Passes a key event to the client.
        Parameters:
        event - the AWT event representing the key event.
      • sendKey

        public static void sendKey​(char character)
        Sends the given character as a key press event with a delay of 0 milliseconds.
        Parameters:
        character - the character to be sent as a key press event
      • sendKey

        public static void sendKey​(char character,
                                   int keyPressModifier)
        Sends a key press, key typed, and key release event corresponding to a given character and key press modifier.
        Parameters:
        character - the character to be typed
        keyPressModifier - the key press modifier (e.g. shift, alt)
      • pressKeyCodeUntil

        public static void pressKeyCodeUntil​(int keyCode,
                                             java.util.function.Supplier<java.lang.Boolean> supplier,
                                             int timeout)
        Presses a specified key code until a condition provided by the supplier is met, with a specified timeout.
        Parameters:
        keyCode - the key code to be pressed
        supplier - the condition to be met by the keystrokes
        timeout - the maximum time in milliseconds to wait for the condition to be met
      • holdKeyCodeUntil

        public static void holdKeyCodeUntil​(int keyCode,
                                            java.util.function.Supplier<java.lang.Boolean> supplier,
                                            int timeout)
        Holds the specified key code until the supplier condition is met or the timeout is reached.
        Parameters:
        keyCode - the key code to hold
        supplier - a supplier that determines the condition
        timeout - the maximum duration to hold the key (in milliseconds)
      • eraseUntil

        public static void eraseUntil​(java.util.function.Supplier<java.lang.Boolean> supplier,
                                      int timeout)
        Erases text until the given condition is met or the timeout is reached.
        Parameters:
        supplier - a supplier that returns a boolean indicating the condition to be met
        timeout - the maximum amount of time to wait for the condition to be met (in milliseconds)
      • pressEnter

        public static void pressEnter()
        Presses the enter key.
      • pressSpace

        public static void pressSpace()
        Presses the space key on the keyboard.
      • pressEscape

        public static void pressEscape()
        Presses the escape key on the keyboard.
      • pressBackspace

        public static void pressBackspace()
        Presses the Backspace key on the keyboard.
      • sendFKey

        public static void sendFKey​(FKeys fKey)
        Sends a function key event to the client.
        Parameters:
        fKey - the function key to be sent
      • type

        public static void type​(java.lang.String text,
                                boolean enter)
        Types the given text with the option to press the enter key afterwards.
        Parameters:
        text - the text to be typed
        enter - true to press the enter key afterwards, false otherwise
      • type

        public static void type​(java.lang.String text,
                                boolean enter,
                                int delay)
        Types the specified text, followed by pressing the enter key if specified, with the given delay.
        Parameters:
        text - the text to be typed
        enter - true if the enter key should be pressed, false otherwise
        delay - the delay in milliseconds between each key press
      • type

        public static void type​(java.lang.String text,
                                boolean enter,
                                java.util.function.IntSupplier delaySupplier)
        Types the given text, with optional delay between each character and the option to press enter afterwards.
        Parameters:
        text - the text to be typed
        enter - true if the enter key should be pressed after typing, false otherwise
        delaySupplier - a supplier providing the delay in milliseconds between each character
      • typeUntil

        public static void typeUntil​(java.lang.String text,
                                     boolean enter,
                                     java.util.function.Supplier<java.lang.Boolean> supplier,
                                     int timeout)
        Types the specified text until the given condition is met or a timeout occurs.
        Parameters:
        text - the text to be typed
        enter - true if Enter key should be pressed after typing, false otherwise
        supplier - a supplier supplying a boolean value indicating whether to stop typing or not
        timeout - the maximum time (in milliseconds) to wait for the condition to be met before timing out
      • setInputText

        public static void setInputText​(java.lang.String text,
                                        boolean enter)
        Sets the input text in the Runescape client and optionally sends an Enter key press.
        Parameters:
        text - the text to set as input
        enter - true if an Enter key press should be sent, false otherwise