robotjs Documentation

Node.js Desktop Automation.

12,764 stars C C 1 file ยท ~3,195 tokens
RAW Doc

1. Project Overview & Quickstart (octalmage/robotjs)

Node.js Desktop Automation. Control the mouse, keyboard, and read the screen.

RobotJS supports Mac, Windows, and Linux.

This is a work in progress so the exported functions could change at any time before the first stable release (1.0.0). Ideas?

Check out some of the cool things people are making with RobotJS! Have your own rad RobotJS project? Feel free to add it!

Contents

Installation

Install RobotJS using npm:

text
npm install robotjs

You can get npm here if you don't have it installed.

Published packages include Node-API prebuilds for Linux, macOS, and Windows on
x64 and arm64. Other targets fall back to a source build.

If you need to build RobotJS, see the building section. Instructions for Electron.

Examples

[Mouse](https://github.com/octalmage/robotjs/wiki/Syntax#mouse)

js
// Move the mouse across the screen as a sine wave.
const robot = require("robotjs");

// Speed up the mouse.
robot.setMouseDelay(2);

const twoPI = Math.PI * 2;
const screenSize = robot.getScreenSize();
const height = (screenSize.height / 2) - 10;
const width = screenSize.width;

for (let x = 0; x < width; x++) {
	const y = height * Math.sin((twoPI * x) / width) + height;
	robot.moveMouse(x, y);
}

[Keyboard](https://github.com/octalmage/robotjs/wiki/Syntax#keyboard)

js
// Type "Hello World" then press enter.
const robot = require("robotjs");

// Type "Hello World".
robot.typeString("Hello World");

// Press enter.
robot.keyTap("enter");

[Screen](https://github.com/octalmage/robotjs/wiki/Syntax#screen)

js
// Get pixel color under the mouse.
const robot = require("robotjs");

// Get mouse position.
const mouse = robot.getMousePos();

// Get pixel color in hex format.
const hex = robot.getPixelColor(mouse.x, mouse.y);
console.log(`#${hex} at x:${mouse.x} y:${mouse.y}`);
js
const robot = require("robotjs");

const screen = robot.screen.capture();
const target = robot.image.load("./target.bmp");
const match = screen.findImage(target, { tolerance: 0.1 });

if (match) {
	screen.click(match, target);
}

Captured and loaded images also provide findImages, countImage, findColor,
findColors, countColor, colorAt, and save. Image searches return the
target's top-left capture coordinates. click converts those coordinates to
screen coordinates and clicks the target's center.
Read the Wiki for more information!

[API](http://robotjs.dev/docs/syntax)

The RobotJS API is hosted at https://robotjs.dev/docs/syntax.

macOS permissions

getAccessibilityPermission() and getScreenCapturePermission() report the
current grants. requestAccessibilityPermission() and
requestScreenCapturePermission() trigger the corresponding macOS system
prompts. macOS still requires the user to approve each request.
The Accessibility prompt is asynchronous, so requestAccessibilityPermission()
returns the current grant. Check getAccessibilityPermission() again after the
user responds.

Building

Please ensure you have the required dependencies before installing:

  • Windows
    • A supported Visual Studio C++ toolchain.
  • macOS
    • Xcode Command Line Tools.
  • Linux
    • Python 3.
    • make.
    • A C/C++ compiler like GCC.
    • libxtst-dev (sudo apt-get install libxtst-dev).

BMP image loading and saving is always available. PNG is enabled in all
published prebuilds: Windows uses Windows Imaging Component, while macOS and
Linux include statically linked libpng. PNG remains optional for macOS and
Linux source builds. To enable it, install libpng and pkg-config, then force
a source build with ROBOTJS_ENABLE_PNG=1. Check
robot.image.supportsPNG at runtime.

Install node-gyp using npm:

text
npm install node-gyp

Then build:

text
node-gyp rebuild

See the node-gyp readme for more details.

Packaging prebuilds

The Prebuilds workflow
builds the release binaries and uploads a complete npm-package artifact. It
does not publish to npm. Download the artifact, then publish it manually:

text
npm publish ./robotjs-<version>.tgz

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 images and colors in captures, and load or save bitmap files.
  • Possibly include window management?

Progress

Module Status Notes
Mouse 100% All planned features implemented.
Keyboard 100% All planned features implemented.
Screen 100% Screen capture, image search, and pixel search.
Bitmap 100% BMP I/O and optional PNG support.

FAQ

Does RobotJS support global hotkeys?

Not currently, and I don't know if it ever will. I personally use Electron/NW.js for global hotkeys, and this works well. Later on I might add hotkey support or create a separate module. See #55 for details.

Can I take a screenshot with RobotJS?

Yes. robot.screen.capture() captures the main display. Pass
x, y, width, height to capture a specific rectangle.

Why is <insert key> missing from the keyboard functions?

We've been implementing keys as we need them. Feel free to create an issue or submit a pull request!

How about multi-monitor support?

Use robot.getDisplays() to inspect displays and pass a rectangle from one
display to robot.screen.capture(x, y, width, height). A capture rectangle
cannot span multiple displays. Linux reports the current X11 screen.

For any other questions please submit an issue.

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 difficult in other languages. For example, it's imagesearch and pixel related functions are hard to reproduce on Mac, especially 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.

License

MIT

Based on autopy.
Maintained by Jason Stallings.

2. Official Technical Reference & Guides (octalmage/docs)

File: README.md

 

Building

Getting the repo

If you are contributing to the repository, make sure to fork this repo, and then clone your own fork. You will need to do this to make creating pull requests easier.

bash
git clone https://github.com/<your-username>/terra-docs

Adding an article

All articles are markdown files, placed under the /docs/ directory. You can create folders underneath the /docs directory, such as the following:

text
/docs
    /dev
        spec-auth.md
        ...
    /node
        installation.md
        ...

Notice how README.md serves as the default root of the folder.

Editing the navigation

To edit the navigation to include your new article, edit /docs/.vuepress/config.js and add your new article in the appropriate section in themeConfig.sidebar, following the other paths as examples.

Test it out locally

Make sure you install all the dependencies:

bash
npm install

Build and run locally (hot-reloading dev server):

bash
npm run dev

Organization

Module Specs

Each module should be documented with the following subheaders:

  1. Abstract (no header)

    Maximum 2 paragraphs to explain, in broad terms, the general purpose of the module, to provide a "big-picture" perspective of how the module provides functionality and organization to the Terra protocol, and how it interacts with other modules.

  2. Concepts

    A section dedicated to the concepts that are required to understand how the module works. This may include:

    • layman primer
    • math formulas (formatted with LaTeX)
    • diagrams
  3. Data

    A section that covers the various data structures used by the module.

  4. State

    A section that covers the keeper state for that module key-value store

  5. Messages

    A section that covers the various types of messages and gives a rough explanation on how they are handled.

  6. Proposals

    A section that covers the related governance proposals

  7. Transitions

    A section that covers the begin-blocker and end-blocker transition functions

  8. Parameters

    A section that covers the chain parameters that can be modified by governance via the params module

Built With

  • Vuepress
  • MathJax
  • Terra Docs custom theme

License

This software is licensed under the MIT license. See LICENSE for full disclosure.

ยฉ 2020 Terraform Labs, PTE.


 


File: docs/README.md

Terra Docs

Welcome to the official documentation for Terra, a decentralized financial infrastructure powering the innovation of money. Terra provides the foundational building blocks for a new digital economy with its stablecoin protocol, oracle system, smart contracts, and plan for mass-user adoption.

text
What is Terra?


  If this is your first time learning about Terra, start here.
text
What is Luna?


  Learn about Luna, the native staking asset that powers the Terra ecosystem.
text
Stability Mechanisms


  Learn about how Terra achieves price-stability while ensuring steady increase in validator incentives.
text
Run a Full Node


  Learn how to participate in the Terra network by running your own full Terra node.
text
Contribute to Core


  Hack on the latest version of Terra core, the node software for Terra.
text
Run a validator


  Become a validator and earn delegation commissions in exchange for helping secure the network.
text
Smart Contracts


  Build dApps that leverage the robust infrastructure for decentralized finance provided by Terra.
text
Integrations


  Discover novel applications built on Terra and integrations with existing tools.

SDKs for Developers

The Terra SDKs provide an easy way to programmatically interact with a Terra node with popular programming languages to develop applications. Currently, we have SDKs in Python 3 and JavaScript, with support for other runtimes coming soon in the near future.

text
Terra SDK


  Python SDK
text
Terra.js


  JavaScript SDK