Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/octalmage/robotjs
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/robotjs.cc
  • Loading branch information
BHamrick1 committed Jan 10, 2017
2 parents e16b821 + dfd7e60 commit 0fef6e8
Show file tree
Hide file tree
Showing 15 changed files with 299 additions and 61 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:
7 changes: 7 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Copyright (c) 2014 Jason Stallings

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 changes: 10 additions & 10 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 Down Expand Up @@ -35,7 +35,7 @@ It's that easy! npm will download one of the prebuilt [binaries](https://github.

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.
If you need to build RobotJS, see the [building](#building) section. Instructions for [Electron](https://github.com/octalmage/robotjs/wiki/Electron).

## Examples

Expand All @@ -44,10 +44,10 @@ If you need to build RobotJS, see the [building](#building) section.
<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 @@ -65,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 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
7 changes: 4 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ function bitmap(width, height, byteWidth, bitsPerPixel, bytesPerPixel, image)
this.bitsPerPixel = bitsPerPixel;
this.bytesPerPixel = bytesPerPixel;
this.image = image;

this.colorAt = function(x, y)
{
return robotjs.getColor(this, x, y);
};

}

module.exports.screen.capture = function(x, y, width, height)
Expand All @@ -30,6 +31,6 @@ module.exports.screen.capture = function(x, y, width, height)
{
b = robotjs.captureScreen();
}

return new bitmap(b.width, b.height, b.byteWidth, b.bitsPerPixel, b.bytesPerPixel, b.image);
};
};
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.4",
"version": "0.4.5",
"description": "Node.js Desktop Automation.",
"main": "index.js",
"typings": "index.d.ts",
"scripts": {
"test": "node test/all.js",
"install": "prebuild --install"
Expand Down
9 changes: 9 additions & 0 deletions src/bmp_io.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
#include "MMBitmap.h"
#include "io.h"

#ifdef __cplusplus
extern "C"
{
#endif

enum _BMPReadError {
kBMPGenericError = 0,
kBMPAccessError,
Expand Down Expand Up @@ -51,4 +56,8 @@ int saveMMBitmapAsBMP(MMBitmapRef bitmap, const char *path);
*/
void flipBitmapData(void *data, size_t width, size_t height, size_t bytewidth);

#ifdef __cplusplus
}
#endif

#endif /* BMP_IO_H */
9 changes: 9 additions & 0 deletions src/io.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
#include <stddef.h>
#include <stdint.h>

#ifdef __cplusplus
extern "C"
{
#endif

enum _MMImageType {
kInvalidImageType = 0,
Expand Down Expand Up @@ -43,4 +47,9 @@ int saveMMBitmapToFile(MMBitmapRef bitmap, const char *path, MMImageType type);
* Returned string is constant and hence should not be freed. */
const char *MMIOErrorString(MMImageType type, MMIOError error);

#ifdef __cplusplus
}
#endif


#endif /* IO_H */
36 changes: 36 additions & 0 deletions src/keycode.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,18 @@ enum _MMKeyCode {
K_F10 = kVK_F10,
K_F11 = kVK_F11,
K_F12 = kVK_F12,
K_F13 = kVK_F13,
K_F14 = kVK_F14,
K_F15 = kVK_F15,
K_F16 = kVK_F16,
K_F17 = kVK_F17,
K_F18 = kVK_F18,
K_F19 = kVK_F19,
K_F20 = kVK_F20,
K_F21 = K_NOT_A_KEY,
K_F22 = K_NOT_A_KEY,
K_F23 = K_NOT_A_KEY,
K_F24 = K_NOT_A_KEY,
K_META = kVK_Command,
K_ALT = kVK_Option,
K_CONTROL = kVK_Control,
Expand Down Expand Up @@ -117,6 +129,18 @@ enum _MMKeyCode {
K_F10 = XK_F10,
K_F11 = XK_F11,
K_F12 = XK_F12,
K_F13 = XK_F13,
K_F14 = XK_F14,
K_F15 = XK_F15,
K_F16 = XK_F16,
K_F17 = XK_F17,
K_F18 = XK_F18,
K_F19 = XK_F19,
K_F20 = XK_F20,
K_F21 = XK_F21,
K_F22 = XK_F22,
K_F23 = XK_F23,
K_F24 = XK_F24,
K_META = XK_Super_L,
K_ALT = XK_Alt_L,
K_CONTROL = XK_Control_L,
Expand Down Expand Up @@ -189,6 +213,18 @@ enum _MMKeyCode {
K_F10 = VK_F10,
K_F11 = VK_F11,
K_F12 = VK_F12,
K_F13 = VK_F13,
K_F14 = VK_F14,
K_F15 = VK_F15,
K_F16 = VK_F16,
K_F17 = VK_F17,
K_F18 = VK_F18,
K_F19 = VK_F19,
K_F20 = VK_F20,
K_F21 = VK_F21,
K_F22 = VK_F22,
K_F23 = VK_F23,
K_F24 = VK_F24,
K_META = VK_LWIN,
K_CONTROL = VK_CONTROL,
K_SHIFT = VK_SHIFT,
Expand Down
Loading

0 comments on commit 0fef6e8

Please sign in to comment.