diff --git a/README.md b/README.md index 8a5274d..cae9d07 100644 --- a/README.md +++ b/README.md @@ -132,11 +132,12 @@ func main() { robotgo.ScrollMouse(10, "up") robotgo.Scroll(100, 200) - robotgo.MoveMouse(10, 10) + robotgo.Move(10, 10) robotgo.Drag(10, 10) - robotgo.MouseClick("left", true) - robotgo.MoveMouseSmooth(100, 200, 1.0, 100.0) + robotgo.Click("left", true) + robotgo.MoveSmooth(100, 200, 1.0, 100.0) + robotgo.MouseToggle("up") } ``` @@ -169,6 +170,8 @@ func main() { arr := []string{"alt", "command"} robotgo.KeyTap("i", arr) + robotgo.KeyToggle("a", "down") + robotgo.WriteAll("Test") text, err := robotgo.ReadAll() if err == nil { @@ -186,6 +189,7 @@ import ( "fmt" "github.com/go-vgo/robotgo" + "github.com/vcaesar/imgo" ) func main() { @@ -197,6 +201,13 @@ func main() { sx, sy := robotgo.GetScreenSize() fmt.Println("get screen size: ", sx, sy) + + bit := robotgo.CaptureScreen(10, 10, 30, 30) + defer robotgo.FreeBitmap(bit) + robotgo.SaveBitmap(bit, "test_1.png") + + img := robotgo.ToImage(bit) + imgo.Save("test.png", img) } ``` @@ -248,6 +259,15 @@ func opencv() { defer robotgo.FindBitmap(bit) fmt.Print("find bitmap: ") fmt.Println(robotgo.FindBitmap(bit)) + + bit0 := robotgo.CaptureScreen() + img := robotgo.ToImage(bit0) + bit1 := robotgo.CaptureScreen(10, 10, 30, 30) + img1 := robotgo.ToImage(bit1) + defer robotgo.FreeBitmapArr(bit0, bit1) + + fmt.Print("gcv find image: ") + fmt.Println(gcv.FindImg(img1, img)) } ``` diff --git a/README_zh.md b/README_zh.md index 502a0f4..c6c1742 100644 --- a/README_zh.md +++ b/README_zh.md @@ -130,11 +130,12 @@ func main() { robotgo.ScrollMouse(10, "up") robotgo.Scroll(100, 200) - robotgo.MoveMouse(10, 10) + robotgo.Move(10, 10) robotgo.Drag(10, 10) - robotgo.MouseClick("left", true) - robotgo.MoveMouseSmooth(100, 200, 1.0, 100.0) + robotgo.Click("left", true) + robotgo.MoveSmooth(100, 200, 1.0, 100.0) + robotgo.MouseToggle("up") } ``` @@ -167,6 +168,8 @@ func main() { arr := []string{"alt", "command"} robotgo.KeyTap("i", arr) + robotgo.KeyToggle("a", "down") + robotgo.WriteAll("テストする") text, err := robotgo.ReadAll() if err == nil { @@ -184,6 +187,7 @@ import ( "fmt" "github.com/go-vgo/robotgo" + "github.com/vcaesar/imgo" ) func main() { @@ -195,6 +199,13 @@ func main() { sx, sy := robotgo.GetScreenSize() fmt.Println("get screen size: ", sx, sy) + + bit := robotgo.CaptureScreen(10, 10, 30, 30) + defer robotgo.FreeBitmap(bit) + robotgo.SaveBitmap(bit, "test_1.png") + + img := robotgo.ToImage(bit) + imgo.Save("test.png", img) } ``` @@ -246,6 +257,15 @@ func opencv() { defer robotgo.FindBitmap(bit) fmt.Print("find bitmap: ") fmt.Println(robotgo.FindBitmap(bit)) + + bit0 := robotgo.CaptureScreen() + img := robotgo.ToImage(bit0) + bit1 := robotgo.CaptureScreen(10, 10, 30, 30) + img1 := robotgo.ToImage(bit1) + defer robotgo.FreeBitmapArr(bit0, bit1) + + fmt.Print("gcv find image: ") + fmt.Println(gcv.FindImg(img1, img)) } ``` diff --git a/robotgo.go b/robotgo.go index 0a192ed..2b232d2 100644 --- a/robotgo.go +++ b/robotgo.go @@ -1215,12 +1215,19 @@ func Convert(opath, spath string, args ...int) { SaveBitmap(bitmap, spath, mtype) } -// FreeBitmap free and dealloc bitmap +// FreeBitmap free and dealloc the C bitmap func FreeBitmap(bitmap C.MMBitmapRef) { // C.destroyMMBitmap(bitmap) C.bitmap_dealloc(bitmap) } +// FreeBitmapArr free and dealloc the C bitmap array +func FreeBitmapArr(bit ...C.MMBitmapRef) { + for i := 0; i < len(bit); i++ { + FreeBitmap(bit[i]) + } +} + // ReadBitmap returns false and sets error if |bitmap| is NULL func ReadBitmap(bitmap C.MMBitmapRef) bool { abool := C.bitmap_ready(bitmap)