项目地址
发行包下载
Examples:
//鼠标
package main
import (
"github.com/go-vgo/robotgo"
)
func main() {
robotgo.ScrollMouse(10, "up")
robotgo.MouseClick("left", true)
robotgo.MoveMouseSmooth(100, 200, 1.0, 100.0)
}
//键盘
package main
import (
"fmt"
"github.com/go-vgo/robotgo"
)
func main() {
robotgo.TypeString("Hello World")
robotgo.TypeString("测试")
robotgo.TypeStr("测试")
robotgo.TypeStr("山达尔星新星军团, galaxy. こんにちは世界.")
robotgo.Sleep(1)
ustr := uint32(robotgo.CharCodeAt("测试", 0))
robotgo.UnicodeType(ustr)
robotgo.KeyTap("enter")
robotgo.TypeString("en")
robotgo.KeyTap("i", "alt", "command")
arr := []string{"alt", "command"}
robotgo.KeyTap("i", arr)
robotgo.WriteAll("测试")
text, err := robotgo.ReadAll()
if err == nil {
fmt.Println(text)
}
}
//屏幕
package main
import (
"fmt"
"github.com/go-vgo/robotgo"
)
func main() {
x, y := robotgo.GetMousePos()
fmt.Println("pos: ", x, y)
color := robotgo.GetPixelColor(100, 200)
fmt.Println("color----", color)
}
//位图
package main
import (
"fmt"
"github.com/go-vgo/robotgo"
)
func main() {
bitmap := robotgo.CaptureScreen(10, 20, 30, 40)
// use `defer robotgo.FreeBitmap(bit)` to free the bitmap
defer robotgo.FreeBitmap(bitmap)
fmt.Println("...", bitmap)
fx, fy := robotgo.FindBitmap(bitmap)
fmt.Println("FindBitmap------", fx, fy)
robotgo.SaveBitmap(bitmap, "test.png")
}
//事件
package main
import (
"fmt"
"github.com/go-vgo/robotgo"
)
func main() {
keve := robotgo.AddEvent("k")
if keve == 0 {
fmt.Println("you press... ", "k")
}
mleft := robotgo.AddEvent("mleft")
if mleft == 0 {
fmt.Println("you press... ", "mouse left button")
}
}
//窗口句柄
package main
import (
"fmt"
"github.com/go-vgo/robotgo"
)
func main() {
fpid, err := robotgo.FindIds("Google")
if err == nil {
fmt.Println("pids...", fpid)
if len(fpid) > 0 {
robotgo.ActivePID(fpid[0])
robotgo.Kill(fpid[0])
}
}
robotgo.ActiveName("chrome")
isExist, err := robotgo.PidExists(100)
if err == nil && isExist {
fmt.Println("pid exists is", isExist)
robotgo.Kill(100)
}
abool := robotgo.ShowAlert("test", "robotgo")
if abool == 0 {
fmt.Println("ok@@@ ", "ok")
}
title := robotgo.GetTitle()
fmt.Println("title@@@ ", title)
}