From d725cdc6f2fa5114ea88310d5ddf60c93bc0ef11 Mon Sep 17 00:00:00 2001 From: vcaesar Date: Thu, 25 Nov 2021 15:54:54 -0400 Subject: [PATCH 1/2] Add more and optimize test code, fixed typo --- docs/doc.md | 8 ++++---- docs/doc_zh.md | 8 ++++---- robot_info_test.go | 8 +++++++- robotgo_test.go | 30 +++++++++++++++++++----------- 4 files changed, 34 insertions(+), 20 deletions(-) diff --git a/docs/doc.md b/docs/doc.md index cca9369..1a5d3b1 100644 --- a/docs/doc.md +++ b/docs/doc.md @@ -213,8 +213,8 @@ robotgo.MoveMouseSmooth(100, 200, 1.0, 100.0) #### Examples: ```Go -robogo.MouseClick() -robogo.MouseClick("left", true) +robotgo.MouseClick() +robotgo.MouseClick("left", true) ``` ###

.MoveClick(x, y, button, double)

@@ -231,8 +231,8 @@ robogo.MouseClick("left", true) #### Examples: ```Go -robogo.MoveClick(10, 20) -robogo.MoveClick(10, 20, "left", true) +robotgo.MoveClick(10, 20) +robotgo.MoveClick(10, 20, "left", true) ``` ###

.MouseToggle(down, button)

diff --git a/docs/doc_zh.md b/docs/doc_zh.md index 1f7e439..a3dbebc 100644 --- a/docs/doc_zh.md +++ b/docs/doc_zh.md @@ -221,8 +221,8 @@ robotgo.MoveMouseSmooth(100, 200, 1.0, 100.0) #### 示例: ```Go -robogo.MouseClick() -robogo.MouseClick("left", true) +robotgo.MouseClick() +robotgo.MouseClick("left", true) ``` ###

.MoveClick(x, y, button, double)

@@ -239,8 +239,8 @@ robogo.MouseClick("left", true) #### 示例: ```Go -robogo.MoveClick(10, 20) -robogo.MoveClick(10, 20, "left", true) +robotgo.MoveClick(10, 20) +robotgo.MoveClick(10, 20, "left", true) ``` ###

.MouseToggle(down, button)

