Skip to content

Feature: Add keyDown/keyUp methods for advanced keyboard control #17

@NakaokaRei

Description

@NakaokaRei

Description

SwiftAutoGUI provides keyDown(KeyCode) and keyUp(KeyCode) methods that allow pressing and releasing individual keys. This enables more advanced keyboard control scenarios that aren't possible with just sendKeyShortcut.

Implementation Details

Add two new tools to the Keyboard category:

  1. keyDown - Press and hold a key
  2. keyUp - Release a held key

Parameters

Both tools accept:

  • key: The key code to press/release (string representation matching KeyCode enum)

Use Cases

  • Holding modifier keys while performing other actions
  • Gaming automation requiring sustained key presses
  • Complex key combinations beyond simple shortcuts
  • Simulating human-like typing patterns
  • Accessibility tools requiring precise key control

Example Usage

// Press and hold shift
{
  "tool": "keyDown",
  "arguments": {
    "key": "shift"
  }
}

// Perform other actions while shift is held...

// Release shift
{
  "tool": "keyUp",
  "arguments": {
    "key": "shift"
  }
}

Implementation Notes

  • Should validate that the key string maps to a valid KeyCode
  • Consider adding safety features to prevent keys from being stuck down
  • May want to track pressed keys to ensure proper cleanup
  • Error handling for invalid key codes

Priority

Medium - This feature enables advanced automation scenarios but requires careful implementation to avoid leaving keys in a pressed state.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions