robotgo

package module
v0.101.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 22, 2021 License: Apache-2.0 Imports: 22 Imported by: 0

README

Robotgo

Build Status CircleCI Status Build Status Appveyor Go Report Card GoDoc GitHub release

NOTE I just forked this to remove bitmap support so it'll compile on Win easily.

Golang Desktop Automation. Control the mouse, keyboard, bitmap and image, read the screen, process, Window Handle and global event listener.

RobotGo supports Mac, Windows, and Linux(X11); and robotgo supports arm64 and x86-amd64.

Chinese Simplified

Contents

Docs

Binding:

ADB, packaging android adb API.

Robotn, binding JavaScript and other, support more language.

Requirements:

Now, Please make sure Golang, GCC is installed correctly before installing RobotGo.

ALL:
Golang

GCC
For Mac OS X:

Xcode Command Line Tools (And Privacy setting: #277 )

xcode-select --install
For Windows:

MinGW-w64 (Use recommended)

Or the other GCC (But you should compile the "libpng" with yourself. 
Or you can removed the bitmap.go. 

In the plans, the bitmap.go will moves to the bitmap dir, but break the API. )
For everything else:
GCC, libpng

X11 with the XTest extension (also known as the Xtst library)

Event:

xcb, xkb, libxkbcommon
Ubuntu:
# gcc
sudo apt install gcc libc6-dev

sudo apt install libx11-dev xorg-dev libxtst-dev libpng++-dev

sudo apt install xcb libxcb-xkb-dev x11-xkb-utils libx11-xcb-dev libxkbcommon-x11-dev libxkbcommon-dev

sudo apt install xsel xclip
Fedora:
sudo dnf install libxkbcommon-devel libXtst-devel libxkbcommon-x11-devel xorg-x11-xkb-utils-devel

sudo dnf install libpng-devel

sudo dnf install xsel xclip

Installation:

With Go module support (Go 1.11+), just import:

import "github.com/drognisep/robotgo"

Otherwise, to install the robotgo package, run the command:

go get github.com/go-vgo/robotgo

png.h: No such file or directory? Please see issues/47.

Update:

go get -u github.com/go-vgo/robotgo

Note go1.10.x C file compilation cache problem, golang #24355. go mod vendor problem, golang #26366.

Examples:

Mouse
package main

import (
  "github.com/drognisep/robotgo"
)

func main() {
  // robotgo.ScrollMouse(10, "up")
  robotgo.Scroll(0, -10)
  robotgo.Scroll(100, 0)

  robotgo.MilliSleep(100)
  robotgo.ScrollSmooth(-10, 6)
  // robotgo.ScrollRelative(10, -100)

  robotgo.MouseSleep = 100
  robotgo.Move(10, 20)
  robotgo.MoveRelative(0, -10)
  robotgo.Drag(10, 10)

  robotgo.Click("wheelRight")
  robotgo.Click("left", true)
  robotgo.MoveSmooth(100, 200, 1.0, 10.0)

  robotgo.Toggle("left")
  robotgo.Toggle("left", "up")
}
Keyboard
package main

import (
  "fmt"

  "github.com/drognisep/robotgo"
)

func main() {
  robotgo.TypeStr("Hello World")
  robotgo.TypeStr("だんしゃり", 1.0)
  // robotgo.TypeStr("テストする")

  robotgo.TypeStr("Hi galaxy. こんにちは世界.")
  robotgo.Sleep(1)

  // ustr := uint32(robotgo.CharCodeAt("Test", 0))
  // robotgo.UnicodeType(ustr)

  robotgo.KeySleep = 100
  robotgo.KeyTap("enter")
  // robotgo.TypeStr("en")
  robotgo.KeyTap("i", "alt", "command")

  arr := []string{"alt", "command"}
  robotgo.KeyTap("i", arr)

  robotgo.MilliSleep(100)
  robotgo.KeyToggle("a")
  robotgo.KeyToggle("a", "up")

  robotgo.WriteAll("Test")
  text, err := robotgo.ReadAll()
  if err == nil {
    fmt.Println(text)
  }
}
Screen
package main

import (
  "fmt"

  "github.com/drognisep/robotgo"
  "github.com/vcaesar/imgo"
)

func main() {
  x, y := robotgo.GetMousePos()
  fmt.Println("pos: ", x, y)

  color := robotgo.GetPixelColor(100, 200)
  fmt.Println("color---- ", color)

  sx, sy := robotgo.GetScreenSize()
  fmt.Println("get screen size: ", sx, sy)

  bit := robotgo.CaptureScreen(10, 10, 30, 30)
  defer robotgo.FreeBitmap(bit)
  robotgo.SaveBitmap(bit, "test_1.png")

  img := robotgo.ToImage(bit)
  imgo.Save("test.png", img)
}
Bitmap
package main

import (
  "fmt"

  "github.com/drognisep/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...", bitmap)
  img := robotgo.ToImage(bitmap)
  robotgo.SavePng(img, "test_1.png")

  bit2 := robotgo.ToCBitmap(robotgo.ImgToBitmap(img))
  fx, fy := robotgo.FindBitmap(bit2)
  fmt.Println("FindBitmap------ ", fx, fy)
  robotgo.Move(fx, fy)

  arr := robotgo.FindAllBitmap(bit2)
  fmt.Println("Find all bitmap: ", arr)
  robotgo.SaveBitmap(bitmap, "test.png")

  fx, fy = robotgo.FindBitmap(bitmap)
  fmt.Println("FindBitmap------ ", fx, fy)

  robotgo.SaveBitmap(bitmap, "test.png")
}
OpenCV
package main

