From 4bf054f47a4e732f8510c80b69bc8129e5dd399d Mon Sep 17 00:00:00 2001 From: vcaesar Date: Tue, 1 Nov 2022 10:28:00 -0700 Subject: [PATCH] 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)