Package Exports
- robotjs
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (robotjs) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
RobotJS
Node.js GUI Automation. Control the mouse, keyboard, and read the screen.
This is a work in progress so the exported functions could change at any time before the first stable release (1.0.0). Ideas?
Only tested on Mac OS X using Node.js v0.10.31.
node-gyp is only configured for Mac, but this project will support Windows and Linux when I have time to test.
Installing
npm install robotjs
Examples
Get the mouse location and move it.
var robot = require("robotjs");
//Get the mouse position, retuns an object with x and y.
var mouse=robot.getMousePos();
console.log("Mouse is at x:" + mouse.x + " y:" + mouse.y);
//Move the mouse down by 100 pixels.
robot.moveMouse(mouse.x,mouse.y+100);
//Left click!
robot.mouseClick();
Type "Hello World".
var robot = require("robotjs");
//Type "Hello Worl".
robot.typeString("Hello Worl");
//Type "d".
robot.keyTap("d");
Get pixel color under the mouse.
var robot = require("robotjs");
//Get mouse position.
var mouse=robot.getMousePos();
//Get pixel color in hex format.
var hex = robot.getPixelColor(mouse.x, mouse.y);
console.log("#" + hex + " at x:" + mouse.x + " y:" + mouse.y);
Building
RobotJS uses node-gyp for building.
Install node-gyp using npm:
npm install -g node-gyp
Then confgure and build:
node-gyp configure
node-gyp build
Plans
- Control the mouse by changing the mouse position, left/right clicking, and dragging.
- Control the keyboard by pressing keys, holding keys down, and typing words.
- Read pixel color from the screen and capture the screen.
- Find image on screen, read pixels from image.
- Possibly include window management?
Progress
Module | Status | Notes |
---|---|---|
Mouse | 80% | Can't specify mouse button. |
Keyboard | 50% | No toggle support. |
Screen | 5% | Screenshot, read pixel color, image search. |
Window | 1% | Manipulate external windows. |
Story
I'm a huge fan of AutoHotkey, and I've used it for a very long time. AutoHotkey is great for automation and it can do a bunch of things that are very diffucult in other languages. For example, it's imagesearch and pixel related functions are hard to reproduce on Mac, espscially in scripting languages. These functions are great for automating apps that can't be automated like Netflix. This has never been a big deal since I've always used Windows at work, but for the past few years I've been using Mac exclusively.
I like AutoHotkey, but I like Node.js more. By developing RobotJS I get an AutoHotkey replacement on Mac (finally!), and I get to use my favorite language.
TLDR: There's nothing like AutoHotkey on Mac, so I'm making it.
Based on autopy.