Class Keyboard
- java.lang.Object
-
- net.eternalclient.api.wrappers.input.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.
-
-
-
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 typedkeyPressModifier
- 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 pressedsupplier
- the condition to be met by the keystrokestimeout
- 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 holdsupplier
- a supplier that determines the conditiontimeout
- 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 mettimeout
- 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 typedenter
- 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 typedenter
- true if the enter key should be pressed, false otherwisedelay
- 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 typedenter
- true if the enter key should be pressed after typing, false otherwisedelaySupplier
- 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 typedenter
- true if Enter key should be pressed after typing, false otherwisesupplier
- a supplier supplying a boolean value indicating whether to stop typing or nottimeout
- 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 inputenter
- true if an Enter key press should be sent, false otherwise
-
-