Skip to content

Commit bb2ab38

Browse files
committed
Allow x, y, width, and height to be passed.
1 parent 0cd6db2 commit bb2ab38

File tree

1 file changed

+29
-3
lines changed

1 file changed

+29
-3
lines changed

src/robotjs.cc

+29-3
Original file line numberDiff line numberDiff line change
@@ -642,10 +642,36 @@ NAN_METHOD(getScreenSize)
642642
}
643643

644644
NAN_METHOD(captureScreen)
645-
{
646-
MMSize displaySize = getMainDisplaySize();
645+
{
646+
size_t x;
647+
size_t y;
648+
size_t w;
649+
size_t h;
650+
651+
//If user has provided screen coords, use them!
652+
if (info.Length() == 4)
653+
{
654+
//TODO: Make sure requested coords are within the screen bounds, or we get a seg fault.
655+
// An error message is much nicer!
656+
657+
x = info[0]->Int32Value();
658+
y = info[1]->Int32Value();
659+
w = info[2]->Int32Value();
660+
h = info[3]->Int32Value();
661+
}
662+
else
663+
{
664+
//We're getting the full screen.
665+
x = 0;
666+
y = 0;
667+
668+
//Get screen size.
669+
MMSize displaySize = getMainDisplaySize();
670+
w = displaySize.width;
671+
h = displaySize.height;
672+
}
647673

648-
MMBitmapRef bitmap = copyMMBitmapFromDisplayInRect(MMRectMake(0, 0, displaySize.width, displaySize.height));
674+
MMBitmapRef bitmap = copyMMBitmapFromDisplayInRect(MMRectMake(x, y, w, h));
649675

650676
uint32_t bufferSize = bitmap->bytesPerPixel * bitmap->width * bitmap->height;
651677
Local<Object> buffer = Nan::NewBuffer((char*)bitmap->imageBuffer, bufferSize, destroyMMBitmapBuffer, NULL).ToLocalChecked();

0 commit comments

Comments
 (0)