import (
  "fmt"
  "math/rand"

  "github.com/drognisep/robotgo"
  "github.com/vcaesar/gcv"
)

func main() {
  opencv()
}

func opencv() {
  name := "test.png"
  name1 := "test_001.png"
  robotgo.SaveCapture(name1, 10, 10, 30, 30)
  robotgo.SaveCapture(name)

  fmt.Print("gcv find image: ")
  fmt.Println(gcv.FindImgFile(name1, name))
  fmt.Println(gcv.FindAllImgFile(name1, name))

  bit := robotgo.OpenBitmap(name1)
  defer robotgo.FindBitmap(bit)
  fmt.Print("find bitmap: ")
  fmt.Println(robotgo.FindBitmap(bit))

  // bit0 := robotgo.CaptureScreen()
  // img := robotgo.ToImage(bit0)
  // bit1 := robotgo.CaptureScreen(10, 10, 30, 30)
  // img1 := robotgo.ToImage(bit1)
  // defer robotgo.FreeBitmapArr(bit0, bit1)
  img := robotgo.CaptureImg()
  img1 := robotgo.CaptureImg(10, 10, 30, 30)

  fmt.Print("gcv find image: ")
  fmt.Println(gcv.FindImg(img1, img))
  fmt.Println()

  res := gcv.FindAllImg(img1, img)
  fmt.Println(res[0].TopLeft.Y, res[0].Rects.TopLeft.X, res)
  x, y := res[0].TopLeft.X, res[0].TopLeft.Y
  robotgo.Move(x, y-rand.Intn(5))
  robotgo.MilliSleep(100)
  robotgo.Click()

  res = gcv.FindAll(img1, img) // use find template and sift
  fmt.Println("find all: ", res)
  res1 := gcv.Find(img1, img)
  fmt.Println("find: ", res1)

  img2, _, _ := robotgo.DecodeImg("test_001.png")
  x, y = gcv.FindX(img2, img)
  fmt.Println(x, y)
}
Event
package main

import (
  "fmt"

  "github.com/drognisep/robotgo"
  hook "github.com/robotn/gohook"
)

func main() {
  add()
  low()
  event()
}

func add() {
  fmt.Println("--- Please press ctrl + shift + q to stop hook ---")
  robotgo.EventHook(hook.KeyDown, []string{"q", "ctrl", "shift"}, func(e hook.Event) {
    fmt.Println("ctrl-shift-q")
    robotgo.EventEnd()
  })

  fmt.Println("--- Please press w---")
  robotgo.EventHook(hook.KeyDown, []string{"w"}, func(e hook.Event) {
    fmt.Println("w")
  })

  s := robotgo.EventStart()
  <-robotgo.EventProcess(s)
}

func low() {
	evChan := hook.Start()
	defer hook.End()

	for ev := range evChan {
		fmt.Println("hook: ", ev)
	}
}

func event() {
  ok := robotgo.AddEvents("q", "ctrl", "shift")
  if ok {
    fmt.Println("add events...")
  }

  keve := robotgo.AddEvent("k")
  if keve {
    fmt.Println("you press... ", "k")
  }

  mleft := robotgo.AddEvent("mleft")
  if mleft {
    fmt.Println("you press... ", "mouse left button")
  }
}
Window
package main

import (
  "fmt"

  "github.com/drognisep/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 {
 	  fmt.Println("ok@@@ ", "ok")
  }

  title := robotgo.GetTitle()
  fmt.Println("title@@@ ", title)
}

CrossCompiling

Windows64 to windows32
SET CGO_ENABLED=1
SET GOARCH=386
go build main.go
Other to windows

Install Requirements (Ubuntu):

sudo apt install gcc-multilib
sudo apt install gcc-mingw-w64
# fix err: zlib.h: No such file or directory
sudo apt install libz-mingw-w64-dev

Build the binary:

GOOS=windows GOARCH=amd64 CGO_ENABLED=1 CC=x86_64-w64-mingw32-gcc CXX=x86_64-w64-mingw32-g++ go build -x ./
// CC=mingw-w64\x86_64-7.2.0-win32-seh-rt_v5-rev1\mingw64\bin\gcc.exe
// CXX=mingw-w64\x86_64-7.2.0-win32-seh-rt_v5-rev1\mingw64\bin\g++.exe

Some discussions and questions, please see issues/228, issues/143.

Authors

Plans

  • Update Find an image on screen, read pixels from an image
  • Update Window Handle
  • Try support Android, maybe support IOS

Contributors

License

Robotgo is primarily distributed under the terms of "both the MIT license and the Apache License (Version 2.0)", with portions covered by various BSD-like licenses.

See LICENSE-APACHE, LICENSE-MIT.

Documentation

Overview

Package robotgo Go native cross-platform system automation.

Please make sure Golang, GCC is installed correctly before installing RobotGo;

See Requirements:

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

Installation: With Go module support (Go 1.11+), just import: ```go

import "github.com/drognisep/robotgo"

```

Otherwise, to install the robotgo package, run the command:

go get -u github.com/go-vgo/robotgo

Index

Constants

View Source
const (
	// Version get the robotgo version
	Version = "v0.100.0.1189, MT. Baker!"
)

Variables

View Source
var (
	// MouseSleep set the mouse default millisecond sleep time
	MouseSleep = 0
	// KeySleep set the key default millisecond sleep time
	KeySleep = 0
)
View Source
var Keycode = keycode.Keycode

Keycode robotgo hook key's code map

View Source
var MouseMap = keycode.MouseMap

MouseMap robotgo hook mouse's code map

View Source
var Special = keycode.Special

Special is the special key map

Functions

func ActiveName

func ActiveName(name string) error

ActiveName active the window by name

Examples:

robotgo.ActiveName("chrome")

func ActivePID

func ActivePID(pid int32, args ...int) error

ActivePID active the window by PID,

If args[0] > 0 on the Windows platform via a window handle to active, If args[0] > 0 on the unix platform via a xid to active

func ActivePIDC

func ActivePIDC(pid int32, args ...int) error

ActivePIDC active the window by PID, If args[0] > 0 on the unix platform via a xid to active

func AddEvent

func AddEvent(key string) bool

AddEvent add event listener,

parameters for the string type, the keyboard corresponding key parameters,

mouse arguments: mleft, center, mright, wheelDown, wheelUp, wheelLeft, wheelRight.

Use "robotgo.AddEvents()" or "gohook" add asynchronous event listener

func AddEvents

func AddEvents(key string, arr ...string) bool

AddEvents add global event hook

robotgo.AddEvents("q") robotgo.AddEvents("q", "ctrl") robotgo.AddEvents("q", "ctrl", "shift")

func AddMouse

func AddMouse(btn string, x ...int16) bool

AddMouse add mouse event hook

mouse arguments: left, center, right, wheelDown, wheelUp, wheelLeft, wheelRight.

robotgo.AddMouse("left") robotgo.AddMouse("left", 100, 100)

func AddMousePos

func AddMousePos(x, y int16) bool

AddMousePos add listen mouse event pos hook

func ByteToImg

func ByteToImg(b []byte) (image.Image, error)

ByteToImg convert []byte to image.Image

func CaptureImg

func CaptureImg(args ...int) image.Image

CaptureImg capture the screen and return image.Image

func CaptureScreen

func CaptureScreen(args ...int) C.MMBitmapRef

CaptureScreen capture the screen return bitmap(c struct), use `defer robotgo.FreeBitmap(bitmap)` to free the bitmap

robotgo.CaptureScreen(x, y, w, h int)

func CharCodeAt

func CharCodeAt(s string, n int) rune

CharCodeAt char code at utf-8

func CheckMouse

func CheckMouse(btn string) C.MMMouseButton

CheckMouse check the mouse button

func Click

func Click(args ...interface{})

Click click the mouse button

robotgo.Click(button string, double bool)

Examples:

robotgo.Click() // default is left button
robotgo.Click("right")
robotgo.Click("wheelLeft")

func CloseWindow

func CloseWindow(args ...int32)

CloseWindow close the window

func DecodeImg

func DecodeImg(path string) (image.Image, string, error)

DecodeImg decode the image to image.Image and return

func Drag deprecated

func Drag(x, y int, args ...string)

Deprecated: use the DragSmooth(),

Drag drag the mouse to (x, y), It's not valid now, use the DragSmooth()

func DragMouse deprecated

func DragMouse(x, y int, args ...interface{})

Deprecated: use the DragSmooth(),

DragMouse drag the mouse to (x, y), It's same with the DragSmooth() now

func DragSmooth

func DragSmooth(x, y int, args ...interface{})

DragSmooth drag the mouse like smooth to (x, y)

Examples:

robotgo.DragSmooth(10, 10)

func End deprecated

func End()

Deprecated: use the EventEnd(),

End removes global event hook

func EventEnd

func EventEnd()

EventEnd removes global event hook

func EventHook

func EventHook(when uint8, keysPressed []string, callback func(hook.Event))

EventHook register gohook event

func EventProcess

func EventProcess(events chan hook.Event) chan bool

EventProcess return go hook process

func EventStart

func EventStart() chan hook.Event

EventStart start global event hook return event channel

func FindIds

func FindIds(name string) ([]int32, error)

FindIds finds the all processes named with a subset of "name" (case insensitive), return matched IDs.

func FindName

func FindName(pid int32) (string, error)

FindName find the process name by the process id

func FindNames

func FindNames() ([]string, error)

FindNames find the all process name

func FindPath

func FindPath(pid int32) (string, error)

FindPath find the process path by the process pid

func FreeBitmap

func FreeBitmap(bitmap C.MMBitmapRef)

FreeBitmap free and dealloc the C bitmap

func GetActive

func GetActive() C.MData

GetActive get the active window

func GetBHandle deprecated

func GetBHandle() int

Deprecated: use the GetHandle(),

GetBHandle get the window handle, Wno-deprecated

