Skip to content

Commit

Permalink
Added getPixelColor.
Browse files Browse the repository at this point in the history
  • Loading branch information
octalmage committed Feb 4, 2015
1 parent ea69110 commit f250355
Showing 1 changed file with 42 additions and 2 deletions.
44 changes: 42 additions & 2 deletions src/robotjs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
#include "mouse.h"
#include "deadbeef_rand.h"
#include "keypress.h"
#include "screen.h"
#include "screengrab.h"
#include "MMBitmap.h"

using namespace v8;

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

NAN_METHOD(moveMouse)
{
Expand Down Expand Up @@ -80,7 +83,7 @@ NAN_METHOD(mouseClick)
| . \ __/ |_| | |_) | (_) | (_| | | | (_| |
|_|\_\___|\__, |_.__/ \___/ \__,_|_| \__,_|
|___/
*/
*/

NAN_METHOD (keyTap)
{
Expand Down Expand Up @@ -109,6 +112,40 @@ NAN_METHOD (typeString)
NanReturnValue(NanNew("1"));
}

/*
____
/ ___| ___ _ __ ___ ___ _ __
\___ \ / __| '__/ _ \/ _ \ '_ \
___) | (__| | | __/ __/ | | |
|____/ \___|_| \___|\___|_| |_|
*/

NAN_METHOD (getPixelColor)
{
NanScope();

MMBitmapRef bitmap;
MMRGBHex color;

size_t x = args[0]->Int32Value();
size_t y = args[1]->Int32Value();

bitmap = copyMMBitmapFromDisplayInRect(MMRectMake(x, y, 1, 1));

color = MMRGBHexAtPoint(bitmap, 0, 0);

char hex [6];

//Length needs to be 7 because snprintf includes a terminating null.
//Use %06x to pad hex value with leading 0s.
snprintf(hex, 7, "%06x", color);

destroyMMBitmap(bitmap);

NanReturnValue(NanNew(hex));
}

void init(Handle<Object> target)
{

Expand All @@ -130,6 +167,9 @@ void init(Handle<Object> target)
target->Set(NanNew<String>("typeString"),
NanNew<FunctionTemplate>(typeString)->GetFunction());

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

}

NODE_MODULE(robotjs, init)

0 comments on commit f250355

Please sign in to comment.