Class Keyboard

java.lang.Object
com.randomnoun.common.Keyboard

public class Keyboard extends Object
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
    Constructor
    Description
    Create a new Keyboard object
    Keyboard(Robot robot)
    Create a new Keyboard object, using the supplied AWT Robot class to create virtual keystrokes.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    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 after bufferSize characters have been typed, in milliseconds
    void
    type(char character)
    Type an individual character
    void
    type(CharSequence characters)
    Type the supplied character sequence (typically a String).

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Keyboard

      public Keyboard() throws AWTException
      Create a new Keyboard object
      Throws:
      AWTException
    • Keyboard

      public Keyboard(Robot robot)
      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

      public void setBufferSize(int bufferSize)
      Sets the size of the 'keyboard buffer'. Once this many characters have been typed using the type(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

      public void setDelayMillis(int delayMillis)
      Sets the delay to introduce after bufferSize characters have been typed, in milliseconds
      Parameters:
      delayMillis - delay in milliseconds
    • resetBuffer

      public void resetBuffer()
      Resets the keyboard buffer; i.e. sets the internal count of number of characters typed to zero.
    • type

      public void type(CharSequence characters)
      Type the supplied character sequence (typically a String). An artificial delay will be introduced every bufferSize characters, of size delayMillis.
      Parameters:
      characters - characters to type
    • type

      public void type(char character)
      Type an individual character
      Parameters:
      character - character to type
    • doType

      public void doType(int... keyCodes)
      Type a series of keyCodes. Is equivalent to calling doType(keyCodes, 0, keyCodes.length);. The bufferSize and delayMillis settings are not used by this method.
      Parameters:
      keyCodes - keyCodes to type
      See Also:
    • doType

      public void doType(int[] keyCodes, int offset, int length)
      Type a series of keyCodes. The bufferSize and delayMillis settings are not used by this method.
      Parameters:
      keyCodes - keyCodes to type