This function will be removed in version v1.0.0

func GetBounds

func GetBounds(pid int32, args ...int) (int, int, int, int)

GetBounds get the window bounds

func GetHandPid

func GetHandPid(pid int32, args ...int32) C.MData

GetHandPid get handle mdata by pid

func GetHandle

func GetHandle() int

GetHandle get the window handle

func GetMouseColor

func GetMouseColor() string

GetMouseColor get the mouse pos's color

func GetMousePos

func GetMousePos() (int, int)

GetMousePos get the mouse's portion return x, y

func GetPID

func GetPID() int32

GetPID get the process id return int32

func GetPixelColor

func GetPixelColor(x, y int) string

GetPixelColor get the pixel color return string

func GetPxColor

func GetPxColor(x, y int) C.MMRGBHex

GetPxColor get the pixel color return C.MMRGBHex

func GetScaleSize

func GetScaleSize() (int, int)

GetScaleSize get the screen scale size

func GetScreenSize

func GetScreenSize() (int, int)

GetScreenSize get the screen size

func GetText

func GetText(imgPath string, args ...string) (string, error)

GetText get the image text by tesseract ocr

robotgo.GetText(imgPath, lang string)

func GetTitle

func GetTitle(args ...int32) string

GetTitle get the window title return string

Examples:

fmt.Println(robotgo.GetTitle())

ids, _ := robotgo.FindIds()
robotgo.GetTitle(ids[0])

func GetVersion

func GetVersion() string

GetVersion get the robotgo version

func GetXDisplayName

func GetXDisplayName() string

GetXDisplayName get XDisplay name (Linux)

func GetXId

func GetXId(xu *xgbutil.XUtil, pid int32) (xproto.Window, error)

GetXId get the xid return window and error

func GetXidFromPid

func GetXidFromPid(xu *xgbutil.XUtil, pid int32) (xproto.Window, error)

GetXidFromPid get the xide from pid

func GoString

func GoString(char *C.char) string

GoString trans C.char to string

func Height

func Height(img image.Image) int

Height return the image.Image height

func HexToRgb

func HexToRgb(hex uint32) *C.uint8_t

HexToRgb trans hex to rgb

func ImgSize

func ImgSize(path string) (int, int, error)

ImgSize get the file image size

func Is64Bit

func Is64Bit() bool

Is64Bit determine whether the sys is 64bit

func IsValid

func IsValid() bool

IsValid valid the window

func KeyDown

func KeyDown(key string)

KeyDown press down a key

func KeyPress

func KeyPress(key string)

KeyPress press key string

func KeyTap

func KeyTap(tapKey string, args ...interface{}) string

KeyTap tap the keyboard code;

See keys:

https://github.com/go-vgo/robotgo/blob/master/docs/keys.md

Examples:

robotgo.KeySleep = 100 // 100 millisecond
robotgo.KeyTap("a")
robotgo.KeyTap("i", "alt", "command")

arr := []string{"alt", "command"}
robotgo.KeyTap("i", arr)

func KeyToggle

func KeyToggle(key string, args ...string) string

KeyToggle toggle the keyboard, if there not have args default is "down"

See keys:

https://github.com/go-vgo/robotgo/blob/master/docs/keys.md

Examples:

robotgo.KeyToggle("a")
robotgo.KeyToggle("a", "up")

robotgo.KeyToggle("a", "up", "alt", "cmd")

func KeyUp

func KeyUp(key string)

KeyUp press up a key

func Kill

func Kill(pid int32) error

Kill kill the process by PID

func MaxWindow

func MaxWindow(pid int32, args ...interface{})

MaxWindow set the window max

func MicroSleep

func MicroSleep(tm float64)

MicroSleep time C.microsleep(tm)

func MilliSleep

func MilliSleep(tm int)

MilliSleep sleep tm milli second

func MinWindow

func MinWindow(pid int32, args ...interface{})

MinWindow set the window min

func MouseClick deprecated

func MouseClick(args ...interface{})

Deprecated: use the Click(),

MouseClick click the mouse

robotgo.MouseClick(button string, double bool)

func MouseToggle deprecated

func MouseToggle(togKey string, args ...interface{}) int

Deprecated: use the Toggle(),

MouseToggle toggle the mouse

Examples:

robotgo.MouseToggle("down", "right")
robotgo.MouseToggle("up", "right")

func Move

func Move(x, y int)

Move move the mouse to (x, y)

Examples:

robotgo.MouseSleep = 100  // 100 millisecond
robotgo.Move(10, 10)

func MoveArgs

func MoveArgs(x, y int) (int, int)

MoveArgs get the mouse relative args

func MoveClick

func MoveClick(x, y int, args ...interface{})

MoveClick move and click the mouse

robotgo.MoveClick(x, y int, button string, double bool)

Examples:

robotgo.MouseSleep = 100
robotgo.MoveClick(10, 10)

func MoveMouse deprecated

func MoveMouse(x, y int)

Deprecated: use the Move(),

MoveMouse move the mouse

func MoveMouseSmooth deprecated

func MoveMouseSmooth(x, y int, args ...interface{}) bool

Deprecated: use the MoveSmooth(),

MoveMouseSmooth move the mouse smooth, moves mouse to x, y human like, with the mouse button up.

func MoveRelative

func MoveRelative(x, y int)

MoveRelative move mouse with relative

func MoveSmooth

func MoveSmooth(x, y int, args ...interface{}) bool

MoveSmooth move the mouse smooth, moves mouse to x, y human like, with the mouse button up.

robotgo.MoveSmooth(x, y int, low, high float64, mouseDelay int)

Examples:

robotgo.MoveSmooth(10, 10)
robotgo.MoveSmooth(10, 10, 1.0, 2.0)

func MoveSmoothRelative

func MoveSmoothRelative(x, y int, args ...interface{})

MoveSmoothRelative move mouse smooth with relative

func MovesClick

func MovesClick(x, y int, args ...interface{})

MovesClick move smooth and click the mouse

use the `robotgo.MouseSleep = 100`

func Mul deprecated

func Mul(x int) int

Deprecated: use the ScaledF(),

Mul mul the scale, drop

func OpenImg

func OpenImg(path string) ([]byte, error)

OpenImg open the image return []byte

func PadHex

func PadHex(hex C.MMRGBHex) string

PadHex trans C.MMRGBHex to string

func PasteStr

func PasteStr(str string) string

PasteStr paste a string, support UTF-8, write the string to clipboard and tap `cmd + v`

func PidExists

func PidExists(pid int32) (bool, error)

PidExists determine whether the process exists

func Pids

func Pids() ([]int32, error)

Pids get the all process id

func Read

func Read(path string) (image.Image, error)

Read read the file return image.Image

func ReadAll

func ReadAll() (string, error)

ReadAll read string from clipboard

func RgbToHex

func RgbToHex(r, g, b uint8) C.uint32_t

RgbToHex trans rgb to hex

func Run

func Run(path string) ([]byte, error)

Run run a cmd shell

func Save

func Save(img image.Image, path string) error

Save create a image file with the image.Image

func SaveImg

func SaveImg(b []byte, path string) error

SaveImg save the image by []byte

func SaveJpeg

func SaveJpeg(img image.Image, path string) error

SaveJpeg save the image by image.Image

func SavePng

func SavePng(img image.Image, path string) error

SavePng save the image by image.Image

func Scale deprecated

func Scale() int

Deprecated: use the ScaledF(),

Scale get the screen scale (only windows old), drop

func Scale0 deprecated

func Scale0() int

Deprecated: use the ScaledF(),

Scale0 return ScaleX() / 0.96, drop

func ScaleF

func ScaleF() float64

ScaleF get the system scale val

func ScaleX deprecated

func ScaleX() int

Deprecated: use the ScaledF(),

ScaleX get the primary display horizontal DPI scale factor, drop

func ScaleY deprecated

func ScaleY() int

Deprecated: use the ScaledF(),

ScaleY get primary display vertical DPI scale factor, drop

func Scaled

func Scaled(x int) int

Scaled get the screen scaled size

func Scaled0

func Scaled0(x int, f float64) int

Scaled0 return int(x * f)

func Scroll

func Scroll(x, y int, args ...int)

Scroll scroll the mouse to (x, y)

robotgo.Scroll(x, y, msDelay int)

Examples:

robotgo.Scroll(10, 10)

func ScrollMouse deprecated

func ScrollMouse(x int, direction string)

Deprecated: use the Scroll(),

ScrollMouse scroll the mouse to (x, "up")

Examples:

robotgo.ScrollMouse(10, "down")
robotgo.ScrollMouse(10, "up")

func ScrollRelative

func ScrollRelative(x, y int, args ...int)

ScrollRelative scroll mouse with relative

Examples:

robotgo.ScrollRelative(10, 10)

func ScrollSmooth

func ScrollSmooth(to int, args ...int)

ScrollSmooth scroll the mouse smooth, default scroll 5 times and sleep 100 millisecond

robotgo.ScrollSmooth(toy, num, sleep, tox)

Examples:

robotgo.ScrollSmooth(-10)
robotgo.ScrollSmooth(-10, 6, 200, -10)

func SetActive

func SetActive(win C.MData)

SetActive set the window active

func SetDelay

func SetDelay(d ...int)

SetDelay set the key and mouse delay

func SetHandle

func SetHandle(hwnd int)

SetHandle set the window handle

func SetHandlePid

func SetHandlePid(pid int32, args ...int32)

SetHandlePid set the window handle by pid

func SetKeyDelay

func SetKeyDelay(delay int)

SetKeyDelay set keyboard delay

func SetKeyboardDelay deprecated

func SetKeyboardDelay(delay int)

Deprecated: use the SetKeyDelay(),

SetKeyboardDelay set keyboard delay, Wno-deprecated,

This function will be removed in version v1.0.0

func SetMouseDelay

func SetMouseDelay(delay int)

SetMouseDelay set mouse delay

func SetXDisplayName

func SetXDisplayName(name string) string

SetXDisplayName set XDisplay name (Linux)

func ShowAlert

func ShowAlert(title, msg string, args ...string) bool

ShowAlert show a alert window Displays alert with the attributes. If cancel button is not given, only the default button is displayed

Examples:

robotgo.ShowAlert("hi", "window", "ok", "cancel")

func Sleep

func Sleep(tm int)

Sleep time.Sleep tm second

func Start deprecated

func Start() chan hook.Event

Deprecated: use the EventStart(),

Start start global event hook return event channel

func StopEvent

func StopEvent()

StopEvent stop event listener, use by AddEvent()

func StrToImg

func StrToImg(data string) (image.Image, error)

StrToImg convert base64 string to image.Image

func SysScale

func SysScale() float64

SysScale get the sys scale

func ToByteImg

func ToByteImg(img image.Image, fm ...string) []byte

ToByteImg convert image.Image to []byte

func ToImage

func ToImage(bit C.MMBitmapRef) image.Image

ToImage convert C.MMBitmapRef to standard image.Image

func ToMMRGBHex

func ToMMRGBHex(hex CHex) C.MMRGBHex

ToMMRGBHex trans CHex to C.MMRGBHex

func ToRGBA

func ToRGBA(bit C.MMBitmapRef) *image.RGBA

ToRGBA convert C.MMBitmapRef to standard image.RGBA

func ToRGBAGo

func ToRGBAGo(bmp1 Bitmap) *image.RGBA

ToRGBAGo convert Bitmap to standard image.RGBA

func ToStringImg

func ToStringImg(img image.Image, fm ...string) string

