From 15d5d147bc92398d2363e217af6b5e0a7d01fb08 Mon Sep 17 00:00:00 2001 From: vcaesar Date: Wed, 17 Nov 2021 14:16:30 -0400 Subject: [PATCH 1/4] Update README.md --- README.md | 41 ++++++++++++++++++++++++++--------------- README_zh.md | 38 +++++++++++++++++++++++--------------- 2 files changed, 49 insertions(+), 30 deletions(-) diff --git a/README.md b/README.md index 220a6a9..36eea26 100644 --- a/README.md +++ b/README.md @@ -36,9 +36,10 @@ RobotGo supports Mac, Windows, and Linux(X11); and robotgo supports arm64 and x8 - [License](#license) ## Docs - - [GoDoc](https://godoc.org/github.com/go-vgo/robotgo) - - [API Docs](https://github.com/go-vgo/robotgo/blob/master/docs/doc.md)     - - [Chinese Docs](https://github.com/go-vgo/robotgo/blob/master/docs/doc_zh.md) + - [GoDoc](https://godoc.org/github.com/go-vgo/robotgo)
+ + - [API Docs](https://github.com/go-vgo/robotgo/blob/master/docs/doc.md)     (Deprecated, no updated) + - [Chinese Docs](https://github.com/go-vgo/robotgo/blob/master/docs/doc_zh.md) (Deprecated, no updated) ## Binding: [ADB](https://github.com/vcaesar/adb), packaging android adb API. @@ -57,14 +58,17 @@ GCC ``` #### For Mac OS X: + +Xcode Command Line Tools (And Privacy setting: #277 ) + ``` -Xcode Command Line Tools +xcode-select --install ``` #### For Windows: -``` -MinGW-w64 (Use recommended) or other GCC -``` + +[MinGW-w64](https://sourceforge.net/projects/mingw-w64/files) (Use recommended) or other GCC + #### For everything else: @@ -81,12 +85,12 @@ xcb, xkb, libxkbcommon ##### Ubuntu: ```yml +# gcc sudo apt install gcc libc6-dev sudo apt install libx11-dev xorg-dev libxtst-dev libpng++-dev -sudo apt install xcb libxcb-xkb-dev x11-xkb-utils libx11-xcb-dev libxkbcommon-x11-dev -sudo apt install libxkbcommon-dev +sudo apt install xcb libxcb-xkb-dev x11-xkb-utils libx11-xcb-dev libxkbcommon-x11-dev libxkbcommon-dev sudo apt install xsel xclip ``` @@ -130,19 +134,25 @@ import ( ) func main() { - robotgo.ScrollMouse(10, "up") - robotgo.Scroll(100, 200) + // robotgo.ScrollMouse(10, "up") + robotgo.Scroll(0, -10) + robotgo.Scroll(100, 0) + robotgo.MilliSleep(100) - robotgo.ScrollRelative(10, -100) + robotgo.ScrollSmooth(-10, 6) + // robotgo.ScrollRelative(10, -100) robotgo.MouseSleep = 100 robotgo.Move(10, 20) robotgo.MoveRelative(0, -10) robotgo.Drag(10, 10) + robogo.Click("wheelRight") robotgo.Click("left", true) - robotgo.MoveSmooth(100, 200, 1.0, 100.0) - robotgo.MouseToggle("up") + robotgo.MoveSmooth(100, 200, 1.0, 10.0) + + robotgo.Toggle("left") + robotgo.Toggle("left", "up") } ``` @@ -177,7 +187,8 @@ func main() { robotgo.KeyTap("i", arr) robotgo.MilliSleep(100) - robotgo.KeyToggle("a", "down") + robogo.KeyToggle("a") + robotgo.KeyToggle("a", "up") robotgo.WriteAll("Test") text, err := robotgo.ReadAll() diff --git a/README_zh.md b/README_zh.md index 474789a..8e013ff 100644 --- a/README_zh.md +++ b/README_zh.md @@ -32,9 +32,10 @@ RobotGo 支持 Mac, Windows, and Linux(X11). - [License](#license) ## Docs -- [GoDoc](https://godoc.org/github.com/go-vgo/robotgo) -- [中文文档](https://github.com/go-vgo/robotgo/blob/master/docs/doc_zh.md)    -- [English Docs](https://github.com/go-vgo/robotgo/blob/master/docs/doc.md) +- [GoDoc](https://godoc.org/github.com/go-vgo/robotgo)
+ +- [中文文档](https://github.com/go-vgo/robotgo/blob/master/docs/doc_zh.md)    (弃用) +- [English Docs](https://github.com/go-vgo/robotgo/blob/master/docs/doc.md) (弃用) ## Binding: @@ -53,14 +54,17 @@ GCC ``` #### For Mac OS X: + +Xcode Command Line Tools (And Privacy setting: #277 ) + ``` -Xcode Command Line Tools +xcode-select --install ``` #### For Windows: -``` -MinGW-w64 (推荐使用) or other GCC -``` + +[MinGW-w64](https://sourceforge.net/projects/mingw-w64/files) (推荐使用) or other GCC + #### For everything else (Linux 等其他系统): @@ -81,8 +85,7 @@ sudo apt install gcc libc6-dev sudo apt install libx11-dev xorg-dev libxtst-dev libpng++-dev -sudo apt install xcb libxcb-xkb-dev x11-xkb-utils libx11-xcb-dev libxkbcommon-x11-dev -sudo apt install libxkbcommon-dev +sudo apt install xcb libxcb-xkb-dev x11-xkb-utils libx11-xcb-dev libxkbcommon-x11-dev libxkbcommon-dev sudo apt install xsel xclip @@ -127,10 +130,12 @@ import ( ) func main() { - robotgo.ScrollMouse(10, "up") - robotgo.Scroll(100, 200) + // robotgo.ScrollMouse(10, "up") + robotgo.Scroll(0, -10) + robotgo.Scroll(100, 0) robotgo.MilliSleep(100) - robotgo.ScrollRelative(10, -100) + // robotgo.ScrollRelative(10, -100) + robogo.ScrollSmooth(-10, 6) robotgo.MouseSleep = 100 robotgo.Move(10, 20) @@ -138,8 +143,10 @@ func main() { robotgo.Drag(10, 10) robotgo.Click("left", true) - robotgo.MoveSmooth(100, 200, 1.0, 100.0) - robotgo.MouseToggle("up") + robotgo.MoveSmooth(100, 200, 1.0, 10.0) + + robogo.Toggle("left") + robotgo.Toggle("left", "up") } ``` @@ -174,7 +181,8 @@ func main() { robotgo.KeyTap("i", arr) robotgo.MilliSleep(100) - robotgo.KeyToggle("a", "down") + robotgo.KeyToggle("a") + robotgo.KeyToggle("a", "up") robotgo.WriteAll("テストする") text, err := robotgo.ReadAll() From 4302f69b95cd852a3a7273ba4d2718ceb746c5db Mon Sep 17 00:00:00 2001 From: vcaesar Date: Wed, 17 Nov 2021 14:52:05 -0400 Subject: [PATCH 2/4] Update README.md --- README.md | 17 +++++++++++------ README_zh.md | 13 ++++++++----- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 36eea26..27c4225 100644 --- a/README.md +++ b/README.md @@ -37,8 +37,8 @@ RobotGo supports Mac, Windows, and Linux(X11); and robotgo supports arm64 and x8 ## Docs - [GoDoc](https://godoc.org/github.com/go-vgo/robotgo)
- - - [API Docs](https://github.com/go-vgo/robotgo/blob/master/docs/doc.md)     (Deprecated, no updated) + + - [API Docs](https://github.com/go-vgo/robotgo/blob/master/docs/doc.md) (Deprecated, no updated) - [Chinese Docs](https://github.com/go-vgo/robotgo/blob/master/docs/doc_zh.md) (Deprecated, no updated) ## Binding: @@ -59,7 +59,7 @@ GCC #### For Mac OS X: -Xcode Command Line Tools (And Privacy setting: #277 ) +Xcode Command Line Tools (And Privacy setting: [#277](#277) ) ``` xcode-select --install @@ -67,8 +67,13 @@ xcode-select --install #### For Windows: -[MinGW-w64](https://sourceforge.net/projects/mingw-w64/files) (Use recommended) or other GCC +[MinGW-w64](https://sourceforge.net/projects/mingw-w64/files) (Use recommended) +``` +Or the other GCC (But you should compile the "libpng" with yourself. Or you can removed the bitmap.go. + +In the plans, the bitmap.go will moves to the bitmap dir, but break the API. ) +``` #### For everything else: @@ -147,7 +152,7 @@ func main() { robotgo.MoveRelative(0, -10) robotgo.Drag(10, 10) - robogo.Click("wheelRight") + robotgo.Click("wheelRight") robotgo.Click("left", true) robotgo.MoveSmooth(100, 200, 1.0, 10.0) @@ -187,7 +192,7 @@ func main() { robotgo.KeyTap("i", arr) robotgo.MilliSleep(100) - robogo.KeyToggle("a") + robotgo.KeyToggle("a") robotgo.KeyToggle("a", "up") robotgo.WriteAll("Test") diff --git a/README_zh.md b/README_zh.md index 8e013ff..23a143a 100644 --- a/README_zh.md +++ b/README_zh.md @@ -34,7 +34,7 @@ RobotGo 支持 Mac, Windows, and Linux(X11). ## Docs - [GoDoc](https://godoc.org/github.com/go-vgo/robotgo)
-- [中文文档](https://github.com/go-vgo/robotgo/blob/master/docs/doc_zh.md)    (弃用) +- [中文文档](https://github.com/go-vgo/robotgo/blob/master/docs/doc_zh.md) (弃用) - [English Docs](https://github.com/go-vgo/robotgo/blob/master/docs/doc.md) (弃用) ## Binding: @@ -55,7 +55,7 @@ GCC #### For Mac OS X: -Xcode Command Line Tools (And Privacy setting: #277 ) +Xcode Command Line Tools (And Privacy setting: [#277](#277) ) ``` xcode-select --install @@ -63,8 +63,11 @@ xcode-select --install #### For Windows: -[MinGW-w64](https://sourceforge.net/projects/mingw-w64/files) (推荐使用) or other GCC +[MinGW-w64](https://sourceforge.net/projects/mingw-w64/files) (推荐使用) +``` +Or the other GCC (But you should compile the "libpng" with yourself. Or you can removed the bitmap.go ) +``` #### For everything else (Linux 等其他系统): @@ -135,7 +138,7 @@ func main() { robotgo.Scroll(100, 0) robotgo.MilliSleep(100) // robotgo.ScrollRelative(10, -100) - robogo.ScrollSmooth(-10, 6) + robotgo.ScrollSmooth(-10, 6) robotgo.MouseSleep = 100 robotgo.Move(10, 20) @@ -145,7 +148,7 @@ func main() { robotgo.Click("left", true) robotgo.MoveSmooth(100, 200, 1.0, 10.0) - robogo.Toggle("left") + robotgo.Toggle("left") robotgo.Toggle("left", "up") } ``` From a6f18bc2b3420de5e2a508bb1c019661541b7dcc Mon Sep 17 00:00:00 2001 From: vcaesar Date: Wed, 17 Nov 2021 17:08:59 -0400 Subject: [PATCH 3/4] Update godoc and README.md --- README.md | 6 +++--- README_zh.md | 6 +++--- clipboard/clipboard_test.go | 3 +++ robotgo_mac_win.go | 4 ++++ 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 27c4225..bf74a8b 100644 --- a/README.md +++ b/README.md @@ -59,7 +59,7 @@ GCC #### For Mac OS X: -Xcode Command Line Tools (And Privacy setting: [#277](#277) ) +Xcode Command Line Tools (And Privacy setting: [#277](https://github.com/go-vgo/robotgo/issues/277) ) ``` xcode-select --install @@ -70,7 +70,8 @@ xcode-select --install [MinGW-w64](https://sourceforge.net/projects/mingw-w64/files) (Use recommended) ``` -Or the other GCC (But you should compile the "libpng" with yourself. Or you can removed the bitmap.go. +Or the other GCC (But you should compile the "libpng" with yourself. +Or you can removed the bitmap.go. In the plans, the bitmap.go will moves to the bitmap dir, but break the API. ) ``` @@ -114,7 +115,6 @@ sudo dnf install xsel xclip ``` go get github.com/go-vgo/robotgo ``` - It's that easy! png.h: No such file or directory? Please see [issues/47](https://github.com/go-vgo/robotgo/issues/47). diff --git a/README_zh.md b/README_zh.md index 23a143a..350248b 100644 --- a/README_zh.md +++ b/README_zh.md @@ -55,7 +55,7 @@ GCC #### For Mac OS X: -Xcode Command Line Tools (And Privacy setting: [#277](#277) ) +Xcode Command Line Tools (And Privacy setting: [#277](https://github.com/go-vgo/robotgo/issues/277) ) ``` xcode-select --install @@ -66,7 +66,8 @@ xcode-select --install [MinGW-w64](https://sourceforge.net/projects/mingw-w64/files) (推荐使用) ``` -Or the other GCC (But you should compile the "libpng" with yourself. Or you can removed the bitmap.go ) +Or the other GCC (But you should compile the "libpng" with yourself. +Or you can removed the bitmap.go ) ``` #### For everything else (Linux 等其他系统): @@ -108,7 +109,6 @@ sudo dnf install xsel xclip ``` go get github.com/go-vgo/robotgo ``` - It's that easy! png.h: No such file or directory? Please see [issues/47](https://github.com/go-vgo/robotgo/issues/47). diff --git a/clipboard/clipboard_test.go b/clipboard/clipboard_test.go index 993d343..43f05ad 100644 --- a/clipboard/clipboard_test.go +++ b/clipboard/clipboard_test.go @@ -2,6 +2,9 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +//go:build darwin || windows +// +build darwin windows + package clipboard_test import ( diff --git a/robotgo_mac_win.go b/robotgo_mac_win.go index de6d21a..b0486c9 100644 --- a/robotgo_mac_win.go +++ b/robotgo_mac_win.go @@ -37,6 +37,10 @@ func internalGetTitle(pid int32, args ...int32) string { // ActivePID active the window by PID, // // If args[0] > 0 on the Windows platform via a window handle to active +// +// Examples: +// ids, _ := robotgo.FindIds() +// robotgo.ActivePID(ids[0]) func ActivePID(pid int32, args ...int) error { var hwnd int if len(args) > 0 { From b25cecf984251d9cbe087a6b7b70655632aa7377 Mon Sep 17 00:00:00 2001 From: vcaesar Date: Wed, 17 Nov 2021 17:29:31 -0400 Subject: [PATCH 4/4] remove move scaled and drop some API keep one, add toggle micro sleep --- base/microsleep.h | 3 +-- key/keypress_c.h | 5 +++++ mouse/mouse_c.h | 3 ++- robotgo.go | 23 +++++++++++++++-------- 4 files changed, 23 insertions(+), 11 deletions(-) diff --git a/base/microsleep.h b/base/microsleep.h index bbb8a4f..777831c 100644 --- a/base/microsleep.h +++ b/base/microsleep.h @@ -20,8 +20,7 @@ * * Pauses execution for the given amount of milliseconds. */ -H_INLINE void microsleep(double milliseconds) -{ +H_INLINE void microsleep(double milliseconds) { #if defined(IS_WINDOWS) Sleep((DWORD)milliseconds); /* (Unfortunately truncated to a 32-bit integer.) */ #else diff --git a/key/keypress_c.h b/key/keypress_c.h index da63ae4..8fd0502 100644 --- a/key/keypress_c.h +++ b/key/keypress_c.h @@ -173,6 +173,7 @@ void toggleKeyCode(MMKeyCode code, const bool down, MMKeyFlags flags){ void tapKeyCode(MMKeyCode code, MMKeyFlags flags){ toggleKeyCode(code, true, flags); + microsleep(5.0); toggleKeyCode(code, false, flags); } @@ -224,6 +225,7 @@ void toggleKey(char c, const bool down, MMKeyFlags flags){ void tapKey(char c, MMKeyFlags flags){ toggleKey(c, true, flags); + microsleep(5.0); toggleKey(c, false, flags); } @@ -289,6 +291,7 @@ void unicodeType(const unsigned value){ UniChar ch = (UniChar)value; // Convert to unsigned char toggleUnicode(ch, true); + microsleep(5.0); toggleUnicode(ch, false); #elif defined(IS_WINDOWS) INPUT input[2]; @@ -307,10 +310,12 @@ void unicodeType(const unsigned value){ SendInput(2, input, sizeof(INPUT)); #elif defined(USE_X11) toggleUniKey(value, true); + microsleep(5.0); toggleUniKey(value, false); #endif } +// todo: removed void typeStringDelayed(const char *str, const unsigned cpm){ /* Characters per second */ diff --git a/mouse/mouse_c.h b/mouse/mouse_c.h index 245f618..1b72e74 100644 --- a/mouse/mouse_c.h +++ b/mouse/mouse_c.h @@ -206,6 +206,7 @@ void toggleMouse(bool down, MMMouseButton button){ void clickMouse(MMMouseButton button){ toggleMouse(true, button); + microsleep(5.0); toggleMouse(false, button); } @@ -309,7 +310,7 @@ void scrollMouse(int scrollMagnitude, MMMouseWheelDirection scrollDirection){ #endif } -void scrollMouseXY(int x, int y){ +void scrollMouseXY(int x, int y) { #if defined(IS_WINDOWS) // Fix for #97, // C89 needs variables declared on top of functions (mouseScrollInput) diff --git a/robotgo.go b/robotgo.go index eff9581..7d319e8 100644 --- a/robotgo.go +++ b/robotgo.go @@ -441,6 +441,7 @@ func CheckMouse(btn string) C.MMMouseButton { return C.LEFT_BUTTON } +// Deprecated: // MoveMouse move the mouse func MoveMouse(x, y int) { Move(x, y) @@ -452,10 +453,10 @@ func MoveMouse(x, y int) { // robotgo.MouseSleep = 100 // 100 millisecond // robotgo.Move(10, 10) func Move(x, y int) { - if runtime.GOOS == "windows" { - f := ScaleF() - x, y = Scaled0(x, f), Scaled0(y, f) - } + // if runtime.GOOS == "windows" { + // f := ScaleF() + // x, y = Scaled0(x, f), Scaled0(y, f) + // } cx := C.int32_t(x) cy := C.int32_t(y) @@ -464,6 +465,7 @@ func Move(x, y int) { MilliSleep(MouseSleep) } +// Deprecated: // DragMouse drag the mouse to (x, y), // It's same with the DragSmooth() now func DragMouse(x, y int, args ...interface{}) { @@ -474,6 +476,7 @@ func DragMouse(x, y int, args ...interface{}) { Toggle("left", "up") } +// Deprecated: // Drag drag the mouse to (x, y), // It's not valid now, use the DragSmooth() func Drag(x, y int, args ...string) { @@ -500,6 +503,7 @@ func DragSmooth(x, y int, args ...interface{}) { Toggle("left", "up") } +// Deprecated: // MoveMouseSmooth move the mouse smooth, // moves mouse to x, y human like, with the mouse button up. func MoveMouseSmooth(x, y int, args ...interface{}) bool { @@ -515,10 +519,10 @@ func MoveMouseSmooth(x, y int, args ...interface{}) bool { // robotgo.MoveSmooth(10, 10) // robotgo.MoveSmooth(10, 10, 1.0, 2.0) func MoveSmooth(x, y int, args ...interface{}) bool { - if runtime.GOOS == "windows" { - f := ScaleF() - x, y = Scaled0(x, f), Scaled0(y, f) - } + // if runtime.GOOS == "windows" { + // f := ScaleF() + // x, y = Scaled0(x, f), Scaled0(y, f) + // } cx := C.int32_t(x) cy := C.int32_t(y) @@ -577,6 +581,7 @@ func GetMousePos() (int, int) { return x, y } +// Deprecated: // MouseClick click the mouse // // robotgo.MouseClick(button string, double bool) @@ -646,6 +651,7 @@ func Toggle(key ...string) int { return int(i) } +// Deprecated: // MouseToggle toggle the mouse // // Examples: @@ -666,6 +672,7 @@ func MouseToggle(togKey string, args ...interface{}) int { return int(i) } +// Deprecated: // ScrollMouse scroll the mouse to (x, "up") // // Examples: