Skip to content

Commit

Permalink
Merge branch 'master' into new-screenshot-code
Browse files Browse the repository at this point in the history
  • Loading branch information
octalmage committed Oct 15, 2016
2 parents e2ff6cd + a9e12ed commit fbadd72
Show file tree
Hide file tree
Showing 13 changed files with 393 additions and 153 deletions.
6 changes: 6 additions & 0 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
## How to contribute

* Please try to match the style of the code around the feature/bug you're working on.
* Use tabs not spaces.
* Please make sure your pull request only includes changes to the lines you're working on. For example, disable the whitespace extension when using Atom.
* All pull requests must include code for every platform (Mac, Windows, and Linux) before they can be merged. The exception is platform specific features. Feel free to submit a pull request with code for one platform and others can fill in the gaps to help get it merged.
32 changes: 32 additions & 0 deletions .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<!--- Provide a general summary of the issue in the Title above. -->

## Expected Behavior
<!--- If you're describing a bug, tell us what should happen. -->
<!--- If you're suggesting a change/improvement, tell us how it should work. -->

## Current Behavior
<!--- If describing a bug, tell us what happens instead of the expected behavior. -->
<!--- If suggesting a change/improvement, explain the difference from current behavior. -->

## Possible Solution
<!--- Not obligatory, but suggest a fix/reason for the bug, -->
<!--- or ideas how to implement the addition or change. -->

## Steps to Reproduce (for bugs)
<!--- Please provide an unambiguous set of steps to reproduce this bug. -->
<!--- Include code to reproduce. -->
1.
2.
3.
4.

## Context
<!--- How has this issue affected you? What are you trying to accomplish? -->
<!--- Providing context helps us come up with a solution that is most useful in the real world. -->

## Your Environment
<!--- Include as many relevant details about the environment you experienced the bug in. -->
* RobotJS version:
* Node.js version:
* npm version:
* Operating System:
50 changes: 35 additions & 15 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
sudo: false
env:
- CXX=g++-4.8
language: node_js
language: cpp

node_js:
- 0.8
- 0.10
- 0 #Latest 0.x.x build.
- 3 #Latest io.js build.
- 4.2.4 #LTS
- stable
os:
- linux
- osx

matrix:
allow_failures:
- node_js: 0.8
env:
matrix:
- TRAVIS_NODE_VERSION="0.10"
- TRAVIS_NODE_VERSION="0.12"
- TRAVIS_NODE_VERSION="4"
- TRAVIS_NODE_VERSION="5"
- TRAVIS_NODE_VERSION="6"
- TRAVIS_NODE_VERSION="stable"

addons:
apt:
Expand All @@ -27,9 +26,30 @@ addons:
- g++-4.8
- gcc-4.8

before_install:
# reinstall latest nvm
- rm -rf ~/.nvm && git clone https://github.com/creationix/nvm.git ~/.nvm && (cd ~/.nvm && git checkout `git describe --abbrev=0 --tags`) && source ~/.nvm/nvm.sh
- nvm install $TRAVIS_NODE_VERSION
- PATH=$PATH:`pwd`/node_modules/.bin

# print versions
- node --version
- npm --version

# use g++-4.8 on Linux
- if [[ $TRAVIS_OS_NAME == "linux" ]]; then export CXX=g++-4.8; fi
- $CXX --version

before_script:
- export DISPLAY=:99.0
- sh -e /etc/init.d/xvfb start
# Start xvfb
- if [[ $TRAVIS_OS_NAME == "linux" ]]; then export DISPLAY=:99.0; fi
- if [[ $TRAVIS_OS_NAME == "linux" ]]; then sh -e /etc/init.d/xvfb start; fi

install:
- npm install

script:
- npm test

notifications:
webhooks:
Expand Down
74 changes: 39 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<p align="center"><img src="https://cldup.com/1ATDf2JMtv.png"></p>
========

<p align="center"><a href="https://travis-ci.org/octalmage/robotjs"><img src="https://api.travis-ci.org/octalmage/robotjs.svg?branch=master"></a> <a href="https://ci.appveyor.com/project/octalmage/robotjs"><img src="https://ci.appveyor.com/api/projects/status/qh2eqb37j7ap6x36?svg=true"></a> <a href="https://www.npmjs.com/package/robotjs"><img src="https://img.shields.io/npm/v/robotjs.svg"></a> <a href="https://gitter.im/octalmage/robotjs?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge"><img src="https://img.shields.io/badge/gitter-join%20chat-blue.svg"></a> <a href="https://github.com/dthree/wat"><img src="https://img.shields.io/badge/wat-documented-blue.svg"></a></p>
<p align="center"><a href="https://travis-ci.org/octalmage/robotjs"><img src="https://api.travis-ci.org/octalmage/robotjs.svg?branch=master"></a> <a href="https://ci.appveyor.com/project/octalmage/robotjs"><img src="https://ci.appveyor.com/api/projects/status/qh2eqb37j7ap6x36?svg=true"></a> <a href="https://www.npmjs.com/package/robotjs"><img src="https://img.shields.io/npm/v/robotjs.svg"></a> <a href="https://gitter.im/octalmage/robotjs?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge"><img src="https://img.shields.io/badge/gitter-join%20chat-blue.svg"></a> <a href="http://waffle.io/octalmage/robotjs"><img src="https://img.shields.io/waffle/label/octalmage/robotjs/ready.svg?maxAge=3600"></a></p>

> Node.js Desktop Automation. Control the mouse, keyboard, and read the screen.
Expand All @@ -26,37 +26,28 @@ This is a work in progress so the exported functions could change at any time be

## Installation

