mirror of
https://github.com/go-vgo/robotgo.git
synced 2025-06-05 00:03:55 +00:00
Merge pull request #407 from go-vgo/bitmap-pr
Add more test code and Update godoc
This commit is contained in:
commit
3e6ecc5925
@ -183,7 +183,8 @@ func FreeMMPointArr(pointArray C.MMPointArrayRef) {
|
|||||||
C.destroyMMPointArray(pointArray)
|
C.destroyMMPointArray(pointArray)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deprecated: use the FindAllBitmap()
|
// Deprecated: use the FindAllBitmap(),
|
||||||
|
//
|
||||||
// FindEveryBitmap find the every bitmap, same with the FindAllBitmap()
|
// FindEveryBitmap find the every bitmap, same with the FindAllBitmap()
|
||||||
func FindEveryBitmap(bit C.MMBitmapRef, args ...interface{}) []Point {
|
func FindEveryBitmap(bit C.MMBitmapRef, args ...interface{}) []Point {
|
||||||
return FindAllBitmap(bit, args...)
|
return FindAllBitmap(bit, args...)
|
||||||
@ -433,7 +434,8 @@ func FindColorCS(color CHex, x, y, w, h int, args ...float64) (int, int) {
|
|||||||
return rx, ry
|
return rx, ry
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deprecated: use the FindAllColor()
|
// Deprecated: use the FindAllColor(),
|
||||||
|
//
|
||||||
// FindEveryColor find the every color, same with the FindAllColor()
|
// FindEveryColor find the every color, same with the FindAllColor()
|
||||||
func FindEveryColor(color CHex, args ...interface{}) []Point {
|
func FindEveryColor(color CHex, args ...interface{}) []Point {
|
||||||
return FindAllColor(color, args...)
|
return FindAllColor(color, args...)
|
||||||
|
@ -213,8 +213,8 @@ robotgo.MoveMouseSmooth(100, 200, 1.0, 100.0)
|
|||||||
#### Examples:
|
#### Examples:
|
||||||
|
|
||||||
```Go
|
```Go
|
||||||
robogo.MouseClick()
|
robotgo.MouseClick()
|
||||||
robogo.MouseClick("left", true)
|
robotgo.MouseClick("left", true)
|
||||||
```
|
```
|
||||||
|
|
||||||
### <h3 id="MoveClick">.MoveClick(x, y, button, double)</h3>
|
### <h3 id="MoveClick">.MoveClick(x, y, button, double)</h3>
|
||||||
@ -231,8 +231,8 @@ robogo.MouseClick("left", true)
|
|||||||
#### Examples:
|
#### Examples:
|
||||||
|
|
||||||
```Go
|
```Go
|
||||||
robogo.MoveClick(10, 20)
|
robotgo.MoveClick(10, 20)
|
||||||
robogo.MoveClick(10, 20, "left", true)
|
robotgo.MoveClick(10, 20, "left", true)
|
||||||
```
|
```
|
||||||
|
|
||||||
### <h3 id="MouseToggle">.MouseToggle(down, button)</h3>
|
### <h3 id="MouseToggle">.MouseToggle(down, button)</h3>
|
||||||
|
@ -221,8 +221,8 @@ robotgo.MoveMouseSmooth(100, 200, 1.0, 100.0)
|
|||||||
#### 示例:
|
#### 示例:
|
||||||
|
|
||||||
```Go
|
```Go
|
||||||
robogo.MouseClick()
|
robotgo.MouseClick()
|
||||||
robogo.MouseClick("left", true)
|
robotgo.MouseClick("left", true)
|
||||||
```
|
```
|
||||||
|
|
||||||
### <h3 id="MoveClick">.MoveClick(x, y, button, double)</h3>
|
### <h3 id="MoveClick">.MoveClick(x, y, button, double)</h3>
|
||||||
@ -239,8 +239,8 @@ robogo.MouseClick("left", true)
|
|||||||
#### 示例:
|
#### 示例:
|
||||||
|
|
||||||
```Go
|
```Go
|
||||||
robogo.MoveClick(10, 20)
|
robotgo.MoveClick(10, 20)
|
||||||
robogo.MoveClick(10, 20, "left", true)
|
robotgo.MoveClick(10, 20, "left", true)
|
||||||
```
|
```
|
||||||
|
|
||||||
### <h3 id="MouseToggle">.MouseToggle(down, button)</h3>
|
### <h3 id="MouseToggle">.MouseToggle(down, button)</h3>
|
||||||
|
6
hook.go
6
hook.go
@ -36,14 +36,16 @@ func EventEnd() {
|
|||||||
hook.End()
|
hook.End()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deprecated: use the EventStart()
|
// Deprecated: use the EventStart(),
|
||||||
|
//
|
||||||
// Start start global event hook
|
// Start start global event hook
|
||||||
// return event channel
|
// return event channel
|
||||||
func Start() chan hook.Event {
|
func Start() chan hook.Event {
|
||||||
return hook.Start()
|
return hook.Start()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deprecated: use the EventEnd()
|
// Deprecated: use the EventEnd(),
|
||||||
|
//
|
||||||
// End removes global event hook
|
// End removes global event hook
|
||||||
func End() {
|
func End() {
|
||||||
hook.End()
|
hook.End()
|
||||||
|
@ -29,10 +29,16 @@ func TestGetVer(t *testing.T) {
|
|||||||
|
|
||||||
func TestGetScreenSize(t *testing.T) {
|
func TestGetScreenSize(t *testing.T) {
|
||||||
x, y := robotgo.GetScreenSize()
|
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) {
|
func TestGetSysScale(t *testing.T) {
|
||||||
s := robotgo.SysScale()
|
s := robotgo.SysScale()
|
||||||
log.Println("SysScale: ", s)
|
log.Println("SysScale: ", s)
|
||||||
|
|
||||||
|
f := robotgo.ScaleF()
|
||||||
|
log.Println("sclae: ", f)
|
||||||
}
|
}
|
||||||
|
48
robotgo.go
48
robotgo.go
@ -359,19 +359,22 @@ func GetXDisplayName() string {
|
|||||||
return gname
|
return gname
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deprecated: use the ScaledF()
|
// Deprecated: use the ScaledF(),
|
||||||
|
//
|
||||||
// ScaleX get the primary display horizontal DPI scale factor, drop
|
// ScaleX get the primary display horizontal DPI scale factor, drop
|
||||||
func ScaleX() int {
|
func ScaleX() int {
|
||||||
return int(C.scale_x())
|
return int(C.scale_x())
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deprecated: use the ScaledF()
|
// Deprecated: use the ScaledF(),
|
||||||
|
//
|
||||||
// ScaleY get primary display vertical DPI scale factor, drop
|
// ScaleY get primary display vertical DPI scale factor, drop
|
||||||
func ScaleY() int {
|
func ScaleY() int {
|
||||||
return int(C.scale_y())
|
return int(C.scale_y())
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deprecated: use the ScaledF()
|
// Deprecated: use the ScaledF(),
|
||||||
|
//
|
||||||
// Scale get the screen scale (only windows old), drop
|
// Scale get the screen scale (only windows old), drop
|
||||||
func Scale() int {
|
func Scale() int {
|
||||||
dpi := map[int]int{
|
dpi := map[int]int{
|
||||||
@ -394,13 +397,15 @@ func Scale() int {
|
|||||||
return dpi[x]
|
return dpi[x]
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deprecated: use the ScaledF()
|
// Deprecated: use the ScaledF(),
|
||||||
|
//
|
||||||
// Scale0 return ScaleX() / 0.96, drop
|
// Scale0 return ScaleX() / 0.96, drop
|
||||||
func Scale0() int {
|
func Scale0() int {
|
||||||
return int(float64(ScaleX()) / 0.96)
|
return int(float64(ScaleX()) / 0.96)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deprecated: use the ScaledF()
|
// Deprecated: use the ScaledF(),
|
||||||
|
//
|
||||||
// Mul mul the scale, drop
|
// Mul mul the scale, drop
|
||||||
func Mul(x int) int {
|
func Mul(x int) int {
|
||||||
s := Scale()
|
s := Scale()
|
||||||
@ -436,7 +441,8 @@ func CheckMouse(btn string) C.MMMouseButton {
|
|||||||
return C.LEFT_BUTTON
|
return C.LEFT_BUTTON
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deprecated: use the Move()
|
// Deprecated: use the Move(),
|
||||||
|
//
|
||||||
// MoveMouse move the mouse
|
// MoveMouse move the mouse
|
||||||
func MoveMouse(x, y int) {
|
func MoveMouse(x, y int) {
|
||||||
Move(x, y)
|
Move(x, y)
|
||||||
@ -460,7 +466,8 @@ func Move(x, y int) {
|
|||||||
MilliSleep(MouseSleep)
|
MilliSleep(MouseSleep)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deprecated: use the DragSmooth()
|
// Deprecated: use the DragSmooth(),
|
||||||
|
//
|
||||||
// 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{}) {
|
||||||
@ -471,7 +478,8 @@ func DragMouse(x, y int, args ...interface{}) {
|
|||||||
Toggle("left", "up")
|
Toggle("left", "up")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deprecated: use the DragSmooth()
|
// Deprecated: use the DragSmooth(),
|
||||||
|
//
|
||||||
// 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) {
|
||||||
@ -498,7 +506,8 @@ func DragSmooth(x, y int, args ...interface{}) {
|
|||||||
Toggle("left", "up")
|
Toggle("left", "up")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deprecated: use the MoveSmooth()
|
// Deprecated: use the MoveSmooth(),
|
||||||
|
//
|
||||||
// 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 {
|
||||||
@ -575,7 +584,8 @@ func GetMousePos() (int, int) {
|
|||||||
return x, y
|
return x, y
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deprecated: use the Click()
|
// Deprecated: use the Click(),
|
||||||
|
//
|
||||||
// MouseClick click the mouse
|
// MouseClick click the mouse
|
||||||
//
|
//
|
||||||
// robotgo.MouseClick(button string, double bool)
|
// robotgo.MouseClick(button string, double bool)
|
||||||
@ -653,7 +663,8 @@ func Toggle(key ...string) int {
|
|||||||
return int(i)
|
return int(i)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deprecated: use the Toggle()
|
// Deprecated: use the Toggle(),
|
||||||
|
//
|
||||||
// MouseToggle toggle the mouse
|
// MouseToggle toggle the mouse
|
||||||
//
|
//
|
||||||
// Examples:
|
// Examples:
|
||||||
@ -674,7 +685,8 @@ func MouseToggle(togKey string, args ...interface{}) int {
|
|||||||
return int(i)
|
return int(i)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deprecated: use the Scroll()
|
// Deprecated: use the Scroll(),
|
||||||
|
//
|
||||||
// ScrollMouse scroll the mouse to (x, "up")
|
// ScrollMouse scroll the mouse to (x, "up")
|
||||||
//
|
//
|
||||||
// Examples:
|
// Examples:
|
||||||
@ -1074,7 +1086,8 @@ func PasteStr(str string) string {
|
|||||||
return KeyTap("v", "control")
|
return KeyTap("v", "control")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deprecated: use the TypeStr()
|
// Deprecated: use the TypeStr(),
|
||||||
|
//
|
||||||
// TypeString send a string, support unicode(no linux support)
|
// TypeString send a string, support unicode(no linux support)
|
||||||
// TypeStr(string: The string to send), Wno-deprecated
|
// TypeStr(string: The string to send), Wno-deprecated
|
||||||
//
|
//
|
||||||
@ -1098,7 +1111,8 @@ func TypeStrDelay(str string, delay int) {
|
|||||||
Sleep(delay)
|
Sleep(delay)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deprecated: use the TypeStr()
|
// 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
|
// 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))
|
C.set_keyboard_delay(C.size_t(delay))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deprecated: use the SetKeyDelay()
|
// Deprecated: use the SetKeyDelay(),
|
||||||
|
//
|
||||||
// SetKeyboardDelay set keyboard delay, Wno-deprecated,
|
// SetKeyboardDelay set keyboard delay, Wno-deprecated,
|
||||||
//
|
//
|
||||||
// This function will be removed in version v1.0.0
|
// This function will be removed in version v1.0.0
|
||||||
@ -1288,7 +1303,8 @@ func GetHandle() int {
|
|||||||
return ghwnd
|
return ghwnd
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deprecated: use the GetHandle()
|
// 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
|
// This function will be removed in version v1.0.0
|
||||||
|
@ -40,8 +40,8 @@ func TestSize(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestMoveMouse(t *testing.T) {
|
func TestMoveMouse(t *testing.T) {
|
||||||
MoveMouse(20, 20)
|
Move(20, 20)
|
||||||
MilliSleep(10)
|
MilliSleep(50)
|
||||||
x, y := GetMousePos()
|
x, y := GetMousePos()
|
||||||
|
|
||||||
tt.Equal(t, 20, x)
|
tt.Equal(t, 20, x)
|
||||||
@ -49,8 +49,8 @@ func TestMoveMouse(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestMoveMouseSmooth(t *testing.T) {
|
func TestMoveMouseSmooth(t *testing.T) {
|
||||||
b := MoveMouseSmooth(100, 100)
|
b := MoveSmooth(100, 100)
|
||||||
MilliSleep(10)
|
MilliSleep(50)
|
||||||
x, y := GetMousePos()
|
x, y := GetMousePos()
|
||||||
|
|
||||||
tt.True(t, b)
|
tt.True(t, b)
|
||||||
@ -60,7 +60,7 @@ func TestMoveMouseSmooth(t *testing.T) {
|
|||||||
|
|
||||||
func TestDragMouse(t *testing.T) {
|
func TestDragMouse(t *testing.T) {
|
||||||
DragMouse(500, 500)
|
DragMouse(500, 500)
|
||||||
MilliSleep(10)
|
MilliSleep(50)
|
||||||
x, y := GetMousePos()
|
x, y := GetMousePos()
|
||||||
|
|
||||||
tt.Equal(t, 500, x)
|
tt.Equal(t, 500, x)
|
||||||
@ -68,18 +68,20 @@ func TestDragMouse(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestScrollMouse(t *testing.T) {
|
func TestScrollMouse(t *testing.T) {
|
||||||
ScrollMouse(120, "up")
|
// ScrollMouse(120, "up")
|
||||||
|
Scroll(0, 120)
|
||||||
MilliSleep(100)
|
MilliSleep(100)
|
||||||
|
|
||||||
Scroll(210, 210)
|
Scroll(210, 210)
|
||||||
|
MilliSleep(10)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMoveRelative(t *testing.T) {
|
func TestMoveRelative(t *testing.T) {
|
||||||
Move(200, 200)
|
Move(200, 200)
|
||||||
MilliSleep(10)
|
MilliSleep(50)
|
||||||
|
|
||||||
MoveRelative(10, -10)
|
MoveRelative(10, -10)
|
||||||
MilliSleep(10)
|
MilliSleep(50)
|
||||||
|
|
||||||
x, y := GetMousePos()
|
x, y := GetMousePos()
|
||||||
tt.Equal(t, 210, x)
|
tt.Equal(t, 210, x)
|
||||||
@ -88,10 +90,10 @@ func TestMoveRelative(t *testing.T) {
|
|||||||
|
|
||||||
func TestMoveSmoothRelative(t *testing.T) {
|
func TestMoveSmoothRelative(t *testing.T) {
|
||||||
Move(200, 200)
|
Move(200, 200)
|
||||||
MilliSleep(10)
|
MilliSleep(50)
|
||||||
|
|
||||||
MoveSmoothRelative(10, -10)
|
MoveSmoothRelative(10, -10)
|
||||||
MilliSleep(10)
|
MilliSleep(50)
|
||||||
|
|
||||||
x, y := GetMousePos()
|
x, y := GetMousePos()
|
||||||
tt.Equal(t, 210, x)
|
tt.Equal(t, 210, x)
|
||||||
@ -99,7 +101,10 @@ func TestMoveSmoothRelative(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestMouseToggle(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)
|
tt.Zero(t, e)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -141,6 +146,9 @@ func TestKeyCode(t *testing.T) {
|
|||||||
|
|
||||||
k := Keycode["1"]
|
k := Keycode["1"]
|
||||||
tt.Equal(t, 2, k)
|
tt.Equal(t, 2, k)
|
||||||
|
|
||||||
|
s := Special["+"]
|
||||||
|
tt.Equal(t, "=", s)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBitmap(t *testing.T) {
|
func TestBitmap(t *testing.T) {
|
||||||
|
Loading…
Reference in New Issue
Block a user