Package org.dreambot.api.input
Class Keyboard
- java.lang.Object
-
- org.dreambot.api.input.Keyboard
-
public class Keyboard extends java.lang.ObjectKeyboard API class.
-
-
Constructor Summary
Constructors Constructor Description Keyboard()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static booleancloseInterfaceWithEsc()If closing interfaces with esc is enabled in the game, this will close interfaces with the esc keystatic voidgainFocus()Emulates alt+tabbing to gain focus on the client Ignored if client already has focusstatic intgetCurrentModifiers()Currently held down modifiers, shift, ctrl, alt, etc Use bitwise checks on events likeInputEvent.SHIFT_MASKto check if modifier is activestatic KeyboardTypingAlgorithmgetKeyboardTypingAlgorithm()Keyboard typing algorithm, handles the actual typing implementationsstatic doublegetWordsPerMinute()Gets the currentKeyboardProfile.getWordsPerMinute()static voidholdControl(Condition release)HoldsKey.CTRLuntil the givenCondition.verify()returns true Defaults to a 3 second timeout Defaults to theKeyLocation.LEFTcontrol Can be canceled usingmarkHeld(Key, boolean)with falsestatic voidholdControl(Condition release, long timeout)HoldsKey.CTRLuntil the givenCondition.verify()returns true or the given timeout is reached Defaults to theKeyLocation.LEFTcontrol Can be canceled usingmarkHeld(Key, boolean)with falsestatic voidholdKey(Key key, Condition release)SeeholdKey(Key, Condition, long)with a default timeout of 3000static voidholdKey(Key key, Condition release, long timeout)Submits a newHoldKeywith a givenKeyuntil the givenCondition.verify()returns true or the passed in timeout is reached.static voidholdShift(Condition release)HoldsKey.SHIFTuntil the givenCondition.verify()returns true Defaults to a 3 second timeout Defaults to theKeyLocation.LEFTshift Can be canceled usingmarkHeld(Key, boolean)with falsestatic voidholdShift(Condition release, long timeout)HoldsKey.SHIFTuntil the givenCondition.verify()returns true or the given timeout is reached Defaults to theKeyLocation.LEFTshift Can be canceled usingmarkHeld(Key, boolean)with falsestatic voidholdSpace(Condition release)HoldsKey.SPACEuntil the givenCondition.verify()returns true Defaults to a 3 second timeout Can be canceled usingmarkHeld(Key, boolean)with falsestatic voidholdSpace(Condition release, long timeout)HoldsKey.SPACEuntil the givenCondition.verify()returns true or the given timeout is reached Can be canceled usingmarkHeld(Key, boolean)with falsestatic booleanisHeld(Key key)Checks if a givenKeyis currently being heldstatic booleanisPressed(Key key)Checks if a key is pressedstatic voidloseFocus()Emulates alt+tabbing to lose focus on the client Ignored if client currently does not have focusstatic voidmarkHeld(Key key, boolean held)Marks theKeyas being held, does NOT send any events.static voidmarkPressed(Key key)Marks the givenKeyas pressed.static voidmarkReleased(Key key)Marks a givenKeyas released.static voidpressEsc()Presses the ESC key Handles full press/releasestatic voidpressShift()Calls thePressKeyevent forKey.SHIFTDefaults to theKeyLocation.LEFTshift Does NOT handle release.static voidreleaseChar(char character)Creates and runs aReleaseEventon a character.static voidreleaseKey(Key key)Releases aKeyif it marked as pressed or heldstatic voidreleaseShift()static voidsetKeyboardTypingAlgorithm(KeyboardTypingAlgorithm algo)Sets the Keyboard typing algorithm, parent class ofKeyboardTypingAlgorithmstatic voidsetWordsPerMinute(double wpm)static booleantype(java.lang.Object message)Types out a given message, will press enter at the end if successfulstatic booleantype(java.lang.Object message, boolean enter)Types out a given message, optionally pressing enterstatic voidtype(java.lang.Object message, boolean enter, boolean makeMistakes)Types out a given message, optionally pressing enter and optionally making mistakesstatic booleantype(java.lang.Object message, boolean enter, Condition stop)Types out a given message, optionally pressing enter Uses a stopConditionthat will cause the typing to be interrupted and stopped.static booleantypeKey(int keyCode)Types aKeybased on the keyCode passed in.static booleantypeKey(Key key)Types aKeyHandles 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_MASKto check if modifier is active
-
isPressed
public static boolean isPressed(Key key)
Checks if a key is pressed- Parameters:
key-Keykey to check- Returns:
- true if pressed, else false
-
markPressed
public static void markPressed(Key key)
Marks the givenKeyas pressed. Primarily for internal usage. Also marks this key as held withmarkHeld(Key, boolean)- Parameters:
key-Keyto mark as pressed
-
markReleased
public static void markReleased(Key key)
Marks a givenKeyas released. Primarily for internal usage. Also marks this key as not held withmarkHeld(Key, boolean)- Parameters:
key-Keyto mark as released
-
isHeld
public static boolean isHeld(Key key)
Checks if a givenKeyis currently being held- Parameters:
key-Keyto check- Returns:
- true if held, else false
-
markHeld
public static void markHeld(Key key, boolean held)
Marks theKeyas being held, does NOT send any events.- Parameters:
key-Keyto 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 stopConditionthat 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- stopConditionto 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 aKeybased 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
Keyand types it, else false
-
typeKey
public static boolean typeKey(Key key)
Types aKeyHandles the full press, type(if necessary), release Defaults to not push enter.- Parameters:
key-Keyto 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 newHoldKeywith a givenKeyuntil 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.SHIFTuntil the givenCondition.verify()returns true Defaults to a 3 second timeout Defaults to theKeyLocation.LEFTshift Can be canceled usingmarkHeld(Key, boolean)with false- Parameters:
release-Conditionfor when to release Shift
-
holdShift
public static void holdShift(Condition release, long timeout)
HoldsKey.SHIFTuntil the givenCondition.verify()returns true or the given timeout is reached Defaults to theKeyLocation.LEFTshift Can be canceled usingmarkHeld(Key, boolean)with false- Parameters:
release-Conditionfor when to release Shifttimeout- timeout for holding the shift key
-
holdControl
public static void holdControl(Condition release)
HoldsKey.CTRLuntil the givenCondition.verify()returns true Defaults to a 3 second timeout Defaults to theKeyLocation.LEFTcontrol Can be canceled usingmarkHeld(Key, boolean)with false- Parameters:
release-Conditionfor when to release CTRL
-
holdControl
public static void holdControl(Condition release, long timeout)
HoldsKey.CTRLuntil the givenCondition.verify()returns true or the given timeout is reached Defaults to theKeyLocation.LEFTcontrol Can be canceled usingmarkHeld(Key, boolean)with false- Parameters:
release-Conditionfor when to release CTRLtimeout- timeout for holding the control key
-
holdSpace
public static void holdSpace(Condition release)
HoldsKey.SPACEuntil the givenCondition.verify()returns true Defaults to a 3 second timeout Can be canceled usingmarkHeld(Key, boolean)with false- Parameters:
release-Conditionfor when to release space
-
holdSpace
public static void holdSpace(Condition release, long timeout)
HoldsKey.SPACEuntil the givenCondition.verify()returns true or the given timeout is reached Can be canceled usingmarkHeld(Key, boolean)with false- Parameters:
release-Conditionfor when to release the space keytimeout- timeout for holding the space key
-
pressShift
public static void pressShift()
Calls thePressKeyevent forKey.SHIFTDefaults to theKeyLocation.LEFTshift Does NOT handle release.
-
releaseShift
public static void releaseShift()
-
releaseKey
public static void releaseKey(Key key)
Releases aKeyif it marked as pressed or held- Parameters:
key-
-
releaseChar
public static void releaseChar(char character)
Creates and runs aReleaseEventon 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
-
-