Skip to content

Commit

Permalink
Fixed merge conflicts.
Browse files Browse the repository at this point in the history
  • Loading branch information
octalmage committed Jan 27, 2015
2 parents 19261d7 + d9b1d98 commit a896fb8
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 64 deletions.
45 changes: 42 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,19 @@ 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).

Only tested on Mac OS X using Node.js v0.10.31. I'm working on rewriting RobotJS using [nan](https://github.com/rvagg/nan) to support other versions of Node.js. node-gyp is only configured for Mac, but this project will support Windows and Linux when I have time to test.

Based on [autopy](https://github.com/msanders/autopy).

##Installing##
##Installing

```
npm install robotjs
```

##Examples##
##Examples
Get the mouse location and move it.

```JavaScript
Expand All @@ -26,11 +31,45 @@ robot.moveMouse(mouse.x,mouse.y+100);
//Left click!
robot.mouseClick();
```
##Progress##

##Building

RobotJS uses [node-gyp](https://github.com/TooTallNate/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 mouse 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](http://www.autohotkey.com/), 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](https://www.autohotkey.com/docs/commands/ImageSearch.htm) and [pixel](https://www.autohotkey.com/docs/commands/PixelGetColor.htm) 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](http://blueshirtdesign.com/apps/autoflix/). 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.
2 changes: 1 addition & 1 deletion binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
}
]
],
"sources": ["src/robotjs.cc", "src/deadbeef_rand.c", "src/mouse.c", "src/screen.c", "src/keypress.c" , "src/keycode.c", "src/screengrab.c", "src/MMBitmap.c"]
"sources": ["src/robotjs.cc", "src/deadbeef_rand.c", "src/mouse.c", "src/keypress.c" , "src/keycode.c"]
}
]
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "robotjs",
"version": "0.0.2",
"version": "0.0.3",
"description": "Node.js GUI Automation.",
"main": "index.js",
"scripts": {
Expand Down
60 changes: 1 addition & 59 deletions src/robotjs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
#include <vector>
#include "mouse.h"
#include "deadbeef_rand.h"
#include "screen.h"
#include "screengrab.h"
#include "keypress.h"

using namespace v8;
Expand All @@ -16,6 +14,7 @@ using namespace v8;
| |\/| |/ _ \| | | / __|/ _ \
| | | | (_) | |_| \__ \ __/
|_| |_|\___/ \__,_|___/\___|
*/

Handle<Value> moveMouse(const Arguments& args)
Expand Down Expand Up @@ -108,62 +107,6 @@ Handle<Value> typeString(const Arguments& args)
return scope.Close(String::New("1"));
}

//Screen

Handle<Value> captureScreen(const Arguments& args)
{
HandleScope scope;

MMRect rect;
MMBitmapRef bitmap = NULL;
MMSize displaySize = getMainDisplaySize();

rect = MMRectMake(0, 0, displaySize.width, displaySize.height);

bitmap = copyMMBitmapFromDisplayInRect(rect);

return scope.Close(External::Wrap(bitmap));

//return scope.Close(String::New("1"));
}

Handle<Value> getWindows(const Arguments& args)
{
HandleScope scope;

CFArrayRef windowList = CGWindowListCopyWindowInfo(kCGWindowListOptionOnScreenOnly, kCGNullWindowID);
CFIndex windowNum = CFArrayGetCount(windowList);

std::vector<Object> windows;
Local<Object> obj = Object::New();


for (int i = 0; i < (int)windowNum; i++)
{
CFDictionaryRef info = (CFDictionaryRef)CFArrayGetValueAtIndex(windowList, i);
CFNumberRef currentPID = (CFNumberRef)CFDictionaryGetValue(info, kCGWindowOwnerPID);
CFNumberRef currentWindowNumber = (CFNumberRef)CFDictionaryGetValue(info, kCGWindowNumber);
CFStringRef currentTitle = (CFStringRef)CFDictionaryGetValue(info, kCGWindowName);
CFIndex length = CFStringGetLength(currentTitle);
CFIndex maxSize = CFStringGetMaximumSizeForEncoding(length, kCFStringEncodingUTF8);
char *buffer = (char *)malloc(maxSize);
CFStringGetCString(currentTitle, buffer, maxSize, kCFStringEncodingUTF8);
obj->Set(String::NewSymbol("title"), String::New(buffer));
obj->Set(String::NewSymbol("id"), Number::New(*(int *)currentWindowNumber));
printf(buffer);
printf("\n");
//windows.push_back(obj);

}



//return scope.Close(String::New("1"));

return scope.Close(String::New("1"));
}


void init(Handle<Object> target)
{

Expand All @@ -187,7 +130,6 @@ void init(Handle<Object> target)

target->Set(NanNew<String>("getWindows"),
NanNew<FunctionTemplate>(getWindows)->GetFunction());

}

NODE_MODULE(robotjs, init)

0 comments on commit a896fb8

Please sign in to comment.