Class Keyboard


  • public class Keyboard
    extends java.lang.Object
    Keyboard API class.
    • Constructor Detail

      • Keyboard

        public Keyboard()
    • Method Detail

      • getKeyboardTypingAlgorithm

        public static KeyboardTypingAlgorithm getKeyboardTypingAlgorithm()
        Keyboard typing algorithm, handles the actual typing implementations
      • getCurrentModifiers

        public static int getCurrentModifiers()
        Currently held down modifiers, shift, ctrl, alt, etc Use bitwise checks on events like InputEvent.SHIFT_MASK to check if modifier is active
      • isPressed

        public static boolean isPressed​(Key key)
        Checks if a key is pressed
        Parameters:
        key - Key key to check
        Returns:
        true if pressed, else false
      • markPressed

        public static void markPressed​(Key key)
        Marks the given Key as pressed. Primarily for internal usage. Also marks this key as held with markHeld(Key, boolean)
        Parameters:
        key - Key to mark as pressed
      • markReleased

        public static void markReleased​(Key key)
        Marks a given Key as released. Primarily for internal usage. Also marks this key as not held with markHeld(Key, boolean)
        Parameters:
        key - Key to mark as released
      • isHeld

        public static boolean isHeld​(Key key)
        Checks if a given Key is currently being held
        Parameters:
        key - Key to check
        Returns:
        true if held, else false
      • markHeld

        public static void markHeld​(Key key,
                                    boolean held)
        Marks the Key as being held, does NOT send any events.
        Parameters:
        key - Key to mark
        held - true if you want it to be marked as held, else false
      • closeInterfaceWithEsc

        public static boolean closeInterfaceWithEsc()
        If closing interfaces with esc is enabled in the game, this will close interfaces with the esc key
        Returns:
        false if esc close not enabled, else true
      • type

        public static boolean type​(java.lang.Object message)
        Types out a given message, will press enter at the end if successful
        Parameters:
        message - message to type
        Returns:
        true if completes successfully, else false
      • type

        public static boolean type​(java.lang.Object message,
                                   boolean enter)
        Types out a given message, optionally pressing enter
        Parameters:
        message - message to type
        enter - whether to press enter at the end if successful or not
        Returns:
        true if completes successfully, else false
      • type

        public static boolean type​(java.lang.Object message,
                                   boolean enter,
                                   Condition stop)
        Types out a given message, optionally pressing enter Uses a stop Condition that will cause the typing to be interrupted and stopped. In interruption, enter will not be pushed.
        Parameters:
        message - message to type
        enter - whether to press enter at the end if successful or not
        stop - stop Condition to interrupt typing
        Returns:
        true if completes successfully, else false
      • type

        public static void type​(java.lang.Object message,
                                boolean enter,
                                boolean makeMistakes)
        Types out a given message, optionally pressing enter and optionally making mistakes
        Parameters:
        message - message to type
        enter - whether to hit enter or not when typing successfully completes
        makeMistakes - whether to have a chance of making mistakes or not during typing
      • typeKey

        public static boolean typeKey​(int keyCode)
        Types a Key based on the keyCode passed in. Handles the full press, type(if necessary), release Defaults to not push enter. Examples: KeyEvent.VK_F1 Recommended to use typeKey(Key) instead.
        Parameters:
        keyCode - keyCode to press
        Returns:
        true if successfully finds a Key and types it, else false
      • typeKey

        public static boolean typeKey​(Key key)
        Types a Key Handles the full press, type(if necessary), release Defaults to not push enter.
        Parameters:
        key - Key to press
        Returns:
        True if key is not null and is typed successfully, else false
      • pressEsc

        public static void pressEsc()
        Presses the ESC key Handles full press/release
      • holdKey

        public static void holdKey​(Key key,
                                   Condition release,
                                   long timeout)
        Submits a new HoldKey with a given Key until the given Condition.verify() returns true or the passed in timeout is reached. see Key.getDefaultLocation() for default key locations Can be canceled using markHeld(Key, boolean) with false This method is threaded and will return after a 10ms sleep If the key is already marked as held, it will not create a new hold key thread
        Parameters:
        key - Key to hold
        release - Condition for when to release the key
        timeout - timeout for holding the key
      • holdSpace

        public static void holdSpace​(Condition release,
                                     long timeout)
        Holds Key.SPACE until the given Condition.verify() returns true or the given timeout is reached Can be canceled using markHeld(Key, boolean) with false
        Parameters:
        release - Condition for when to release the space key
        timeout - timeout for holding the space key
      • releaseKey

        public static void releaseKey​(Key key)
        Releases a Key if it marked as pressed or held
        Parameters:
        key -
      • releaseChar

        public static void releaseChar​(char character)
        Creates and runs a ReleaseEvent on a character. Does NOT verify if that character was currently being held or not.
        Parameters:
        character - character to release
      • loseFocus

        public static void loseFocus()
        Emulates alt+tabbing to lose focus on the client Ignored if client currently does not have focus
      • gainFocus

        public static void gainFocus()
        Emulates alt+tabbing to gain focus on the client Ignored if client already has focus