Tego Bot API Documentation v0.1.1
Tego Bot
High-performance desktop automation library for Node.js. Powered by Rust for extreme speed and memory safety.
- ๐ Extreme performance โ Rust core optimized for maximum speed & efficiency
- ๐ Memory safe โ Rust's type system guarantees memory safety
- ๐ฏ API compatible โ Similar API design to robotjs for easy migration
- ๐ Cross-platform โ Supports Windows, macOS, and Linux
- ๐ฆ Zero dependencies โ No additional Node.js dependencies required
- ๐งช Well tested โ Comprehensive test coverage
๐ Quick Start โ
You can add Tego Bot to your project via the @tego/botjs package:
bash
pnpm add @tego/botjs
# Or: npm/yarn/bun add @tego/botjsMinimal Example โ
ts
import { moveMouse, mouseClick, keyTap, typeString, captureScreen } from '@tego/botjs';
// Move mouse and click
moveMouse(100, 200);
mouseClick('left');
// Type text
typeString('Hello from Tego Bot!');
keyTap('enter');
// Capture screen
const screenshot = await captureScreen();
// screenshot.image contains PNG buffer๐ API Documentation โ
Mouse Operations โ
ts
import { moveMouse, moveMouseSmooth, mouseClick, getMousePos, dragMouse, scrollMouse } from '@tego/botjs';
// Move mouse to coordinates
moveMouse(100, 200);
// Smooth movement
moveMouseSmooth(300, 400);
moveMouseSmooth(500, 600, 5.0); // with custom speed
// Click
mouseClick('left'); // Left click
mouseClick('right', true); // Right double click
mouseClick('middle'); // Middle click
// Get mouse position
const pos = getMousePos();
console.log(`Mouse at: ${pos.x}, ${pos.y}`);
// Drag
dragMouse(500, 600);
// Scroll
scrollMouse(0, 3); // Scroll down
scrollMouse(2, 0); // Scroll rightKeyboard Operations โ
ts
import { keyTap, keyToggle, typeString, typeStringDelayed, unicodeTap } from '@tego/botjs';
// Tap a key
keyTap('a');
keyTap('enter');
keyTap('c', ['control']); // Ctrl+C
keyTap('v', ['control', 'shift']); // Ctrl+Shift+V
// Toggle key
keyToggle('a', 'down'); // Press 'a'
keyToggle('a', 'up'); // Release 'a'
// Type text
typeString('Hello, World!');
// Type with delay (characters per minute)
typeStringDelayed('Hello', 300); // 300 CPM
// Tap Unicode character
unicodeTap(0x1F600); // ๐Screen Operations โ
ts
import { captureScreen, captureScreenRegion, getScreenSize, getPixelColor, screen } from '@tego/botjs';
import fs from 'fs';
// Capture entire screen
const screenshot = await captureScreen();
fs.writeFileSync('screenshot.png', screenshot.image);
// Capture region
const region = await captureScreenRegion(100, 100, 800, 600);
fs.writeFileSync('region.png', region.image);
// Get screen size
const size = getScreenSize();
console.log(`Screen: ${size.width}x${size.height}`);
// Get pixel color (returns hex string)
const color = await getPixelColor(100, 200);
console.log(`Color: ${color}`); // e.g., "#FF0000"
// Using screen object
const bitmap = await screen.capture(0, 0, 800, 600);
const pixelColor = bitmap.colorAt(100, 200);Configuration โ
ts
import { setMouseDelay, setKeyboardDelay, updateScreenMetrics } from '@tego/botjs';
// Set delays (in milliseconds)
setMouseDelay(50);
setKeyboardDelay(10);
// Update screen metrics (refresh monitor information)
updateScreenMetrics();๐ฏ Supported Keys โ
Modifier Keys โ
control/ctrlโ Control keyshiftโ Shift keyaltโ Alt keycommand/cmd/metaโ Command/Meta key
Function Keys โ
f1โf12โ F1 to F12
Special Keys โ
enter/returnโ Enter keyescape/escโ ESC keybackspaceโ Backspace keytabโ Tab keyspaceโ Space keydelete/delโ Delete keyup/down/left/rightโ Arrow keyshome/endโ Home/End keyspageup/page_downโ Page Up/Down keys
Mouse Buttons โ
leftโ Left buttonrightโ Right buttonmiddleโ Middle button
๐ ๏ธ Building โ
To build the library from source:
bash
# Install dependencies
pnpm install
# Build Rust code and generate Node.js bindings
pnpm build
# Or build only Rust code
pnpm rs:build๐ System Requirements โ
macOS โ
- macOS 10.13+
- Screen recording permission required (System Preferences > Security & Privacy > Screen Recording)
Windows โ
- Windows 10+
- No additional configuration needed
Linux โ
- X11 or Wayland
- May require system dependencies:bash
# Ubuntu/Debian sudo apt-get install libxcb1-dev libxrandr-dev libdbus-1-dev # Fedora sudo dnf install libxcb-devel libXrandr-devel dbus-devel
๐งช Testing โ
bash
# Run Rust tests
pnpm test
# Build and test Node.js bindings
pnpm build๐ Comparison with robotjs โ
| Feature | robotjs | Tego Bot (@tego/botjs) |
|---|---|---|
| Performance | Medium (C++ bindings) | โก Extremely high (Rust native) |
| Maintenance | โ No longer maintained | โ Actively maintained |
| Memory Safety | โ ๏ธ C++ | โ Rust |
| API Design | โ Simple | โ Compatible |
| Cross-platform | โ | โ |
| Type Safety | โ ๏ธ Runtime checks | โ Compile-time guarantees |
๐ License โ
Licensed under the MIT License.
๐ค Contributing โ
Contributions are welcome! Please feel free to submit a Pull Request.