Class Keyboard


  • public class Keyboard
    extends Object
    Provides operations related to the Keyboard. Please note that this should only be used when necessary. In most cases there are better alternatives, such as invoking CS2 via Game.ScriptExecutor.
    • Constructor Detail

      • Keyboard

        public Keyboard()
    • Method Detail

      • sendText

        public static void sendText​(String text,
                                    boolean pressEnter)
        Sends a sequence of characters as keyboard input.

        Each character in the provided string is dispatched as a key typed event. Optionally, the Enter key can be pressed after the input.

        Parameters:
        text - the text to send as keyboard input
        pressEnter - true to press the Enter key after sending the text, false otherwise
        Throws:
        IllegalArgumentException - if text is null
      • pressEnter

        public static void pressEnter()
        Presses the Enter key.

        This method dispatches both KEY_PRESSED and KEY_RELEASED events for the Enter key.

      • sendKey

        public static void sendKey​(char key)
        Sends a single character as keyboard input.

        This method dispatches a KEY_TYPED event for the given character.

        Parameters:
        key - the character to send as input
      • pressEventKey

        public static void pressEventKey​(int eventKey)
        Presses and releases a key specified by its key code.

        This method dispatches both KEY_PRESSED and KEY_RELEASED events for the specified key code.

        Parameters:
        eventKey - the key code of the key to press