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

Add more test code and Update godoc
This commit is contained in:
Evans 2021-11-25 15:09:42 -05:00 committed by GitHub
commit 3e6ecc5925
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 74 additions and 40 deletions

View File

@ -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...)

View File

@ -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)
```
### <h3 id="MoveClick">.MoveClick(x, y, button, double)</h3>
@ -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)
```
### <h3 id="MouseToggle">.MouseToggle(down, button)</h3>

View File

@ -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)
```
### <h3 id="MoveClick">.MoveClick(x, y, button, double)</h3>
@ -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)
```
### <h3 id="MouseToggle">.MouseToggle(down, button)</h3>

View File

@ -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()

View File

@ -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)
}

View File

@ -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

View File

@ -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) {