Interface KeyboardController


public interface KeyboardController
Core interface for keyboard control operations.

This interface defines the contract for keyboard control implementations, completely decoupled from any higher-level components like Find or Actions. It represents pure keyboard control functionality with no dependencies on the Brobot action framework.

Implementations can use various technologies for keyboard control:

  • AWT Robot for Java-based control
  • Sikuli's keyboard control capabilities
  • Platform-specific APIs
  • Mock implementations for testing

Key design principles:

  • No dependencies on Find, Actions, or any higher-level components
  • Pure keyboard control - no pattern matching or element finding
  • Support for text typing and special key combinations
  • Thread-safe operations
Since:
2.0.0
  • Method Details

    • type

      boolean type(String text)
      Types the specified text string.

      This method simulates typing the given text as if typed on a physical keyboard. The typing speed may vary based on implementation and configuration.

      Parameters:
      text - The text to type
      Returns:
      true if typing was successful, false otherwise
    • type

      boolean type(String text, int delayMs)
      Types the specified text with a delay between characters.

      This method allows control over typing speed by specifying a delay in milliseconds between each character.

      Parameters:
      text - The text to type
      delayMs - Delay in milliseconds between characters
      Returns:
      true if typing was successful, false otherwise
    • pressKey

      boolean pressKey(KeyboardController.SpecialKey key)
      Presses and releases a special key.

      This method simulates pressing a special key like Enter, Tab, or function keys.

      Parameters:
      key - The special key to press
      Returns:
      true if key press was successful, false otherwise
    • keyDown

      boolean keyDown(KeyboardController.SpecialKey key)
      Presses and holds a special key without releasing.

      This method is useful for key combinations where a modifier key needs to be held while other keys are pressed.

      Parameters:
      key - The special key to press and hold
      Returns:
      true if key down was successful, false otherwise
    • keyUp

      boolean keyUp(KeyboardController.SpecialKey key)
      Releases a previously pressed key.

      This method releases a key that was pressed with keyDown.

      Parameters:
      key - The special key to release
      Returns:
      true if key release was successful, false otherwise
    • shortcut

      boolean shortcut(KeyboardController.SpecialKey modifier, char key)
      Performs a keyboard shortcut with a modifier key.

      This method handles common shortcuts like Ctrl+C, Ctrl+V, etc.

      Parameters:
      modifier - The modifier key (CTRL, ALT, SHIFT, CMD)
      key - The character key to press with the modifier
      Returns:
      true if shortcut was successful, false otherwise
    • shortcut

      boolean shortcut(KeyboardController.SpecialKey[] modifiers, char key)
      Performs a keyboard shortcut with multiple modifier keys.

      This method handles complex shortcuts like Ctrl+Shift+S.

      Parameters:
      modifiers - Array of modifier keys to hold
      key - The character key to press with the modifiers
      Returns:
      true if shortcut was successful, false otherwise
    • shortcut

      boolean shortcut(KeyboardController.SpecialKey modifier, KeyboardController.SpecialKey specialKey)
      Performs a keyboard shortcut with a modifier and special key.

      This method handles shortcuts like Alt+Tab, Ctrl+Home, etc.

      Parameters:
      modifier - The modifier key
      specialKey - The special key to press with the modifier
      Returns:
      true if shortcut was successful, false otherwise
    • clearAndType

      boolean clearAndType(String text)
      Clears the current text selection and types new text.

      This method first selects all text (Ctrl+A), then types the new text, effectively replacing any existing content.

      Parameters:
      text - The text to type after clearing
      Returns:
      true if operation was successful, false otherwise
    • copy

      boolean copy()
      Performs a copy operation (Ctrl+C or Cmd+C).

      Convenience method for the copy shortcut.

      Returns:
      true if copy was successful, false otherwise
    • paste

      boolean paste()
      Performs a paste operation (Ctrl+V or Cmd+V).

      Convenience method for the paste shortcut.

      Returns:
      true if paste was successful, false otherwise
    • cut

      boolean cut()
      Performs a cut operation (Ctrl+X or Cmd+X).

      Convenience method for the cut shortcut.

      Returns:
      true if cut was successful, false otherwise
    • selectAll

      boolean selectAll()
      Performs a select all operation (Ctrl+A or Cmd+A).

      Convenience method for the select all shortcut.

      Returns:
      true if select all was successful, false otherwise
    • isAvailable

      boolean isAvailable()
      Checks if the keyboard controller is available and functional.

      This method can be used to verify that keyboard control is possible in the current environment.

      Returns:
      true if keyboard control is available, false otherwise
    • getImplementationName

      String getImplementationName()
      Gets the name of this keyboard controller implementation.

      Used for logging and debugging to identify which controller is being used.

      Returns:
      Implementation name (e.g., "AWT Robot", "Sikuli", "Mock")