Please ensure you have the [required dependencies](https://github.com/nodejs/node-gyp#installation) before installing:

* Windows
* Visual Studio 2013 (Express works fine).
* Python (v2.7.3 recommended, v3.x.x is not supported).
* Mac
* Xcode Command Line Tools.
* Linux
* Python (v2.7 recommended, v3.x.x is not supported).
* make.
* A C/C++ compiler like GCC.
* libxtst-dev and libpng++-dev (`sudo apt-get install libxtst-dev libpng++-dev`).

Then install RobotJS using npm:
Install RobotJS using npm:

```
npm install robotjs
```
I [plan on](https://github.com/octalmage/robotjs/issues/64) using node-pre-gyp to make this process easier.
It's that easy! npm will download one of the prebuilt [binaries](https://github.com/octalmage/robotjs/releases/latest) for your OS.

You can get npm [here](https://nodejs.org/en/download/) if you don't have it installed.

If you need to build RobotJS, see the [building](#building) section. Instructions for [Electron](https://github.com/octalmage/robotjs/wiki/Electron).

## Examples

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

![](https://cloudup.com/cw5JY2cusx3+)
<p align="center"><img src="https://cldup.com/lugVjjAkEi.gif"></p>

```JavaScript
//Move the mouse across the screen as a sine wave.
// Move the mouse across the screen as a sine wave.
var robot = require("robotjs");

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

var twoPI = Math.PI * 2.0;
Expand All @@ -74,26 +65,26 @@ for (var x = 0; x < width; x++)
##### [Keyboard](https://github.com/octalmage/robotjs/wiki/Syntax#keyboard)

```JavaScript
//Type "Hello World" then press enter.
// Type "Hello World" then press enter.
var robot = require("robotjs");

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

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

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

```JavaScript
//Get pixel color under the mouse.
// Get pixel color under the mouse.
var robot = require("robotjs");

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

//Get pixel color in hex format.
// Get pixel color in hex format.
var hex = robot.getPixelColor(mouse.x, mouse.y);
console.log("#" + hex + " at x:" + mouse.x + " y:" + mouse.y);
```
Expand All @@ -105,36 +96,49 @@ The [RobotJS API](https://github.com/octalmage/robotjs/wiki/Syntax) is contained

## Building

node-gyp is required to build RobotJS.
Please ensure you have the required dependencies before installing:

* Windows
* Visual Studio 2013 (Express works fine).
* Python (v2.7.3 recommended, v3.x.x is not supported).
* Mac
* Xcode Command Line Tools.
* Linux
* Python (v2.7 recommended, v3.x.x is not supported).
* make.
* A C/C++ compiler like GCC.
* libxtst-dev and libpng++-dev (`sudo apt-get install libxtst-dev libpng++-dev`).

Install node-gyp using npm:

```
npm install -g node-gyp
```

Then configure and build:
Then build:

```
node-gyp configure
node-gyp build
node-gyp rebuild
```

See the [node-gyp readme](https://github.com/nodejs/node-gyp#installation) for more details.

## 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?
* 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 an image on screen, read pixels from an image.
* Possibly include window management?

## Progress

| Module | Status | Notes |
| ------------- |-------------: | ------- |
| Mouse | 100% | All planned features implemented. |
| Keyboard | 100% | All planned features implemented. |
| Screen | 10% | Screenshot, image search. |
| Screen | 85% | Image search, pixel search. |
| Bitmap | 0% | Saving/opening, png support. |

## FAQ

Expand Down
12 changes: 4 additions & 8 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,13 @@
environment:
matrix:
# node.js
- nodejs_version: "0.8"
- nodejs_version: "0.10"
- nodejs_version: "0" #Latest 0.x.x build.
- nodejs_version: "3" #Latest io.js build.
- nodejs_version: "4.2.4" #LTS
- nodejs_version: "0.12"
- nodejs_version: "4"
- nodejs_version: "5"
- nodejs_version: "6"
- nodejs_version: "Stable"

matrix:
allow_failures:
- nodejs_version: "0.8" #Allow Node.js 0.8.x to fail.

# Install scripts. (runs after repo cloning)
install:
# Get the latest stable version of Node 0.STABLE.latest
Expand Down
31 changes: 31 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
export interface Bitmap {
width: number
height: number
image: any
byteWidth: number
bitsPerPixel: number
bytesPerPixel: number
colorAt(x: number, y: number): string
}

export interface Screen {
capture(x?: number, y?: number, width?: number, height?: number): Bitmap
}

export function setKeyboardDelay(ms: number) : void
export function keyTap(key: string, modifier?: string | string[]) : void
export function keyToggle(key: string, down: string, modifier?: string | string[]) : void
export function typeString(string: string) : void
export function typeStringDelayed(string: string, cpm: number) : void
export function setMouseDelay(delay: number) : void
export function moveMouse(x: number, y: number) : void
export function moveMouseSmooth(x: number, y: number) : void
export function mouseClick(button?: string, double?: boolean) : void
export function mouseToggle(down?: string, button?: boolean) : void
export function dragMouse(x: number, y: number) : void
export function scrollMouse(magnitude: number, direction: string) : void
export function getMousePos(): { x: number, y: number }
export function getPixelColor(x: number, y: number): string
export function getScreenSize(): { width: number, height: number }

export var screen: Screen
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"name": "robotjs",
"version": "0.4.2",
"version": "0.4.4",
"description": "Node.js Desktop Automation.",
"main": "index.js",
"typings": "index.d.ts",
"scripts": {
"test": "node test/all.js",
"install": "prebuild --install"
Expand Down
Loading

0 comments on commit fbadd72

Please sign in to comment.