AutoClick for Crystal

test Lines of Code Static Badge

A Windows GUI automation library for Crystal that provides mouse and keyboard automation capabilities by interfacing with Windows User32 API functions.

This is a Crystal port of the Ruby AutoClick library.

Features

Installation

Add this to your application's shard.yml:

dependencies:
  auto_click:
    github: kojix2/auto_click

Then run:

shards install

Usage

Method 1: Include the module

require "auto_click"
include AutoClick

# Mouse operations
left_click()
mouse_move(100, 100)
mouse_move_percentage(0.5, 0.5)  # Move to center of screen
right_click()
double_click()
mouse_scroll(3)  # Scroll up 3 steps

# Keyboard operations
type("Hello World!")
key_stroke("enter")
key_combination("ctrl", "c")  # Copy
copy()  # Shorthand for Ctrl+C
paste()  # Shorthand for Ctrl+V

# System information
width, height = screen_resolution()
x, y = cursor_position()

Method 2: Use as namespace

require "auto_click"

AutoClick.left_click()
AutoClick.mouse_move(100, 100)
AutoClick.type("Hello World!")

API Reference

Mouse Operations

Basic Clicks

Mouse State Control

Cursor Movement

Drag Operations

Scroll Operations

Utility Methods

Keyboard Operations

Key Presses

Text Input

Key Combinations

Common Shortcuts

Key State

Utility Methods

System Information

Key Names

The library supports flexible key naming:

Letters and Numbers

"a", "b", "c", ..., "z"  # Letters (case insensitive)
"0", "1", "2", ..., "9"  # Numbers

Function Keys

"f1", "f2", ..., "f12"   # Function keys

Modifier Keys

"shift", "leftshift", "rightshift"
"ctrl", "control", "leftctrl", "rightctrl"
"alt", "leftalt", "rightalt"
"win", "windows", "leftwin", "rightwin"

Special Keys

"space", "enter", "tab", "esc", "escape"
"backspace", "delete", "insert"
"home", "end", "pageup", "pagedown"
"left", "right", "up", "down"  # Arrow keys
"capslock", "numlock", "scrolllock"
"pause", "printscreen"

Symbol Keys

"semicolon", "equal", "comma", "hyphen", "period"
"slash", "grave", "bracket", "backslash"
"closebracket", "quote"

Special Characters

The library automatically handles special characters that require Shift:

type("Hello World!")  # Automatically presses Shift for '!'
type("user@example.com")  # Handles @ symbol
type("Price: $19.99")  # Handles $ symbol

Supported special characters: ! @ # $ % ^ & * ( ) _ + { } | : " < > ? ~

Platform Support

Requirements

Examples

See the examples/ directory for complete usage examples.

Architecture

The library is organized into several modules:

Contributing

  1. Fork it (https://github.com/kojix2/auto_click/fork)
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

License

MIT License. See LICENSE file for details.

Credits

This library is a Crystal port of the Ruby AutoClick library by erinata.