Go语言:模拟鼠标操作(go-vgo/robotgo)
李大钊:我们要八小时工作!八小时睡觉!另外的八小时留给自己!
▌前置安装:
1
| go get github.com/go-vgo/robotgo
|
▌按键操作:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| package main
import ( "github.com/go-vgo/robotgo" )
func main() { robotgo.ScrollMouse(3, `up`) robotgo.ScrollMouse(2, `down`)
robotgo.MouseClick(`left`, false)
robotgo.MouseToggle(`down`, `left`) robotgo.MouseToggle(`up`, `left`) }
|
▌位置操作:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| package main
import ( "github.com/go-vgo/robotgo" )
func main() { robotgo.MoveMouse(800, 400)
robotgo.MoveMouseSmooth(800, 400)
robotgo.MoveMouseSmooth(800, 400, 20.0, 200.0) }
|
▌组合操作:
1 2 3 4 5 6 7 8 9 10
| package main
import ( "github.com/go-vgo/robotgo" )
func main() { robotgo.MoveClick(800, 400, `left`, true) }
|
▌所在位置:
1 2 3 4 5 6 7 8 9 10 11
| package main
import ( "github.com/go-vgo/robotgo" )
func main() { x, y := robotgo.GetMousePos() println(`x:`, x, ` y:`, y) }
|
转载:https://zhuanlan.zhihu.com/p/140445455