robotgo-cli is a cross-platform command-line tool that wraps the robotgo library's functionality. It allows you to automate desktop tasks from the terminal such as controlling the mouse, keyboard, capturing screenshots, managing windows, handling clipboard operations, and more.
- Features
- Requirements
- Installation
- Usage
- Cross-Compilation
- Troubleshooting
- Contributing
- License
- Acknowledgements
- Mouse Commands:
Move, click, scroll, and toggle mouse buttons. - Keyboard Commands:
Type strings, tap keys (with optional modifiers), and toggle key states. - Screen Commands:
Capture a portion of the screen or the entire screen, get pixel color, and retrieve screen size. - Window Commands:
Activate a window by name or process ID, kill processes, and fetch the active window title. - Event Commands:
Listen for specific key events or print low-level system events. - Clipboard Commands:
Read from and write text to the clipboard. - Process Commands:
List running processes (PID and name).
Platform-specific requirements:
-
Linux:
You may need the following development packages:sudo apt-get install libx11-xcb-dev libx11-dev libxtst-dev
-
Windows:
When cross-compiling on Linux, ensure you have a Windows C compiler like gcc-mingw-w64-x86-64.
-
Clone the Repository:
git clone https://github.com/sampagon/robotgo-cli.git cd robotgo-cli -
Initialize a Go Module:
go mod init robotgo-cli
-
Install Dependencies:
go get github.com/go-vgo/robotgo go get github.com/spf13/cobra go get github.com/robotn/gohook
-
Build the Tool:
go build -o robotgo-cli main.go
After building, run the executable. You can see all commands by executing:
./robotgo-cli --helpMove the Mouse:
./robotgo-cli mouse move --x 100 --y 200Moves the mouse pointer to the coordinates (100, 200).
Click the Mouse:
./robotgo-cli mouse click --button left --doubleClicks the left mouse button (double click if --double is set).
Scroll the Mouse:
./robotgo-cli mouse scroll --direction up --steps 10Scrolls up 10 steps. Change the --direction flag as needed.
Toggle Mouse Button State:
./robotgo-cli mouse toggle --button left --state downToggles the specified mouse button state to either down or up.
Type a String:
./robotgo-cli keyboard type --text "Hello, RobotGo!"Simulates typing the provided string.
Tap a Key (with Modifiers):
./robotgo-cli keyboard tap --key a --mods ctrl,shiftTaps the a key with ctrl and shift modifiers. Use a comma-separated list for modifiers.
Toggle a Key State:
./robotgo-cli keyboard toggle --key a --state upToggles the key a to the specified state.
Capture a Portion of the Screen:
./robotgo-cli screen capture --x 10 --y 10 --width 300 --height 300 --output shot.pngCaptures a 300x300 region starting at (10, 10) and saves it as shot.png.
Capture the Full Screen:
The tool supports a --full flag to capture the entire screen. When this flag is used, the provided coordinates and dimensions are ignored.
./robotgo-cli screen capture --full --output full_shot.pngGet Pixel Color:
./robotgo-cli screen getpixel --x 150 --y 150Returns the color of the pixel at (150, 150).
Get Screen Size:
./robotgo-cli screen sizePrints the current screen width and height.
Activate a Window:
Activate by name:
./robotgo-cli window activate --name chromeOr by process ID:
./robotgo-cli window activate --pid 12345Kill a Window Process:
./robotgo-cli window kill --pid 12345Terminates the process with the given PID.
Get Active Window Title:
./robotgo-cli window titlePrints the title of the currently active window.
Listen for a Specific Key Combination:
./robotgo-cli event listen --keys ctrl,shift,qListens for the ctrl+shift+q combination and prints event details when triggered (listener stops after the first event).
Print Low-Level Events:
./robotgo-cli event lowContinuously prints low-level events until interrupted (e.g., with Ctrl+C).
Read from Clipboard:
./robotgo-cli clipboard readPrints the current contents of the clipboard.
Write to Clipboard:
./robotgo-cli clipboard write --text "Clipboard text"Writes the provided text to the clipboard.
List Running Processes:
./robotgo-cli process listDisplays a list of running processes along with their PID and name.
-
Install the Windows Cross-Compiler:
sudo apt-get install gcc-mingw-w64-x86-64
-
Set the CC Environment Variable:
export CC=x86_64-w64-mingw32-gcc -
Build for Windows:
GOOS=windows GOARCH=amd64 CGO_ENABLED=1 go build -o robotgo-cli.exe main.go
This will produce robotgo-cli.exe, which can be run on Windows.
Contributions are welcome! If you'd like to add new features, improve documentation, or fix bugs, please fork the repository and submit a pull request. For major changes, open an issue first to discuss your ideas.