diff --git a/robot_info_test.go b/robot_info_test.go index 91d9a47..0ce128d 100644 --- a/robot_info_test.go +++ b/robot_info_test.go @@ -29,10 +29,16 @@ func TestGetVer(t *testing.T) { func TestGetScreenSize(t *testing.T) { x, y := robotgo.GetScreenSize() - log.Println("GetScreenSize: ", x, y) + log.Println("Get screen size: ", x, y) + + rect := robotgo.GetScreenRect() + fmt.Println("Get screen rect: ", rect) } func TestGetSysScale(t *testing.T) { s := robotgo.SysScale() log.Println("SysScale: ", s) + + f := robotgo.ScaleF() + log.Println("sclae: ", f) } diff --git a/robotgo_test.go b/robotgo_test.go index e7c0928..5852bc8 100644 --- a/robotgo_test.go +++ b/robotgo_test.go @@ -40,8 +40,8 @@ func TestSize(t *testing.T) { } func TestMoveMouse(t *testing.T) { - MoveMouse(20, 20) - MilliSleep(10) + Move(20, 20) + MilliSleep(50) x, y := GetMousePos() tt.Equal(t, 20, x) @@ -49,8 +49,8 @@ func TestMoveMouse(t *testing.T) { } func TestMoveMouseSmooth(t *testing.T) { - b := MoveMouseSmooth(100, 100) - MilliSleep(10) + b := MoveSmooth(100, 100) + MilliSleep(50) x, y := GetMousePos() tt.True(t, b) @@ -60,7 +60,7 @@ func TestMoveMouseSmooth(t *testing.T) { func TestDragMouse(t *testing.T) { DragMouse(500, 500) - MilliSleep(10) + MilliSleep(50) x, y := GetMousePos() tt.Equal(t, 500, x) @@ -68,18 +68,20 @@ func TestDragMouse(t *testing.T) { } func TestScrollMouse(t *testing.T) { - ScrollMouse(120, "up") + // ScrollMouse(120, "up") + Scroll(0, 120) MilliSleep(100) Scroll(210, 210) + MilliSleep(10) } func TestMoveRelative(t *testing.T) { Move(200, 200) - MilliSleep(10) + MilliSleep(50) MoveRelative(10, -10) - MilliSleep(10) + MilliSleep(50) x, y := GetMousePos() tt.Equal(t, 210, x) @@ -88,10 +90,10 @@ func TestMoveRelative(t *testing.T) { func TestMoveSmoothRelative(t *testing.T) { Move(200, 200) - MilliSleep(10) + MilliSleep(50) MoveSmoothRelative(10, -10) - MilliSleep(10) + MilliSleep(50) x, y := GetMousePos() tt.Equal(t, 210, x) @@ -99,7 +101,10 @@ func TestMoveSmoothRelative(t *testing.T) { } func TestMouseToggle(t *testing.T) { - e := MouseToggle("up", "right") + e := Toggle("right") + tt.Zero(t, e) + + e = Toggle("right", "up") tt.Zero(t, e) } @@ -141,6 +146,9 @@ func TestKeyCode(t *testing.T) { k := Keycode["1"] tt.Equal(t, 2, k) + + s := Special["+"] + tt.Equal(t, "=", s) } func TestBitmap(t *testing.T) { From 8a7d6a130674b4191adf952f948a812e328d1696 Mon Sep 17 00:00:00 2001 From: vcaesar Date: Thu, 25 Nov 2021 16:03:39 -0400 Subject: [PATCH 2/2] Update godoc --- bitmap.go | 6 ++++-- hook.go | 6 ++++-- robotgo.go | 48 ++++++++++++++++++++++++++++++++---------------- 3 files changed, 40 insertions(+), 20 deletions(-) diff --git a/bitmap.go b/bitmap.go index cd86c1d..4ee9f16 100644 --- a/bitmap.go +++ b/bitmap.go @@ -183,7 +183,8 @@ func FreeMMPointArr(pointArray C.MMPointArrayRef) { C.destroyMMPointArray(pointArray) } -// Deprecated: use the FindAllBitmap() +// Deprecated: use the FindAllBitmap(), +// // FindEveryBitmap find the every bitmap, same with the FindAllBitmap() func FindEveryBitmap(bit C.MMBitmapRef, args ...interface{}) []Point { return FindAllBitmap(bit, args...) @@ -433,7 +434,8 @@ func FindColorCS(color CHex, x, y, w, h int, args ...float64) (int, int) { return rx, ry } -// Deprecated: use the FindAllColor() +// Deprecated: use the FindAllColor(), +// // FindEveryColor find the every color, same with the FindAllColor() func FindEveryColor(color CHex, args ...interface{}) []Point { return FindAllColor(color, args...) diff --git a/hook.go b/hook.go index 4f645aa..e7ff930 100644 --- a/hook.go +++ b/hook.go @@ -36,14 +36,16 @@ func EventEnd() { hook.End() } -// Deprecated: use the EventStart() +// Deprecated: use the EventStart(), +// // Start start global event hook // return event channel func Start() chan hook.Event { return hook.Start() } -// Deprecated: use the EventEnd() +// Deprecated: use the EventEnd(), +// // End removes global event hook func End() { hook.End() diff --git a/robotgo.go b/robotgo.go index 33915fb..01ecc1c 100644 --- a/robotgo.go +++ b/robotgo.go @@ -359,19 +359,22 @@ func GetXDisplayName() string { return gname } -// Deprecated: use the ScaledF() +// Deprecated: use the ScaledF(), +// // ScaleX get the primary display horizontal DPI scale factor, drop func ScaleX() int { return int(C.scale_x()) } -// Deprecated: use the ScaledF() +// Deprecated: use the ScaledF(), +// // ScaleY get primary display vertical DPI scale factor, drop func ScaleY() int { return int(C.scale_y()) } -// Deprecated: use the ScaledF() +// Deprecated: use the ScaledF(), +// // Scale get the screen scale (only windows old), drop func Scale() int { dpi := map[int]int{ @@ -394,13 +397,15 @@ func Scale() int { return dpi[x] } -// Deprecated: use the ScaledF() +// Deprecated: use the ScaledF(), +// // Scale0 return ScaleX() / 0.96, drop func Scale0() int { return int(float64(ScaleX()) / 0.96) } -// Deprecated: use the ScaledF() +// Deprecated: use the ScaledF(), +// // Mul mul the scale, drop func Mul(x int) int { s := Scale() @@ -436,7 +441,8 @@ func CheckMouse(btn string) C.MMMouseButton { return C.LEFT_BUTTON } -// Deprecated: use the Move() +// Deprecated: use the Move(), +// // MoveMouse move the mouse func MoveMouse(x, y int) { Move(x, y) @@ -460,7 +466,8 @@ func Move(x, y int) { MilliSleep(MouseSleep) } -// Deprecated: use the DragSmooth() +// Deprecated: use the DragSmooth(), +// // DragMouse drag the mouse to (x, y), // It's same with the DragSmooth() now func DragMouse(x, y int, args ...interface{}) { @@ -471,7 +478,8 @@ func DragMouse(x, y int, args ...interface{}) { Toggle("left", "up") } -// Deprecated: use the DragSmooth() +// Deprecated: use the DragSmooth(), +// // Drag drag the mouse to (x, y), // It's not valid now, use the DragSmooth() func Drag(x, y int, args ...string) { @@ -498,7 +506,8 @@ func DragSmooth(x, y int, args ...interface{}) { Toggle("left", "up") } -// Deprecated: use the MoveSmooth() +// Deprecated: use the MoveSmooth(), +// // 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 { @@ -575,7 +584,8 @@ func GetMousePos() (int, int) { return x, y } -// Deprecated: use the Click() +// Deprecated: use the Click(), +// // MouseClick click the mouse // // robotgo.MouseClick(button string, double bool) @@ -653,7 +663,8 @@ func Toggle(key ...string) int { return int(i) } -// Deprecated: use the Toggle() +// Deprecated: use the Toggle(), +// // MouseToggle toggle the mouse // // Examples: @@ -674,7 +685,8 @@ func MouseToggle(togKey string, args ...interface{}) int { return int(i) } -// Deprecated: use the Scroll() +// Deprecated: use the Scroll(), +// // ScrollMouse scroll the mouse to (x, "up") // // Examples: @@ -1074,7 +1086,8 @@ func PasteStr(str string) string { return KeyTap("v", "control") } -// Deprecated: use the TypeStr() +// Deprecated: use the TypeStr(), +// // TypeString send a string, support unicode(no linux support) // TypeStr(string: The string to send), Wno-deprecated // @@ -1098,7 +1111,8 @@ func TypeStrDelay(str string, delay int) { Sleep(delay) } -// Deprecated: use the TypeStr() +// Deprecated: use the TypeStr(), +// // TypeStringDelayed type string delayed, Wno-deprecated // // This function will be removed in version v1.0.0 @@ -1112,7 +1126,8 @@ func SetKeyDelay(delay int) { C.set_keyboard_delay(C.size_t(delay)) } -// Deprecated: use the SetKeyDelay() +// Deprecated: use the SetKeyDelay(), +// // SetKeyboardDelay set keyboard delay, Wno-deprecated, // // This function will be removed in version v1.0.0 @@ -1288,7 +1303,8 @@ func GetHandle() int { return ghwnd } -// Deprecated: use the GetHandle() +// Deprecated: use the GetHandle(), +// // GetBHandle get the window handle, Wno-deprecated // // This function will be removed in version v1.0.0