diff --git a/src/robotjs.cc b/src/robotjs.cc index f517790f..a76d6260 100644 --- a/src/robotjs.cc +++ b/src/robotjs.cc @@ -472,6 +472,30 @@ NAN_METHOD(getScreenSize) NanReturnValue(obj); } +NAN_METHOD(getScreenImage) +{ + NanScope(); + + size_t x = args[0]->Int32Value(); + size_t y = args[1]->Int32Value(); + size_t w = args[2]->Int32Value(); + size_t h = args[3]->Int32Value(); + MMBitmapRef bitmap = copyMMBitmapFromDisplayInRect(MMRectMake(x, y, w, h)); + uint32_t bufferSize = bitmap->bytesPerPixel * bitmap->width * bitmap->height; + Local buffer = NanNewBufferHandle((char*)bitmap->imageBuffer, bufferSize); + + Local obj = NanNew(); + obj->Set(NanNew("width"), NanNew(bitmap->width)); + obj->Set(NanNew("height"), NanNew(bitmap->height)); + obj->Set(NanNew("byteWidth"), NanNew(bitmap->bytewidth)); + obj->Set(NanNew("bitsPerPixel"), NanNew(bitmap->bitsPerPixel)); + obj->Set(NanNew("bytesPerPixel"), NanNew(bitmap->bytesPerPixel)); + obj->Set(NanNew("image"), buffer); + + destroyMMBitmap(bitmap); + NanReturnValue(obj); +} + void init(Handle target) { @@ -492,7 +516,7 @@ void init(Handle target) target->Set(NanNew("keyTap"), NanNew(keyTap)->GetFunction()); - + target->Set(NanNew("keyToggle"), NanNew(keyToggle)->GetFunction()); @@ -505,6 +529,9 @@ void init(Handle target) target->Set(NanNew("getScreenSize"), NanNew(getScreenSize)->GetFunction()); + target->Set(NanNew("getScreenImage"), + NanNew(getScreenImage)->GetFunction()); + } NODE_MODULE(robotjs, init)