mirror of
https://github.com/go-vgo/robotgo.git
synced 2025-06-07 01:03:54 +00:00
add all mouse and key sleep option and CaptureImg(), Scale0(), ScrollRelative() function; Update godoc and name
This commit is contained in:
parent
dc5f64ef65
commit
0c262d4d42
82
robotgo.go
82
robotgo.go
@ -80,6 +80,13 @@ func GetVersion() string {
|
|||||||
return Version
|
return Version
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
// MouseSleep set the mouse default millisecond sleep time
|
||||||
|
MouseSleep = 0
|
||||||
|
// KeySleep set the key default millisecond sleep time
|
||||||
|
KeySleep = 0
|
||||||
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
// Map a map[string]interface{}
|
// Map a map[string]interface{}
|
||||||
Map map[string]interface{}
|
Map map[string]interface{}
|
||||||
@ -222,7 +229,7 @@ func SysScale() float64 {
|
|||||||
return float64(s)
|
return float64(s)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Scaled x * sys-scale
|
// Scaled return x * sys_scale
|
||||||
func Scaled(x int) int {
|
func Scaled(x int) int {
|
||||||
return int(float64(x) * SysScale())
|
return int(float64(x) * SysScale())
|
||||||
}
|
}
|
||||||
@ -261,6 +268,11 @@ func Scale() int {
|
|||||||
return dpi[x]
|
return dpi[x]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Scale0 return ScaleX() / 0.96
|
||||||
|
func Scale0() int {
|
||||||
|
return int(float64(ScaleX()) / 0.96)
|
||||||
|
}
|
||||||
|
|
||||||
// Mul mul the scale
|
// Mul mul the scale
|
||||||
func Mul(x int) int {
|
func Mul(x int) int {
|
||||||
s := Scale()
|
s := Scale()
|
||||||
@ -328,6 +340,14 @@ func GoCaptureScreen(args ...int) Bitmap {
|
|||||||
return ToBitmap(bit)
|
return ToBitmap(bit)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CaptureImg capture the screen and return image.Image
|
||||||
|
func CaptureImg(args ...int) image.Image {
|
||||||
|
bit := CaptureScreen(args...)
|
||||||
|
defer FreeBitmap(bit)
|
||||||
|
|
||||||
|
return ToImage(bit)
|
||||||
|
}
|
||||||
|
|
||||||
// SaveCapture capture screen and save
|
// SaveCapture capture screen and save
|
||||||
func SaveCapture(spath string, args ...int) {
|
func SaveCapture(spath string, args ...int) {
|
||||||
bit := CaptureScreen(args...)
|
bit := CaptureScreen(args...)
|
||||||
@ -370,22 +390,23 @@ func MoveMouse(x, y int) {
|
|||||||
Move(x, y)
|
Move(x, y)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Move move the mouse
|
// Move move the mouse to (x, y)
|
||||||
func Move(x, y int) {
|
func Move(x, y int) {
|
||||||
cx := C.int32_t(x)
|
cx := C.int32_t(x)
|
||||||
cy := C.int32_t(y)
|
cy := C.int32_t(y)
|
||||||
C.move_mouse(cx, cy)
|
C.move_mouse(cx, cy)
|
||||||
|
|
||||||
|
MilliSleep(MouseSleep)
|
||||||
}
|
}
|
||||||
|
|
||||||
// DragMouse drag the mouse
|
// DragMouse drag the mouse to (x, y)
|
||||||
func DragMouse(x, y int, args ...string) {
|
func DragMouse(x, y int, args ...string) {
|
||||||
Drag(x, y, args...)
|
Drag(x, y, args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Drag drag the mouse
|
// Drag drag the mouse to (x, y)
|
||||||
func Drag(x, y int, args ...string) {
|
func Drag(x, y int, args ...string) {
|
||||||
var button C.MMMouseButton = C.LEFT_BUTTON
|
var button C.MMMouseButton = C.LEFT_BUTTON
|
||||||
|
|
||||||
cx := C.int32_t(x)
|
cx := C.int32_t(x)
|
||||||
cy := C.int32_t(y)
|
cy := C.int32_t(y)
|
||||||
|
|
||||||
@ -394,6 +415,7 @@ func Drag(x, y int, args ...string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
C.drag_mouse(cx, cy, button)
|
C.drag_mouse(cx, cy, button)
|
||||||
|
MilliSleep(MouseSleep)
|
||||||
}
|
}
|
||||||
|
|
||||||
// DragSmooth drag the mouse smooth
|
// DragSmooth drag the mouse smooth
|
||||||
@ -436,6 +458,7 @@ func MoveSmooth(x, y int, args ...interface{}) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
cbool := C.move_mouse_smooth(cx, cy, low, high, C.int(mouseDelay))
|
cbool := C.move_mouse_smooth(cx, cy, low, high, C.int(mouseDelay))
|
||||||
|
MilliSleep(MouseSleep)
|
||||||
|
|
||||||
return bool(cbool)
|
return bool(cbool)
|
||||||
}
|
}
|
||||||
@ -449,12 +472,12 @@ func MoveArgs(x, y int) (int, int) {
|
|||||||
return mx, my
|
return mx, my
|
||||||
}
|
}
|
||||||
|
|
||||||
// MoveRelative move mose relative
|
// MoveRelative move mouse with relative
|
||||||
func MoveRelative(x, y int) {
|
func MoveRelative(x, y int) {
|
||||||
Move(MoveArgs(x, y))
|
Move(MoveArgs(x, y))
|
||||||
}
|
}
|
||||||
|
|
||||||
// MoveSmoothRelative move mose smooth relative
|
// MoveSmoothRelative move mouse smooth with relative
|
||||||
func MoveSmoothRelative(x, y int, args ...interface{}) {
|
func MoveSmoothRelative(x, y int, args ...interface{}) {
|
||||||
mx, my := MoveArgs(x, y)
|
mx, my := MoveArgs(x, y)
|
||||||
MoveSmooth(mx, my, args...)
|
MoveSmooth(mx, my, args...)
|
||||||
@ -495,6 +518,7 @@ func Click(args ...interface{}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
C.mouse_click(button, double)
|
C.mouse_click(button, double)
|
||||||
|
MilliSleep(MouseSleep)
|
||||||
}
|
}
|
||||||
|
|
||||||
// MoveClick move and click the mouse
|
// MoveClick move and click the mouse
|
||||||
@ -523,6 +547,7 @@ func MouseToggle(togKey string, args ...interface{}) int {
|
|||||||
i := C.mouse_toggle(down, button)
|
i := C.mouse_toggle(down, button)
|
||||||
|
|
||||||
C.free(unsafe.Pointer(down))
|
C.free(unsafe.Pointer(down))
|
||||||
|
MilliSleep(MouseSleep)
|
||||||
return int(i)
|
return int(i)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -533,9 +558,10 @@ func ScrollMouse(x int, direction string) {
|
|||||||
C.scroll_mouse(cx, cy)
|
C.scroll_mouse(cx, cy)
|
||||||
|
|
||||||
C.free(unsafe.Pointer(cy))
|
C.free(unsafe.Pointer(cy))
|
||||||
|
MilliSleep(MouseSleep)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Scroll scroll the mouse with x, y
|
// Scroll scroll the mouse to (x, y)
|
||||||
//
|
//
|
||||||
// robotgo.Scroll(x, y, msDelay int)
|
// robotgo.Scroll(x, y, msDelay int)
|
||||||
func Scroll(x, y int, args ...int) {
|
func Scroll(x, y int, args ...int) {
|
||||||
@ -549,6 +575,13 @@ func Scroll(x, y int, args ...int) {
|
|||||||
cz := C.int(msDelay)
|
cz := C.int(msDelay)
|
||||||
|
|
||||||
C.scroll(cx, cy, cz)
|
C.scroll(cx, cy, cz)
|
||||||
|
MilliSleep(MouseSleep)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ScrollRelative scroll mouse with relative
|
||||||
|
func ScrollRelative(x, y int, args ...int) {
|
||||||
|
mx, my := MoveArgs(x, y)
|
||||||
|
Scroll(mx, my, args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetMouseDelay set mouse delay
|
// SetMouseDelay set mouse delay
|
||||||
@ -645,6 +678,7 @@ func KeyTap(tapKey string, args ...interface{}) string {
|
|||||||
C.free(unsafe.Pointer(amod))
|
C.free(unsafe.Pointer(amod))
|
||||||
C.free(unsafe.Pointer(amodt))
|
C.free(unsafe.Pointer(amodt))
|
||||||
|
|
||||||
|
MilliSleep(KeySleep)
|
||||||
return C.GoString(str)
|
return C.GoString(str)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -695,6 +729,7 @@ func KeyToggle(key string, args ...string) string {
|
|||||||
C.free(unsafe.Pointer(cmKey))
|
C.free(unsafe.Pointer(cmKey))
|
||||||
C.free(unsafe.Pointer(cmKeyT))
|
C.free(unsafe.Pointer(cmKeyT))
|
||||||
|
|
||||||
|
MilliSleep(KeySleep)
|
||||||
return C.GoString(str)
|
return C.GoString(str)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -811,6 +846,7 @@ func TypeStr(str string, args ...float64) {
|
|||||||
MicroSleep(tm)
|
MicroSleep(tm)
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
MilliSleep(KeySleep)
|
||||||
}
|
}
|
||||||
|
|
||||||
// PasteStr paste a string, support UTF-8
|
// PasteStr paste a string, support UTF-8
|
||||||
@ -989,7 +1025,7 @@ func FindCBitmap(bmp CBitmap, args ...interface{}) (int, int) {
|
|||||||
|
|
||||||
// FindBitmap find the bitmap's pos
|
// FindBitmap find the bitmap's pos
|
||||||
//
|
//
|
||||||
// robotgo.FindBitmap(bitmap, subbitamp C.MMBitmapRef, tolerance float64)
|
// robotgo.FindBitmap(bitmap, source_bitamp C.MMBitmapRef, tolerance float64)
|
||||||
//
|
//
|
||||||
// |tolerance| should be in the range 0.0f - 1.0f, denoting how closely the
|
// |tolerance| should be in the range 0.0f - 1.0f, denoting how closely the
|
||||||
// colors in the bitmaps need to match, with 0 being exact and 1 being any.
|
// colors in the bitmaps need to match, with 0 being exact and 1 being any.
|
||||||
@ -1023,7 +1059,7 @@ func FindBitmap(bit C.MMBitmapRef, args ...interface{}) (int, int) {
|
|||||||
|
|
||||||
// FindPic finding the image by path
|
// FindPic finding the image by path
|
||||||
//
|
//
|
||||||
// robotgo.FindPic(path string, subbitamp C.MMBitmapRef, tolerance float64)
|
// robotgo.FindPic(path string, source_bitamp C.MMBitmapRef, tolerance float64)
|
||||||
//
|
//
|
||||||
// This method only automatically free the internal bitmap,
|
// This method only automatically free the internal bitmap,
|
||||||
// use `defer robotgo.FreeBitmap(bit)` to free the bitmap
|
// use `defer robotgo.FreeBitmap(bit)` to free the bitmap
|
||||||
@ -1435,32 +1471,32 @@ func ShowAlert(title, msg string, args ...string) bool {
|
|||||||
var (
|
var (
|
||||||
// title string
|
// title string
|
||||||
// msg string
|
// msg string
|
||||||
defaultButton = "Ok"
|
defaultBtn = "Ok"
|
||||||
cancelButton = "Cancel"
|
cancelBtn = "Cancel"
|
||||||
)
|
)
|
||||||
|
|
||||||
if len(args) > 0 {
|
if len(args) > 0 {
|
||||||
// title = args[0]
|
// title = args[0]
|
||||||
// msg = args[1]
|
// msg = args[1]
|
||||||
defaultButton = args[0]
|
defaultBtn = args[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(args) > 1 {
|
if len(args) > 1 {
|
||||||
cancelButton = args[1]
|
cancelBtn = args[1]
|
||||||
}
|
}
|
||||||
|
|
||||||
atitle := C.CString(title)
|
cTitle := C.CString(title)
|
||||||
amsg := C.CString(msg)
|
cMsg := C.CString(msg)
|
||||||
adefaultButton := C.CString(defaultButton)
|
defaultButton := C.CString(defaultBtn)
|
||||||
acancelButton := C.CString(cancelButton)
|
cancelButton := C.CString(cancelBtn)
|
||||||
|
|
||||||
cbool := C.show_alert(atitle, amsg, adefaultButton, acancelButton)
|
cbool := C.show_alert(cTitle, cMsg, defaultButton, cancelButton)
|
||||||
ibool := int(cbool)
|
ibool := int(cbool)
|
||||||
|
|
||||||
C.free(unsafe.Pointer(atitle))
|
C.free(unsafe.Pointer(cTitle))
|
||||||
C.free(unsafe.Pointer(amsg))
|
C.free(unsafe.Pointer(cMsg))
|
||||||
C.free(unsafe.Pointer(adefaultButton))
|
C.free(unsafe.Pointer(defaultButton))
|
||||||
C.free(unsafe.Pointer(acancelButton))
|
C.free(unsafe.Pointer(cancelButton))
|
||||||
|
|
||||||
return ibool == 0
|
return ibool == 0
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user