From 239c29810bb75d47dde1853f311bf23a5d22ad70 Mon Sep 17 00:00:00 2001 From: vCaesar Date: Mon, 24 Oct 2016 14:06:20 +0800 Subject: [PATCH] Update CaptureScreen --- robotgo.go | 26 +++++++++++++++++++++++--- screen/goScreen.h | 2 +- test/main.go | 3 +++ 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/robotgo.go b/robotgo.go index b30c823..c4bd2b0 100644 --- a/robotgo.go +++ b/robotgo.go @@ -74,13 +74,33 @@ func SetXDisplayName(name string) string { return gstr } -func CaptureScreen(x, y, w, h C.int) C.MMBitmapRef { +func CaptureScreen(args ...int) C.MMBitmapRef { + var x C.size_t + var y C.size_t + var w C.size_t + var h C.size_t + Try(func() { + x = C.size_t(args[1]) + y = C.size_t(args[2]) + w = C.size_t(args[3]) + h = C.size_t(args[4]) + }, func(e interface{}) { + // Println("err:::", e) + x = 0 + y = 0 + //Get screen size. + var displaySize C.MMSize + displaySize = C.getMainDisplaySize() + w = displaySize.width + h = displaySize.height + }) + bit := C.aCaptureScreen(x, y, w, h) - Println("...", bit.width) + // Println("...", bit.width) return bit } -func Capture_Screen(x, y, w, h C.int) Bit_map { +func Capture_Screen(x, y, w, h C.size_t) Bit_map { bit := C.aCaptureScreen(x, y, w, h) // Println("...", bit) bit_map := Bit_map{ diff --git a/screen/goScreen.h b/screen/goScreen.h index 2dec9e4..8344e49 100644 --- a/screen/goScreen.h +++ b/screen/goScreen.h @@ -67,7 +67,7 @@ char* aSetXDisplayName(char* name){ #endif } -MMBitmapRef aCaptureScreen(int x,int y,int w,int h){ +MMBitmapRef aCaptureScreen(size_t x,size_t y,size_t w,size_t h){ // if (){ // x = 0; // y = 0; diff --git a/test/main.go b/test/main.go index d0797e1..0c2896b 100644 --- a/test/main.go +++ b/test/main.go @@ -32,6 +32,9 @@ func arobotgo() { // robotgo.KeyToggle("enter", "down") robotgo.TypeString("en") + abit_map := robotgo.CaptureScreen() + Println("all...", abit_map) + bit_map := robotgo.CaptureScreen(10, 20, 30, 40) Println("...", bit_map)