Package org.dreambot.api.input
Class Keyboard
- java.lang.Object
-
- org.dreambot.api.input.Keyboard
-
public class Keyboard extends java.lang.Object
Keyboard API class.
-
-
Constructor Summary
Constructors Constructor Description Keyboard()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static boolean
closeInterfaceWithEsc()
If closing interfaces with esc is enabled in the game, this will close interfaces with the esc keystatic void
gainFocus()
Emulates alt+tabbing to gain focus on the client Ignored if client already has focusstatic int
getCurrentModifiers()
Currently held down modifiers, shift, ctrl, alt, etc Use bitwise checks on events likeInputEvent.SHIFT_MASK
to check if modifier is activestatic KeyboardTypingAlgorithm
getKeyboardTypingAlgorithm()
Keyboard typing algorithm, handles the actual typing implementationsstatic double
getWordsPerMinute()
Gets the currentKeyboardProfile.getWordsPerMinute()
static void
holdControl(Condition release)
HoldsKey.CTRL
until the givenCondition.verify()
returns true Defaults to a 3 second timeout Defaults to theKeyLocation.LEFT
control Can be canceled usingmarkHeld(Key, boolean)
with falsestatic void
holdControl(Condition release, long timeout)
HoldsKey.CTRL
until the givenCondition.verify()
returns true or the given timeout is reached Defaults to theKeyLocation.LEFT
control Can be canceled usingmarkHeld(Key, boolean)
with falsestatic void
holdKey(Key key, Condition release)
SeeholdKey(Key, Condition, long)
with a default timeout of 3000static void
holdKey(Key key, Condition release, long timeout)
Submits a newHoldKey
with a givenKey
until the givenCondition.verify()
returns true or the passed in timeout is reached.static void
holdShift(Condition release)
HoldsKey.SHIFT
until the givenCondition.verify()
returns true Defaults to a 3 second timeout Defaults to theKeyLocation.LEFT
shift Can be canceled usingmarkHeld(Key, boolean)
with falsestatic void
holdShift(Condition release, long timeout)
HoldsKey.SHIFT
until the givenCondition.verify()
returns true or the given timeout is reached Defaults to theKeyLocation.LEFT
shift Can be canceled usingmarkHeld(Key, boolean)
with falsestatic void
holdSpace(Condition release)
HoldsKey.SPACE
until the givenCondition.verify()
returns true Defaults to a 3 second timeout Can be canceled usingmarkHeld(Key, boolean)
with falsestatic void
holdSpace(Condition release, long timeout)
HoldsKey.SPACE
until the givenCondition.verify()
returns true or the given timeout is reached Can be canceled usingmarkHeld(Key, boolean)
with falsestatic boolean
isHeld(Key key)
Checks if a givenKey
is currently being heldstatic boolean
isPressed(Key key)
Checks if a key is pressedstatic void
loseFocus()
Emulates alt+tabbing to lose focus on the client Ignored if client currently does not have focusstatic void
markHeld(Key key, boolean held)
Marks theKey
as being held, does NOT send any events.static void
markPressed(Key key)
Marks the givenKey
as pressed.static void
markReleased(Key key)
Marks a givenKey
as released.static void
pressEsc()
Presses the ESC key Handles full press/releasestatic void
pressShift()
Calls thePressKey
event forKey.SHIFT
Defaults to theKeyLocation.LEFT
shift Does NOT handle release.static void
releaseChar(char character)
Creates and runs aReleaseEvent
on a character.static void
releaseKey(Key key)
Releases aKey
if it marked as pressed or heldstatic void
releaseShift()
static void
setKeyboardTypingAlgorithm(KeyboardTypingAlgorithm algo)
Sets the Keyboard typing algorithm, parent class ofKeyboardTypingAlgorithm
static void
setWordsPerMinute(double wpm)
static boolean
type(java.lang.Object message)
Types out a given message, will press enter at the end if successfulstatic boolean
type(java.lang.Object message, boolean enter)
Types out a given message, optionally pressing enterstatic void
type(java.lang.Object message, boolean enter, boolean makeMistakes)
Types out a given message, optionally pressing enter and optionally making mistakesstatic boolean
type(java.lang.Object message, boolean enter, Condition stop)
Types out a given message, optionally pressing enter Uses a stopCondition
that will cause the typing to be interrupted and stopped.static boolean
typeKey(int keyCode)
Types aKey
based on the keyCode passed in.static boolean
typeKey(Key key)
Types aKey
Handles the full press, type(if necessary), release Defaults to not push enter.
-
-
-
Method Detail
-
getKeyboardTypingAlgorithm
public static KeyboardTypingAlgorithm getKeyboardTypingAlgorithm()
Keyboard typing algorithm, handles the actual typing implementations
-
setKeyboardTypingAlgorithm
public static void setKeyboardTypingAlgorithm(KeyboardTypingAlgorithm algo)
Sets the Keyboard typing algorithm, parent class ofKeyboardTypingAlgorithm
-
getCurrentModifiers
public static int getCurrentModifiers()
Currently held down modifiers, shift, ctrl, alt, etc Use bitwise checks on events likeInputEvent.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 givenKey
as pressed. Primarily for internal usage. Also marks this key as held withmarkHeld(Key, boolean)
- Parameters:
key
-Key
to mark as pressed
-
markReleased
public static void markReleased(Key key)
Marks a givenKey
as released. Primarily for internal usage. Also marks this key as not held withmarkHeld(Key, boolean)
- Parameters:
key
-Key
to mark as released
-
isHeld
public static boolean isHeld(Key key)
Checks if a givenKey
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 theKey
as being held, does NOT send any events.- Parameters:
key
-Key
to markheld
- 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 typeenter
- 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 stopCondition
that will cause the typing to be interrupted and stopped. In interruption, enter will not be pushed.- Parameters:
message
- message to typeenter
- whether to press enter at the end if successful or notstop
- stopCondition
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 typeenter
- whether to hit enter or not when typing successfully completesmakeMistakes
- whether to have a chance of making mistakes or not during typing
-
typeKey
public static boolean typeKey(int keyCode)
Types aKey
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 usetypeKey(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 aKey
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)
SeeholdKey(Key, Condition, long)
with a default timeout of 3000
-
holdKey
public static void holdKey(Key key, Condition release, long timeout)
Submits a newHoldKey
with a givenKey
until the givenCondition.verify()
returns true or the passed in timeout is reached. seeKey.getDefaultLocation()
for default key locations Can be canceled usingmarkHeld(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
-
holdShift
public static void holdShift(Condition release)
HoldsKey.SHIFT
until the givenCondition.verify()
returns true Defaults to a 3 second timeout Defaults to theKeyLocation.LEFT
shift Can be canceled usingmarkHeld(Key, boolean)
with false- Parameters:
release
-Condition
for when to release Shift
-
holdShift
public static void holdShift(Condition release, long timeout)
HoldsKey.SHIFT
until the givenCondition.verify()
returns true or the given timeout is reached Defaults to theKeyLocation.LEFT
shift Can be canceled usingmarkHeld(Key, boolean)
with false- Parameters:
release
-Condition
for when to release Shifttimeout
- timeout for holding the shift key
-
holdControl
public static void holdControl(Condition release)
HoldsKey.CTRL
until the givenCondition.verify()
returns true Defaults to a 3 second timeout Defaults to theKeyLocation.LEFT
control Can be canceled usingmarkHeld(Key, boolean)
with false- Parameters:
release
-Condition
for when to release CTRL
-
holdControl
public static void holdControl(Condition release, long timeout)
HoldsKey.CTRL
until the givenCondition.verify()
returns true or the given timeout is reached Defaults to theKeyLocation.LEFT
control Can be canceled usingmarkHeld(Key, boolean)
with false- Parameters:
release
-Condition
for when to release CTRLtimeout
- timeout for holding the control key
-
holdSpace
public static void holdSpace(Condition release)
HoldsKey.SPACE
until the givenCondition.verify()
returns true Defaults to a 3 second timeout Can be canceled usingmarkHeld(Key, boolean)
with false- Parameters:
release
-Condition
for when to release space
-
holdSpace
public static void holdSpace(Condition release, long timeout)
HoldsKey.SPACE
until the givenCondition.verify()
returns true or the given timeout is reached Can be canceled usingmarkHeld(Key, boolean)
with false- Parameters:
release
-Condition
for when to release the space keytimeout
- timeout for holding the space key
-
pressShift
public static void pressShift()
Calls thePressKey
event forKey.SHIFT
Defaults to theKeyLocation.LEFT
shift Does NOT handle release.
-
releaseShift
public static void releaseShift()
-
releaseKey
public static void releaseKey(Key key)
Releases aKey
if it marked as pressed or held- Parameters:
key
-
-
releaseChar
public static void releaseChar(char character)
Creates and runs aReleaseEvent
on a character. Does NOT verify if that character was currently being held or not.- Parameters:
character
- character to release
-
getWordsPerMinute
public static double getWordsPerMinute()
Gets the currentKeyboardProfile.getWordsPerMinute()
-
setWordsPerMinute
public static void setWordsPerMinute(double wpm)
-
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
-
-