ToStringImg convert image.Image to string

func ToUC

func ToUC(text string) []string

ToUC trans string to unicode []string

func ToUint8p

func ToUint8p(dst []uint8) *uint8

ToUint8p convert the []uint8 to uint8 pointer

func Toggle

func Toggle(key ...string) int

Toggle toggle the mouse, support button:

	"left", "center", "right",
 "wheelDown", "wheelUp", "wheelLeft", "wheelRight"

Examples:

robotgo.Toggle("left") // default is down
robotgo.Toggle("left", "up")

func Try

func Try(fun func(), handler func(interface{}))

Try handler(err)

func TypeStr

func TypeStr(str string, args ...float64)

TypeStr send a string, support UTF-8

robotgo.TypeStr(string: The string to send, float64: microsleep time, x11 option)

Examples:

robotgo.TypeStr("abc@123, hi, こんにちは")

func TypeStrDelay

func TypeStrDelay(str string, delay int)

TypeStrDelay type string delayed

func TypeString deprecated

func TypeString(str string, delay ...int)

Deprecated: use the TypeStr(),

TypeString send a string, support unicode(no linux support) TypeStr(string: The string to send), Wno-deprecated

This function will be removed in version v1.0.0

func TypeStringDelayed deprecated

func TypeStringDelayed(str string, delay int)

Deprecated: use the TypeStr(),

TypeStringDelayed type string delayed, Wno-deprecated

This function will be removed in version v1.0.0

func U32ToHex

func U32ToHex(hex C.uint32_t) C.MMRGBHex

U32ToHex trans C.uint32_t to C.MMRGBHex

func U8ToHex

func U8ToHex(hex *C.uint8_t) C.MMRGBHex

U8ToHex trans *C.uint8_t to C.MMRGBHex

func UnicodeType

func UnicodeType(str uint32)

UnicodeType tap uint32 unicode

func Width

func Width(img image.Image) int

Width return the image.Image width

func WriteAll

func WriteAll(text string) error

WriteAll write string to clipboard

Types

type Bitmap

type Bitmap struct {
	ImgBuf        *uint8
	Width, Height int

	Bytewidth     int
	BitsPixel     uint8
	BytesPerPixel uint8
}

Bitmap is Bitmap struct

func GoCaptureScreen

func GoCaptureScreen(args ...int) Bitmap

GoCaptureScreen capture the screen and return bitmap(go struct)

func ImgToBitmap

func ImgToBitmap(m image.Image) (bit Bitmap)

ImgToBitmap convert the standard image.Image to Bitmap

func RGBAToBitmap

func RGBAToBitmap(r1 *image.RGBA) (bit Bitmap)

RGBAToBitmap convert the standard image.RGBA to Bitmap

func ToBitmap

func ToBitmap(bit C.MMBitmapRef) Bitmap

ToBitmap trans C.MMBitmapRef to Bitmap

type CBitmap

type CBitmap C.MMBitmapRef

CBitmap define CBitmap as C.MMBitmapRef type

type CHex

type CHex C.MMRGBHex

CHex define CHex as c rgb Hex type (C.MMRGBHex)

func UintToHex

func UintToHex(u uint32) CHex

UintToHex trans uint32 to robotgo.CHex

type Map

type Map map[string]interface{}

Map a map[string]interface{}

type Nps

type Nps struct {
	Pid  int32
	Name string
}

Nps process struct

func Process

func Process() ([]Nps, error)

Process get the all process struct

type Point

type Point struct {
	X int
	Y int
}

Point is point struct

type Rect

type Rect struct {
	Point
	Size
}

Rect is rect structure

func GetScreenRect

func GetScreenRect(displayId ...int) Rect

GetScreenRect get the screen rect (x, y, w, h)

type Size

type Size struct {
	W, H int
}

Size is size structure

Directories

Path Synopsis
Package clipboard read/write on clipboard
Package clipboard read/write on clipboard
cmd
key

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL