main.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package main
  2. import (
  3. "fmt"
  4. "github.com/go-vgo/robotgo"
  5. )
  6. func main() {
  7. // syscall.NewLazyDLL("user32.dll").NewProc("SetProcessDPIAware").Call()
  8. width, height := robotgo.GetScaleSize()
  9. fmt.Println("get scale screen size: ", width, height)
  10. bitmap := robotgo.CaptureScreen(0, 0, width, height)
  11. defer robotgo.FreeBitmap(bitmap)
  12. // bitmap.Save(bitmap, "test.png")
  13. robotgo.Save(robotgo.ToImage(bitmap), "test.png")
  14. robotgo.Scale = true
  15. robotgo.Move(10, 10)
  16. robotgo.MoveSmooth(100, 100)
  17. fmt.Println(robotgo.Location())
  18. num := robotgo.DisplaysNum()
  19. for i := 0; i < num; i++ {
  20. rect := robotgo.GetScreenRect(i)
  21. fmt.Println("rect: ", rect)
  22. }
  23. }
  24. func old() {
  25. sx := robotgo.ScaleX() // Deprecated
  26. s := robotgo.Scale1() // Deprecated, use the ScaleF() function
  27. robotx, roboty := 35*s/100, 25*s/100
  28. fmt.Println("scale: ", sx, s, " pos: ", robotx, roboty)
  29. mx, my := robotgo.Location()
  30. sx, sy := mx*s/100, my*s/100
  31. rx, ry, rw, rh := sx, sy, robotx, roboty
  32. // bit1 := robotgo.CaptureScreen(10, 20, robotw, roboth)
  33. bit1 := robotgo.CaptureScreen(rx, ry, rw, rh)
  34. defer robotgo.FreeBitmap(bit1)
  35. // bitmap.Save(bit1, "test2.png")
  36. robotgo.Save(robotgo.ToImage(bit1), "test2.png")
  37. clo := robotgo.GetPixelColor(robotx, roboty)
  38. fmt.Println("GetPixelColor...", clo)
  39. }