Robotgo v0.70.0 发布了, 跨平台的Go 桌面自动化操作

Golang 归档:201901
普通
浏览:3221
2019-01-13 19:47:51
RobotGo, Go Native cross-platform GUI automation

项目地址

https://github.com/go-vgo/robotgo

发行包下载

https://github.com/go-vgo/robotgo/releases

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)
}
注意事项
  • 此文章对你有帮助,对作者表示感谢(微信):
  • 本文地址:https://22v.net/article/3225/
  • 转载本文时,请注明转载自“SamBlog”的字样。
  • 如此文章有损您的合法权益,请使用页面底部的邮箱与我取得联系。
分类目录
文章归档
友情站点