Merge pull request #402 from go-vgo/bitmap-pr

remove move scaled and drop some API keep one, add toggle micro sleep
This commit is contained in:
Evans 2021-11-17 16:35:29 -05:00 committed by GitHub
commit bb3d3a536b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 85 additions and 39 deletions

View File

@ -36,9 +36,10 @@ RobotGo supports Mac, Windows, and Linux(X11); and robotgo supports arm64 and x8
- [License](#license) - [License](#license)
## Docs ## Docs
- [GoDoc](https://godoc.org/github.com/go-vgo/robotgo) - [GoDoc](https://godoc.org/github.com/go-vgo/robotgo) <br>
- [API Docs](https://github.com/go-vgo/robotgo/blob/master/docs/doc.md) &nbsp;&nbsp;&nbsp;
- [Chinese Docs](https://github.com/go-vgo/robotgo/blob/master/docs/doc_zh.md) - [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: ## Binding:
[ADB](https://github.com/vcaesar/adb), packaging android adb API. [ADB](https://github.com/vcaesar/adb), packaging android adb API.
@ -57,13 +58,22 @@ GCC
``` ```
#### For Mac OS X: #### For Mac OS X:
Xcode Command Line Tools (And Privacy setting: [#277](https://github.com/go-vgo/robotgo/issues/277) )
``` ```
Xcode Command Line Tools xcode-select --install
``` ```
#### For Windows: #### For Windows:
[MinGW-w64](https://sourceforge.net/projects/mingw-w64/files) (Use recommended)
``` ```
MinGW-w64 (Use recommended) or other GCC 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: #### For everything else:
@ -81,12 +91,12 @@ xcb, xkb, libxkbcommon
##### Ubuntu: ##### Ubuntu:
```yml ```yml
# gcc
sudo apt install gcc libc6-dev sudo apt install gcc libc6-dev
sudo apt install libx11-dev xorg-dev libxtst-dev libpng++-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 xcb libxcb-xkb-dev x11-xkb-utils libx11-xcb-dev libxkbcommon-x11-dev libxkbcommon-dev
sudo apt install libxkbcommon-dev
sudo apt install xsel xclip sudo apt install xsel xclip
``` ```
@ -105,7 +115,6 @@ sudo dnf install xsel xclip
``` ```
go get github.com/go-vgo/robotgo 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). png.h: No such file or directory? Please see [issues/47](https://github.com/go-vgo/robotgo/issues/47).
@ -130,19 +139,25 @@ import (
) )
func main() { func main() {
robotgo.ScrollMouse(10, "up") // robotgo.ScrollMouse(10, "up")
robotgo.Scroll(100, 200) robotgo.Scroll(0, -10)
robotgo.Scroll(100, 0)
robotgo.MilliSleep(100) robotgo.MilliSleep(100)
robotgo.ScrollRelative(10, -100) robotgo.ScrollSmooth(-10, 6)
// robotgo.ScrollRelative(10, -100)
robotgo.MouseSleep = 100 robotgo.MouseSleep = 100
robotgo.Move(10, 20) robotgo.Move(10, 20)
robotgo.MoveRelative(0, -10) robotgo.MoveRelative(0, -10)
robotgo.Drag(10, 10) robotgo.Drag(10, 10)
robotgo.Click("wheelRight")
robotgo.Click("left", true) robotgo.Click("left", true)
robotgo.MoveSmooth(100, 200, 1.0, 100.0) robotgo.MoveSmooth(100, 200, 1.0, 10.0)
robotgo.MouseToggle("up")
robotgo.Toggle("left")
robotgo.Toggle("left", "up")
} }
``` ```
@ -177,7 +192,8 @@ func main() {
robotgo.KeyTap("i", arr) robotgo.KeyTap("i", arr)
robotgo.MilliSleep(100) robotgo.MilliSleep(100)
robotgo.KeyToggle("a", "down") robotgo.KeyToggle("a")
robotgo.KeyToggle("a", "up")
robotgo.WriteAll("Test") robotgo.WriteAll("Test")
text, err := robotgo.ReadAll() text, err := robotgo.ReadAll()

View File

@ -32,9 +32,10 @@ RobotGo 支持 Mac, Windows, and Linux(X11).
- [License](#license) - [License](#license)
## Docs ## Docs
- [GoDoc](https://godoc.org/github.com/go-vgo/robotgo) - [GoDoc](https://godoc.org/github.com/go-vgo/robotgo) <br>
- [中文文档](https://github.com/go-vgo/robotgo/blob/master/docs/doc_zh.md)&nbsp;&nbsp;&nbsp;
- [English Docs](https://github.com/go-vgo/robotgo/blob/master/docs/doc.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: ## Binding:
@ -53,13 +54,20 @@ GCC
``` ```
#### For Mac OS X: #### For Mac OS X:
Xcode Command Line Tools (And Privacy setting: [#277](https://github.com/go-vgo/robotgo/issues/277) )
``` ```
Xcode Command Line Tools xcode-select --install
``` ```
#### For Windows: #### For Windows:
[MinGW-w64](https://sourceforge.net/projects/mingw-w64/files) (推荐使用)
``` ```
MinGW-w64 (推荐使用) or other GCC Or the other GCC (But you should compile the "libpng" with yourself.
Or you can removed the bitmap.go )
``` ```
#### For everything else (Linux 等其他系统): #### For everything else (Linux 等其他系统):
@ -81,8 +89,7 @@ sudo apt install gcc libc6-dev
sudo apt install libx11-dev xorg-dev libxtst-dev libpng++-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 xcb libxcb-xkb-dev x11-xkb-utils libx11-xcb-dev libxkbcommon-x11-dev libxkbcommon-dev
sudo apt install libxkbcommon-dev
sudo apt install xsel xclip sudo apt install xsel xclip
@ -102,7 +109,6 @@ sudo dnf install xsel xclip
``` ```
go get github.com/go-vgo/robotgo 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). png.h: No such file or directory? Please see [issues/47](https://github.com/go-vgo/robotgo/issues/47).
@ -127,10 +133,12 @@ import (
) )
func main() { func main() {
robotgo.ScrollMouse(10, "up") // robotgo.ScrollMouse(10, "up")
robotgo.Scroll(100, 200) robotgo.Scroll(0, -10)
robotgo.Scroll(100, 0)
robotgo.MilliSleep(100) robotgo.MilliSleep(100)
robotgo.ScrollRelative(10, -100) // robotgo.ScrollRelative(10, -100)
robotgo.ScrollSmooth(-10, 6)
robotgo.MouseSleep = 100 robotgo.MouseSleep = 100
robotgo.Move(10, 20) robotgo.Move(10, 20)
@ -138,8 +146,10 @@ func main() {
robotgo.Drag(10, 10) robotgo.Drag(10, 10)
robotgo.Click("left", true) robotgo.Click("left", true)
robotgo.MoveSmooth(100, 200, 1.0, 100.0) robotgo.MoveSmooth(100, 200, 1.0, 10.0)
robotgo.MouseToggle("up")
robotgo.Toggle("left")
robotgo.Toggle("left", "up")
} }
``` ```
@ -174,7 +184,8 @@ func main() {
robotgo.KeyTap("i", arr) robotgo.KeyTap("i", arr)
robotgo.MilliSleep(100) robotgo.MilliSleep(100)
robotgo.KeyToggle("a", "down") robotgo.KeyToggle("a")
robotgo.KeyToggle("a", "up")
robotgo.WriteAll("テストする") robotgo.WriteAll("テストする")
text, err := robotgo.ReadAll() text, err := robotgo.ReadAll()

View File

@ -20,8 +20,7 @@
* *
* Pauses execution for the given amount of milliseconds. * Pauses execution for the given amount of milliseconds.
*/ */
H_INLINE void microsleep(double milliseconds) H_INLINE void microsleep(double milliseconds) {
{
#if defined(IS_WINDOWS) #if defined(IS_WINDOWS)
Sleep((DWORD)milliseconds); /* (Unfortunately truncated to a 32-bit integer.) */ Sleep((DWORD)milliseconds); /* (Unfortunately truncated to a 32-bit integer.) */
#else #else

View File

@ -2,6 +2,9 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
//go:build darwin || windows
// +build darwin windows
package clipboard_test package clipboard_test
import ( import (

View File

@ -173,6 +173,7 @@ void toggleKeyCode(MMKeyCode code, const bool down, MMKeyFlags flags){
void tapKeyCode(MMKeyCode code, MMKeyFlags flags){ void tapKeyCode(MMKeyCode code, MMKeyFlags flags){
toggleKeyCode(code, true, flags); toggleKeyCode(code, true, flags);
microsleep(5.0);
toggleKeyCode(code, false, flags); toggleKeyCode(code, false, flags);
} }
@ -224,6 +225,7 @@ void toggleKey(char c, const bool down, MMKeyFlags flags){
void tapKey(char c, MMKeyFlags flags){ void tapKey(char c, MMKeyFlags flags){
toggleKey(c, true, flags); toggleKey(c, true, flags);
microsleep(5.0);
toggleKey(c, false, flags); toggleKey(c, false, flags);
} }
@ -289,6 +291,7 @@ void unicodeType(const unsigned value){
UniChar ch = (UniChar)value; // Convert to unsigned char UniChar ch = (UniChar)value; // Convert to unsigned char
toggleUnicode(ch, true); toggleUnicode(ch, true);
microsleep(5.0);
toggleUnicode(ch, false); toggleUnicode(ch, false);
#elif defined(IS_WINDOWS) #elif defined(IS_WINDOWS)
INPUT input[2]; INPUT input[2];
@ -307,10 +310,12 @@ void unicodeType(const unsigned value){
SendInput(2, input, sizeof(INPUT)); SendInput(2, input, sizeof(INPUT));
#elif defined(USE_X11) #elif defined(USE_X11)
toggleUniKey(value, true); toggleUniKey(value, true);
microsleep(5.0);
toggleUniKey(value, false); toggleUniKey(value, false);
#endif #endif
} }
// todo: removed
void typeStringDelayed(const char *str, const unsigned cpm){ void typeStringDelayed(const char *str, const unsigned cpm){
/* Characters per second */ /* Characters per second */

View File

@ -206,6 +206,7 @@ void toggleMouse(bool down, MMMouseButton button){
void clickMouse(MMMouseButton button){ void clickMouse(MMMouseButton button){
toggleMouse(true, button); toggleMouse(true, button);
microsleep(5.0);
toggleMouse(false, button); toggleMouse(false, button);
} }
@ -309,7 +310,7 @@ void scrollMouse(int scrollMagnitude, MMMouseWheelDirection scrollDirection){
#endif #endif
} }
void scrollMouseXY(int x, int y){ void scrollMouseXY(int x, int y) {
#if defined(IS_WINDOWS) #if defined(IS_WINDOWS)
// Fix for #97, // Fix for #97,
// C89 needs variables declared on top of functions (mouseScrollInput) // C89 needs variables declared on top of functions (mouseScrollInput)

View File

@ -441,6 +441,7 @@ func CheckMouse(btn string) C.MMMouseButton {
return C.LEFT_BUTTON return C.LEFT_BUTTON
} }
// Deprecated:
// MoveMouse move the mouse // MoveMouse move the mouse
func MoveMouse(x, y int) { func MoveMouse(x, y int) {
Move(x, y) Move(x, y)
@ -452,10 +453,10 @@ func MoveMouse(x, y int) {
// robotgo.MouseSleep = 100 // 100 millisecond // robotgo.MouseSleep = 100 // 100 millisecond
// robotgo.Move(10, 10) // robotgo.Move(10, 10)
func Move(x, y int) { func Move(x, y int) {
if runtime.GOOS == "windows" { // if runtime.GOOS == "windows" {
f := ScaleF() // f := ScaleF()
x, y = Scaled0(x, f), Scaled0(y, f) // x, y = Scaled0(x, f), Scaled0(y, f)
} // }
cx := C.int32_t(x) cx := C.int32_t(x)
cy := C.int32_t(y) cy := C.int32_t(y)
@ -464,6 +465,7 @@ func Move(x, y int) {
MilliSleep(MouseSleep) MilliSleep(MouseSleep)
} }
// Deprecated:
// DragMouse drag the mouse to (x, y), // DragMouse drag the mouse to (x, y),
// It's same with the DragSmooth() now // It's same with the DragSmooth() now
func DragMouse(x, y int, args ...interface{}) { func DragMouse(x, y int, args ...interface{}) {
@ -474,6 +476,7 @@ func DragMouse(x, y int, args ...interface{}) {
Toggle("left", "up") Toggle("left", "up")
} }
// Deprecated:
// Drag drag the mouse to (x, y), // Drag drag the mouse to (x, y),
// It's not valid now, use the DragSmooth() // It's not valid now, use the DragSmooth()
func Drag(x, y int, args ...string) { func Drag(x, y int, args ...string) {
@ -500,6 +503,7 @@ func DragSmooth(x, y int, args ...interface{}) {
Toggle("left", "up") Toggle("left", "up")
} }
// Deprecated:
// MoveMouseSmooth move the mouse smooth, // MoveMouseSmooth move the mouse smooth,
// moves mouse to x, y human like, with the mouse button up. // moves mouse to x, y human like, with the mouse button up.
func MoveMouseSmooth(x, y int, args ...interface{}) bool { 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)
// robotgo.MoveSmooth(10, 10, 1.0, 2.0) // robotgo.MoveSmooth(10, 10, 1.0, 2.0)
func MoveSmooth(x, y int, args ...interface{}) bool { func MoveSmooth(x, y int, args ...interface{}) bool {
if runtime.GOOS == "windows" { // if runtime.GOOS == "windows" {
f := ScaleF() // f := ScaleF()
x, y = Scaled0(x, f), Scaled0(y, f) // x, y = Scaled0(x, f), Scaled0(y, f)
} // }
cx := C.int32_t(x) cx := C.int32_t(x)
cy := C.int32_t(y) cy := C.int32_t(y)
@ -577,6 +581,7 @@ func GetMousePos() (int, int) {
return x, y return x, y
} }
// Deprecated:
// MouseClick click the mouse // MouseClick click the mouse
// //
// robotgo.MouseClick(button string, double bool) // robotgo.MouseClick(button string, double bool)
@ -646,6 +651,7 @@ func Toggle(key ...string) int {
return int(i) return int(i)
} }
// Deprecated:
// MouseToggle toggle the mouse // MouseToggle toggle the mouse
// //
// Examples: // Examples:
@ -666,6 +672,7 @@ func MouseToggle(togKey string, args ...interface{}) int {
return int(i) return int(i)
} }
// Deprecated:
// ScrollMouse scroll the mouse to (x, "up") // ScrollMouse scroll the mouse to (x, "up")
// //
// Examples: // Examples:

View File

@ -37,6 +37,10 @@ func internalGetTitle(pid int32, args ...int32) string {
// ActivePID active the window by PID, // ActivePID active the window by PID,
// //
// If args[0] > 0 on the Windows platform via a window handle to active // 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 { func ActivePID(pid int32, args ...int) error {
var hwnd int var hwnd int
if len(args) > 0 { if len(args) > 0 {