Package com.randomnoun.common
Class Keyboard
java.lang.Object
com.randomnoun.common.Keyboard
Use the AWT Robot class to send strings to another application.
Based on the code at
http://stackoverflow.com/questions/1248510/convert-string-to-keyevents
- Author:
- knoxg
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
doType
(int... keyCodes) Type a series of keyCodes.void
doType
(int[] keyCodes, int offset, int length) Type a series of keyCodes.void
Resets the keyboard buffer; i.e.void
setBufferSize
(int bufferSize) Sets the size of the 'keyboard buffer'.void
setDelayMillis
(int delayMillis) Sets the delay to introduce afterbufferSize
characters have been typed, in millisecondsvoid
type
(char character) Type an individual charactervoid
type
(CharSequence characters) Type the supplied character sequence (typically aString
).
-
Constructor Details
-
Keyboard
Create a new Keyboard object- Throws:
AWTException
-
Keyboard
Create a new Keyboard object, using the supplied AWT Robot class to create virtual keystrokes.- Parameters:
robot
- AWT Robot class to create virtual keystrokes.
-
-
Method Details
-
setBufferSize
Sets the size of the 'keyboard buffer'. Once this many characters have been typed using thetype(CharSequence)
method, an artificial delay is introduced to allow the program handling input to process keystrokes.- Parameters:
bufferSize
- the size of the 'keyboard buffer'
-
setDelayMillis
Sets the delay to introduce afterbufferSize
characters have been typed, in milliseconds- Parameters:
delayMillis
- delay in milliseconds
-
resetBuffer
Resets the keyboard buffer; i.e. sets the internal count of number of characters typed to zero. -
type
Type the supplied character sequence (typically aString
). An artificial delay will be introduced every bufferSize characters, of size delayMillis.- Parameters:
characters
- characters to type
-
type
Type an individual character- Parameters:
character
- character to type
-
doType
Type a series of keyCodes. Is equivalent to callingdoType(keyCodes, 0, keyCodes.length);
. The bufferSize and delayMillis settings are not used by this method.- Parameters:
keyCodes
- keyCodes to type- See Also:
-
doType
Type a series of keyCodes. The bufferSize and delayMillis settings are not used by this method.- Parameters:
keyCodes
- keyCodes to type
-