From 47ca6812fe19e337282bfee60c10a59eb2c7e261 Mon Sep 17 00:00:00 2001 From: vcaesar Date: Mon, 12 Sep 2022 15:20:48 -0700 Subject: [PATCH 1/4] Update README.md --- README.md | 8 ++++---- README_zh.md | 4 +++- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 2f11fc9..b09f518 100644 --- a/README.md +++ b/README.md @@ -163,8 +163,8 @@ import ( func main() { robotgo.MouseSleep = 100 - robotgo.ScrollMouse(10, "up") - robotgo.ScrollMouse(20, "right") + robotgo.ScrollDir(10, "up") + robotgo.ScrollDir(20, "right") robotgo.Scroll(0, -10) robotgo.Scroll(100, 0) @@ -242,7 +242,7 @@ import ( ) func main() { - x, y := robotgo.GetMousePos() + x, y := robotgo.Location() fmt.Println("pos: ", x, y) color := robotgo.GetPixelColor(100, 200) @@ -455,7 +455,7 @@ func main() { robotgo.KeyToggle("a", fpid[0]) robotgo.KeyToggle("a", fpid[0], "up") - robotgo.ActivePID(fpid[0]) + robotgo.ActivePid(fpid[0]) robotgo.Kill(fpid[0]) } diff --git a/README_zh.md b/README_zh.md index 7bac20c..c6f84d9 100644 --- a/README_zh.md +++ b/README_zh.md @@ -1,5 +1,7 @@ # Robotgo +## !!! Warning: this page not updated !!! + [![Build Status](https://github.com/go-vgo/robotgo/workflows/Go/badge.svg)](https://github.com/go-vgo/robotgo/commits/master) [![CircleCI Status](https://circleci.com/gh/go-vgo/robotgo.svg?style=shield)](https://circleci.com/gh/go-vgo/robotgo) [![Build Status](https://travis-ci.org/go-vgo/robotgo.svg)](https://travis-ci.org/go-vgo/robotgo) @@ -67,7 +69,7 @@ xcode-select --install ``` Or the other GCC (But you should compile the "libpng" with yourself. -Or you can removed the bitmap.go ) +Or you can removed the bitmap.go.) ``` #### For everything else (Linux 等其他系统): From e9b5a9251e1689ec54241d569ff5fa2d4a8b650a Mon Sep 17 00:00:00 2001 From: vcaesar Date: Tue, 13 Sep 2022 15:49:21 -0700 Subject: [PATCH 2/4] Update: Unified pid and xid name, Update godoc, fixed typo --- README.md | 2 +- base/pubs.h | 4 ++-- examples/window/main.go | 6 +++--- mouse/mouse_c.h | 2 +- robotgo.go | 47 +++++++++++++++++++++++++++-------------- robotgo_mac.go | 2 +- robotgo_mac_win.go | 8 ++++--- robotgo_win.go | 2 +- robotgo_x11.go | 23 ++++++++++---------- screen/goScreen.h | 2 +- window/goWindow.h | 4 ++-- window/win_sys.h | 4 ++-- window/window.h | 2 +- 13 files changed, 63 insertions(+), 45 deletions(-) diff --git a/README.md b/README.md index b09f518..a375d6f 100644 --- a/README.md +++ b/README.md @@ -53,7 +53,7 @@ Golang GCC ``` -#### For Mac OS X: +#### For MacOS: Xcode Command Line Tools (And Privacy setting: [#277](https://github.com/go-vgo/robotgo/issues/277) ) diff --git a/base/pubs.h b/base/pubs.h index 6dfecc7..1ad716b 100644 --- a/base/pubs.h +++ b/base/pubs.h @@ -22,12 +22,12 @@ return TRUE; } - HWND GetHwndByPId(DWORD dwProcessId) { + HWND GetHwndByPid(DWORD dwProcessId) { WNDINFO info = {0}; info.hWnd = NULL; info.dwPid = dwProcessId; EnumWindows(EnumWindowsProc, (LPARAM)&info); - // printf("%d\n", info.hWnd); + return info.hWnd; } #endif \ No newline at end of file diff --git a/examples/window/main.go b/examples/window/main.go index ffa5c87..7e39b5b 100644 --- a/examples/window/main.go +++ b/examples/window/main.go @@ -28,7 +28,7 @@ func alert() { func get() { // get the current process id - pid := robotgo.GetPID() + pid := robotgo.GetPid() fmt.Println("pid----", pid) // get current Window Active @@ -64,7 +64,7 @@ func findIds() { fmt.Println("pids...", fpid) if len(fpid) > 0 { - err = robotgo.ActivePID(fpid[0]) + err = robotgo.ActivePid(fpid[0]) if err != nil { fmt.Println(err) } @@ -87,7 +87,7 @@ func findIds() { } func active() { - robotgo.ActivePID(100) + robotgo.ActivePid(100) // robotgo.Sleep(2) robotgo.ActiveName("code") robotgo.Sleep(1) diff --git a/mouse/mouse_c.h b/mouse/mouse_c.h index 6e08d9a..a53bdf5 100644 --- a/mouse/mouse_c.h +++ b/mouse/mouse_c.h @@ -192,7 +192,7 @@ void clickMouse(MMMouseButton button){ toggleMouse(false, button); } -/* Special function for sending double clicks, needed for Mac OS X. */ +/* Special function for sending double clicks, needed for MacOS. */ void doubleClick(MMMouseButton button){ #if defined(IS_MACOSX) /* Double click for Mac. */ diff --git a/robotgo.go b/robotgo.go index 420c22c..e9d6efd 100644 --- a/robotgo.go +++ b/robotgo.go @@ -9,20 +9,22 @@ // except according to those terms. /* - Package robotgo Go native cross-platform system automation. Please make sure Golang, GCC is installed correctly before installing RobotGo; See Requirements: + https://github.com/go-vgo/robotgo#requirements Installation: With Go module support (Go 1.11+), just import: + import "github.com/go-vgo/robotgo" Otherwise, to install the robotgo package, run the command: + go get -u github.com/go-vgo/robotgo */ package robotgo @@ -236,8 +238,8 @@ func getNumDisplays() int { return int(C.get_num_displays()) } -// GetHwndByPId get the hwnd by pid -func GetHwndByPId(pid int) int { +// GetHWNDByPid get the hwnd by pid +func GetHWNDByPid(pid int) int { return int(C.get_hwnd_by_pid(C.uintptr(pid))) } @@ -513,8 +515,9 @@ func MoveMouse(x, y int) { // Move move the mouse to (x, y) // // Examples: -// robotgo.MouseSleep = 100 // 100 millisecond -// robotgo.Move(10, 10) +// +// robotgo.MouseSleep = 100 // 100 millisecond +// robotgo.Move(10, 10) func Move(x, y int) { // if runtime.GOOS == "windows" { // f := ScaleF() @@ -560,6 +563,7 @@ func Drag(x, y int, args ...string) { // DragSmooth drag the mouse like smooth to (x, y) // // Examples: +// // robotgo.DragSmooth(10, 10) func DragSmooth(x, y int, args ...interface{}) { Toggle("left") @@ -582,6 +586,7 @@ func MoveMouseSmooth(x, y int, args ...interface{}) bool { // robotgo.MoveSmooth(x, y int, low, high float64, mouseDelay int) // // Examples: +// // robotgo.MoveSmooth(10, 10) // robotgo.MoveSmooth(10, 10, 1.0, 2.0) func MoveSmooth(x, y int, args ...interface{}) bool { @@ -648,7 +653,7 @@ func GetMousePos() (int, int) { // Deprecated: use the Click(), // -// MouseClick click the mouse +// # MouseClick click the mouse // // robotgo.MouseClick(button string, double bool) func MouseClick(args ...interface{}) { @@ -660,7 +665,8 @@ func MouseClick(args ...interface{}) { // robotgo.Click(button string, double bool) // // Examples: -// robotgo.Click() // default is left button +// +// robotgo.Click() // default is left button // robotgo.Click("right") // robotgo.Click("wheelLeft") func Click(args ...interface{}) { @@ -691,6 +697,7 @@ func Click(args ...interface{}) { // robotgo.MoveClick(x, y int, button string, double bool) // // Examples: +// // robotgo.MouseSleep = 100 // robotgo.MoveClick(10, 10) func MoveClick(x, y int, args ...interface{}) { @@ -709,10 +716,12 @@ func MovesClick(x, y int, args ...interface{}) { } // Toggle toggle the mouse, support button: -// "left", "center", "right", -// "wheelDown", "wheelUp", "wheelLeft", "wheelRight" +// +// "left", "center", "right", +// "wheelDown", "wheelUp", "wheelLeft", "wheelRight" // // Examples: +// // robotgo.Toggle("left") // default is down // robotgo.Toggle("left", "up") func Toggle(key ...string) error { @@ -749,6 +758,7 @@ func MouseUp(key ...string) error { // robotgo.Scroll(x, y, msDelay int) // // Examples: +// // robotgo.Scroll(10, 10) func Scroll(x, y int, args ...int) { var msDelay = 10 @@ -767,6 +777,7 @@ func Scroll(x, y int, args ...int) { // supported: "up", "down", "left", "right" // // Examples: +// // robotgo.ScrollMouse(10, "down") // robotgo.ScrollMouse(10, "up") func ScrollMouse(x int, direction ...string) { @@ -797,6 +808,7 @@ func ScrollMouse(x int, direction ...string) { // robotgo.ScrollSmooth(toy, num, sleep, tox) // // Examples: +// // robotgo.ScrollSmooth(-10) // robotgo.ScrollSmooth(-10, 6, 200, -10) func ScrollSmooth(to int, args ...int) { @@ -828,6 +840,7 @@ func ScrollSmooth(to int, args ...int) { // ScrollRelative scroll mouse with relative // // Examples: +// // robotgo.ScrollRelative(10, 10) func ScrollRelative(x, y int, args ...int) { mx, my := MoveArgs(x, y) @@ -987,7 +1000,7 @@ func GetHandle() int { // Deprecated: use the GetHandle(), // -// GetBHandle get the window handle, Wno-deprecated +// # GetBHandle get the window handle, Wno-deprecated // // This function will be removed in version v1.0.0 func GetBHandle() int { @@ -1008,6 +1021,7 @@ func cgetTitle(hwnd, isHwnd int32) string { // GetTitle get the window title return string // // Examples: +// // fmt.Println(robotgo.GetTitle()) // // ids, _ := robotgo.FindIds() @@ -1026,8 +1040,8 @@ func GetTitle(args ...int32) string { return internalGetTitle(args[0]) } -// GetPID get the process id return int32 -func GetPID() int32 { +// GetPid get the process id return int32 +func GetPid() int32 { pid := C.get_PID() return int32(pid) } @@ -1054,9 +1068,9 @@ func internalActive(pid int32, hwnd int) { C.active_PID(C.uintptr(pid), C.uintptr(hwnd)) } -// 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 -// func ActivePID(pid int32, args ...int) { +// func ActivePid(pid int32, args ...int) { // var hwnd int // if len(args) > 0 { // hwnd = args[0] @@ -1068,11 +1082,12 @@ func internalActive(pid int32, hwnd int) { // ActiveName active the window by name // // Examples: -// robotgo.ActiveName("chrome") +// +// robotgo.ActiveName("chrome") func ActiveName(name string) error { pids, err := FindIds(name) if err == nil && len(pids) > 0 { - return ActivePID(pids[0]) + return ActivePid(pids[0]) } return err diff --git a/robotgo_mac.go b/robotgo_mac.go index 0f9ce4a..0d8ac31 100644 --- a/robotgo_mac.go +++ b/robotgo_mac.go @@ -18,7 +18,7 @@ package robotgo */ import "C" -// GetMianId get the main display id +// GetMainId get the main display id func GetMainId() int { return int(C.CGMainDisplayID()) } diff --git a/robotgo_mac_win.go b/robotgo_mac_win.go index 88c1bb9..798ea06 100644 --- a/robotgo_mac_win.go +++ b/robotgo_mac_win.go @@ -44,14 +44,15 @@ func internalGetTitle(pid int32, args ...int32) string { return gtitle } -// 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 // // Examples: +// // ids, _ := robotgo.FindIds() -// robotgo.ActivePID(ids[0]) -func ActivePID(pid int32, args ...int) error { +// robotgo.ActivePid(ids[0]) +func ActivePid(pid int32, args ...int) error { var hwnd int if len(args) > 0 { hwnd = args[0] @@ -71,6 +72,7 @@ func DisplaysNum() int { // If cancel button is not given, only the default button is displayed // // Examples: +// // robotgo.Alert("hi", "window", "ok", "cancel") func Alert(title, msg string, args ...string) bool { return showAlert(title, msg, args...) diff --git a/robotgo_win.go b/robotgo_win.go index e8aced3..2d05078 100644 --- a/robotgo_win.go +++ b/robotgo_win.go @@ -57,7 +57,7 @@ func GetMain() win.HWND { return win.GetActiveWindow() } -// GetMianId get the main display id +// GetMainId get the main display id func GetMainId() int { return int(GetMain()) } diff --git a/robotgo_x11.go b/robotgo_x11.go index cc4dbc5..c6445f8 100644 --- a/robotgo_x11.go +++ b/robotgo_x11.go @@ -34,7 +34,7 @@ func GetBounds(pid int32, args ...int) (int, int, int, int) { return internalGetBounds(pid, hwnd) } - xid, err := GetXId(xu, pid) + xid, err := GetXid(xu, pid) if err != nil { log.Println("Get Xid from Pid errors is: ", err) return 0, 0, 0, 0 @@ -51,7 +51,7 @@ func GetClient(pid int32, args ...int) (int, int, int, int) { return internalGetClient(pid, hwnd) } - xid, err := GetXId(xu, pid) + xid, err := GetXid(xu, pid) if err != nil { log.Println("Get Xid from Pid errors is: ", err) return 0, 0, 0, 0 @@ -68,7 +68,7 @@ func internalGetTitle(pid int32, args ...int32) string { return cgetTitle(pid, hwnd) } - xid, err := GetXId(xu, pid) + xid, err := GetXid(xu, pid) if err != nil { log.Println("Get Xid from Pid errors is: ", err) return "" @@ -77,9 +77,9 @@ func internalGetTitle(pid int32, args ...int32) string { return cgetTitle(int32(xid), hwnd) } -// ActivePIDC active the window by PID, +// ActivePidC active the window by Pid, // If args[0] > 0 on the unix platform via a xid to active -func ActivePIDC(pid int32, args ...int) error { +func ActivePidC(pid int32, args ...int) error { var hwnd int if len(args) > 0 { hwnd = args[0] @@ -87,7 +87,7 @@ func ActivePIDC(pid int32, args ...int) error { return nil } - xid, err := GetXId(xu, pid) + xid, err := GetXid(xu, pid) if err != nil { log.Println("Get Xid from Pid errors is: ", err) return err @@ -97,11 +97,11 @@ func ActivePIDC(pid int32, args ...int) error { return nil } -// 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 unix platform via a xid to active -func ActivePID(pid int32, args ...int) error { +func ActivePid(pid int32, args ...int) error { if xu == nil { var err error xu, err = xgbutil.NewConn() @@ -133,8 +133,8 @@ func ActivePID(pid int32, args ...int) error { return nil } -// GetXId get the xid return window and error -func GetXId(xu *xgbutil.XUtil, pid int32) (xproto.Window, error) { +// GetXid get the xid return window and error +func GetXid(xu *xgbutil.XUtil, pid int32) (xproto.Window, error) { if xu == nil { var err error xu, err = xgbutil.NewConn() @@ -148,7 +148,7 @@ func GetXId(xu *xgbutil.XUtil, pid int32) (xproto.Window, error) { return xid, err } -// GetXidFromPid get the xide from pid +// GetXidFromPid get the xid from pid func GetXidFromPid(xu *xgbutil.XUtil, pid int32) (xproto.Window, error) { windows, err := ewmh.ClientListGet(xu) if err != nil { @@ -214,6 +214,7 @@ func GetMainId() int { // If cancel button is not given, only the default button is displayed // // Examples: +// // robotgo.Alert("hi", "window", "ok", "cancel") func Alert(title, msg string, args ...string) bool { defaultBtn, cancelBtn := alertArgs(args...) diff --git a/screen/goScreen.h b/screen/goScreen.h index b9c0a16..e990d3e 100644 --- a/screen/goScreen.h +++ b/screen/goScreen.h @@ -99,7 +99,7 @@ uint32_t get_num_displays() { uintptr get_hwnd_by_pid(uintptr pid) { #if defined(IS_WINDOWS) - HWND hwnd = GetHwndByPId(pid); + HWND hwnd = GetHwndByPid(pid); return (uintptr)hwnd; #else return 0; diff --git a/window/goWindow.h b/window/goWindow.h index 7ab510e..e73300b 100644 --- a/window/goWindow.h +++ b/window/goWindow.h @@ -24,7 +24,7 @@ void min_window(uintptr pid, bool state, uintptr isHwnd){ // SetState((Window)pid, STATE_MINIMIZE, state); #elif defined(IS_WINDOWS) if (isHwnd == 0) { - HWND hwnd = GetHwndByPId(pid); + HWND hwnd = GetHwndByPid(pid); win_min(hwnd, state); } else { win_min((HWND)pid, state); @@ -41,7 +41,7 @@ void max_window(uintptr pid, bool state, uintptr isHwnd){ // SetState((Window)pid, STATE_MAXIMIZE, state); #elif defined(IS_WINDOWS) if (isHwnd == 0) { - HWND hwnd = GetHwndByPId(pid); + HWND hwnd = GetHwndByPid(pid); win_max(hwnd, state); } else { win_max((HWND)pid, state); diff --git a/window/win_sys.h b/window/win_sys.h index 9a80060..89e643d 100644 --- a/window/win_sys.h +++ b/window/win_sys.h @@ -130,7 +130,7 @@ Bounds get_bounds(uintptr pid, uintptr isHwnd){ #elif defined(IS_WINDOWS) HWND hwnd; if (isHwnd == 0) { - hwnd= GetHwndByPId(pid); + hwnd= GetHwndByPid(pid); } else { hwnd = (HWND)pid; } @@ -195,7 +195,7 @@ Bounds get_client(uintptr pid, uintptr isHwnd) { #elif defined(IS_WINDOWS) HWND hwnd; if (isHwnd == 0) { - hwnd = GetHwndByPId(pid); + hwnd = GetHwndByPid(pid); } else { hwnd = (HWND)pid; } diff --git a/window/window.h b/window/window.h index f25c60c..b4a861f 100644 --- a/window/window.h +++ b/window/window.h @@ -60,7 +60,7 @@ MData set_handle_pid(uintptr pid, uintptr isHwnd){ #elif defined(IS_WINDOWS) // win.HWnd = (HWND)pid; // Handle to a window HWND if (isHwnd == 0) { - win.HWnd = GetHwndByPId(pid); + win.HWnd = GetHwndByPid(pid); } else { win.HWnd = (HWND)pid; } From c3cda41c2d55f17ccfd3d6db0ac52f07e3d7b182 Mon Sep 17 00:00:00 2001 From: vcaesar Date: Wed, 14 Sep 2022 15:23:09 -0700 Subject: [PATCH 3/4] Update: update godoc and fixed typo --- README.md | 4 ++-- key.go | 28 +++++++++++++++------------- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index a375d6f..56e3618 100644 --- a/README.md +++ b/README.md @@ -519,9 +519,9 @@ Some discussions and questions, please see [issues/228](https://github.com/go-vg ## Plans - Refactor some C code to Go (such as x11, windows) - Better multiscreen support -- Waylad supports +- Wayland support - Update Window Handle -- Try support Android and IOS +- Try to support Android and IOS ## Contributors diff --git a/key.go b/key.go index 190270a..c2e05a7 100644 --- a/key.go +++ b/key.go @@ -201,7 +201,7 @@ const ( LightsKbdDown = "lights_kbd_down" ) -// keyNames define MMKeyCode map +// keyNames define a map of key names to MMKeyCode var keyNames = map[string]C.MMKeyCode{ "backspace": C.K_BACKSPACE, "delete": C.K_DELETE, @@ -441,7 +441,7 @@ func keyToggles(k string, keyArr []string, pid int) error { */ -// ToInterfaces []string to []interface{} +// ToInterfaces convert []string to []interface{} func ToInterfaces(fields []string) []interface{} { res := make([]interface{}, 0, len(fields)) for _, s := range fields { @@ -450,7 +450,7 @@ func ToInterfaces(fields []string) []interface{} { return res } -// ToStrings []interface{} to []string +// ToStrings convert []interface{} to []string func ToStrings(fields []interface{}) []string { res := make([]string, 0, len(fields)) for _, s := range fields { @@ -467,19 +467,20 @@ func toErr(str *C.char) error { return errors.New(gstr) } -// KeyTap tap the keyboard code; +// KeyTap taps the keyboard code; // // See keys: +// // https://github.com/go-vgo/robotgo/blob/master/docs/keys.md // // Examples: +// // robotgo.KeySleep = 100 // 100 millisecond // robotgo.KeyTap("a") // robotgo.KeyTap("i", "alt", "command") // // arr := []string{"alt", "command"} // robotgo.KeyTap("i", arr) -// func KeyTap(key string, args ...interface{}) error { var keyArr []string @@ -512,17 +513,18 @@ func KeyTap(key string, args ...interface{}) error { return keyTaps(key, keyArr, pid) } -// KeyToggle toggle the keyboard, if there not have args default is "down" +// KeyToggle toggles the keyboard, if there not have args default is "down" // // See keys: +// // https://github.com/go-vgo/robotgo/blob/master/docs/keys.md // // Examples: +// // robotgo.KeyToggle("a") // robotgo.KeyToggle("a", "up") // // robotgo.KeyToggle("a", "up", "alt", "cmd") -// func KeyToggle(key string, args ...interface{}) error { if len(key) > 0 && unicode.IsUpper([]rune(key)[0]) { @@ -633,13 +635,13 @@ func inputUTF(str string) { C.free(unsafe.Pointer(cstr)) } -// TypeStr send a string, supported UTF-8 +// TypeStr send a string (supported UTF-8) // // robotgo.TypeStr(string: "The string to send", int: pid, "milli_sleep time", "x11 option") // // Examples: -// robotgo.TypeStr("abc@123, Hi galaxy, こんにちは") // +// robotgo.TypeStr("abc@123, Hi galaxy, こんにちは") func TypeStr(str string, args ...int) { var tm, tm1 = 0, 7 @@ -681,7 +683,7 @@ func TypeStr(str string, args ...int) { MilliSleep(KeySleep) } -// PasteStr paste a string, support UTF-8, +// PasteStr paste a string (support UTF-8), // write the string to clipboard and tap `cmd + v` func PasteStr(str string) error { err := clipboard.WriteAll(str) @@ -696,7 +698,7 @@ func PasteStr(str string) error { return KeyTap("v", "control") } -// TypeStrDelay type string delayed +// TypeStrDelay type string with delayed func TypeStrDelay(str string, delay int) { TypeStr(str) MilliSleep(delay) @@ -704,7 +706,7 @@ func TypeStrDelay(str string, delay int) { // Deprecated: use the TypeStr(), // -// TypeStringDelayed type string delayed, Wno-deprecated +// # TypeStringDelayed type string delayed, Wno-deprecated // // This function will be removed in version v1.0.0 func TypeStringDelayed(str string, delay int) { @@ -712,7 +714,7 @@ func TypeStringDelayed(str string, delay int) { TypeStrDelay(str, delay) } -// SetDelay set the key and mouse delay +// SetDelay sets the key and mouse delay func SetDelay(d ...int) { v := 10 if len(d) > 0 { From 4bf054f47a4e732f8510c80b69bc8129e5dd399d Mon Sep 17 00:00:00 2001 From: vcaesar Date: Tue, 1 Nov 2022 10:28:00 -0700 Subject: [PATCH 4/4] Unifed and rename some function for Pad --- examples/mouse/main.go | 6 +++--- robot_info_test.go | 3 +++ robotgo.go | 19 +++++++++++++------ robotgo_test.go | 4 ++-- 4 files changed, 21 insertions(+), 11 deletions(-) diff --git a/examples/mouse/main.go b/examples/mouse/main.go index b49806c..d9ef7e3 100644 --- a/examples/mouse/main.go +++ b/examples/mouse/main.go @@ -55,7 +55,7 @@ func click() { func get() { // gets the mouse coordinates - x, y := robotgo.GetMousePos() + x, y := robotgo.Location() fmt.Println("pos:", x, y) if x == 456 && y == 586 { fmt.Println("mouse...", "586") @@ -66,8 +66,8 @@ func get() { func toggleAndScroll() { // scrolls the mouse either up - robotgo.ScrollMouse(10, "up") - robotgo.ScrollMouse(10, "right") + robotgo.ScrollDir(10, "up") + robotgo.ScrollDir(10, "right") robotgo.Scroll(100, 10) robotgo.Scroll(0, -10) diff --git a/robot_info_test.go b/robot_info_test.go index 0ce128d..81a244c 100644 --- a/robot_info_test.go +++ b/robot_info_test.go @@ -33,6 +33,9 @@ func TestGetScreenSize(t *testing.T) { rect := robotgo.GetScreenRect() fmt.Println("Get screen rect: ", rect) + + x, y = robotgo.Location() + fmt.Println("Get location: ", x, y) } func TestGetSysScale(t *testing.T) { diff --git a/robotgo.go b/robotgo.go index e9d6efd..91faeb9 100644 --- a/robotgo.go +++ b/robotgo.go @@ -624,7 +624,7 @@ func MoveSmooth(x, y int, args ...interface{}) bool { // MoveArgs get the mouse relative args func MoveArgs(x, y int) (int, int) { - mx, my := GetMousePos() + mx, my := Location() mx = mx + x my = my + y @@ -642,8 +642,15 @@ func MoveSmoothRelative(x, y int, args ...interface{}) { MoveSmooth(mx, my, args...) } +// Deprecated: use the function Location() +// // GetMousePos get the mouse's position return x, y func GetMousePos() (int, int) { + return Location() +} + +// Location get the mouse location position return x, y +func Location() (int, int) { pos := C.getMousePos() x := int(pos.x) y := int(pos.y) @@ -773,17 +780,17 @@ func Scroll(x, y int, args ...int) { MilliSleep(MouseSleep + msDelay) } -// ScrollMouse scroll the mouse to (x, "up") +// ScrollDir scroll the mouse with direction to (x, "up") // supported: "up", "down", "left", "right" // // Examples: // -// robotgo.ScrollMouse(10, "down") -// robotgo.ScrollMouse(10, "up") -func ScrollMouse(x int, direction ...string) { +// robotgo.ScrollDir(10, "down") +// robotgo.ScrollDir(10, "up") +func ScrollDir(x int, direction ...interface{}) { d := "down" if len(direction) > 0 { - d = direction[0] + d = direction[0].(string) } if d == "down" { diff --git a/robotgo_test.go b/robotgo_test.go index bf3d54b..c3aed91 100644 --- a/robotgo_test.go +++ b/robotgo_test.go @@ -68,8 +68,8 @@ func TestDragMouse(t *testing.T) { } func TestScrollMouse(t *testing.T) { - ScrollMouse(120, "up") - ScrollMouse(100, "right") + ScrollDir(120, "up") + ScrollDir(100, "right") Scroll(0, 120) MilliSleep(100)