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/go-vgo/robotgo"
```
Otherwise, to install the robotgo package, run the command:
go get -u github.com/go-vgo/robotgo
Index ¶
- Constants
- Variables
- func ActiveName(name string) error
- func ActivePID(pid int32, args ...int) error
- func ActivePIDC(pid int32, args ...int) error
- func AddEvent(key string) bool
- func AddEvents(key string, arr ...string) bool
- func AddMouse(btn string, x ...int16) bool
- func AddMousePos(x, y int16) bool
- func BitmapClick(bitmap C.MMBitmapRef, args ...interface{})
- func BitmapFromStr(str string) C.MMBitmapRef
- func BitmapStr(str string) C.MMBitmapRefdeprecated
- func ByteToImg(b []byte) (image.Image, error)
- func CaptureImg(args ...int) image.Image
- func CaptureScreen(args ...int) C.MMBitmapRef
- func CharCodeAt(s string, n int) rune
- func CheckMouse(btn string) C.MMMouseButton
- func Click(args ...interface{})
- func CloseWindow(args ...int32)
- func Convert(opath, spath string, args ...int) string
- func CopyBitPB(bitmap C.MMBitmapRef) bool
- func CopyBitpb(bitmap C.MMBitmapRef) booldeprecated
- func CountBitmap(bitmap, sbit C.MMBitmapRef, args ...float32) int
- func CountColor(color CHex, args ...interface{}) int
- func CountColorCS(color CHex, x, y, w, h int, args ...float64) int
- func DecodeImg(path string) (image.Image, string, error)
- func DeepCopyBit(bitmap C.MMBitmapRef) C.MMBitmapRef
- func Drag(x, y int, args ...string)deprecated
- func DragMouse(x, y int, args ...interface{})deprecated
- func DragSmooth(x, y int, args ...interface{})
- func End()deprecated
- func EventEnd()
- func EventHook(when uint8, keysPressed []string, callback func(hook.Event))
- func EventProcess(events chan hook.Event) chan bool
- func EventStart() chan hook.Event
- func FindBitmap(bit C.MMBitmapRef, args ...interface{}) (int, int)
- func FindCBitmap(bmp CBitmap, args ...interface{}) (int, int)
- func FindColor(color CHex, args ...interface{}) (int, int)
- func FindColorCS(color CHex, x, y, w, h int, args ...float64) (int, int)
- func FindIds(name string) ([]int32, error)
- func FindName(pid int32) (string, error)
- func FindNames() ([]string, error)
- func FindPath(pid int32) (string, error)
- func FindPic(path string, args ...interface{}) (int, int)
- func FreeBitmap(bitmap C.MMBitmapRef)
- func FreeBitmapArr(bit ...C.MMBitmapRef)
- func FreeMMPointArr(pointArray C.MMPointArrayRef)
- func GetActive() C.MData
- func GetBHandle() intdeprecated
- func GetBounds(pid int32, args ...int) (int, int, int, int)
- func GetColor(bitmap C.MMBitmapRef, x, y int) C.MMRGBHex
- func GetColors(bitmap C.MMBitmapRef, x, y int) string
- func GetHandPid(pid int32, args ...int32) C.MData
- func GetHandle() int
- func GetImgSize(imgPath string) (int, int)
- func GetMouseColor() string
- func GetMousePos() (int, int)
- func GetPID() int32
- func GetPixelColor(x, y int) string
- func GetPortion(bit C.MMBitmapRef, x, y, w, h int) C.MMBitmapRef
- func GetPxColor(x, y int) C.MMRGBHex
- func GetScaleSize() (int, int)
- func GetScreenSize() (int, int)
- func GetText(imgPath string, args ...string) (string, error)
- func GetTitle(args ...int32) string
- func GetVersion() string
- func GetXDisplayName() string
- func GetXId(xu *xgbutil.XUtil, pid int32) (xproto.Window, error)
- func GetXidFromPid(xu *xgbutil.XUtil, pid int32) (xproto.Window, error)
- func GoString(char *C.char) string
- func Height(img image.Image) int
- func HexToRgb(hex uint32) *C.uint8_t
- func ImgSize(path string) (int, int, error)
- func Is64Bit() bool
- func IsValid() bool
- func KeyDown(key string)
- func KeyPress(key string)
- func KeyTap(tapKey string, args ...interface{}) string
- func KeyToggle(key string, args ...string) string
- func KeyUp(key string)
- func Kill(pid int32) error
- func MaxWindow(pid int32, args ...interface{})
- func MicroSleep(tm float64)
- func MilliSleep(tm int)
- func MinWindow(pid int32, args ...interface{})
- func MouseClick(args ...interface{})deprecated
- func MouseToggle(togKey string, args ...interface{}) intdeprecated
- func Move(x, y int)
- func MoveArgs(x, y int) (int, int)
- func MoveClick(x, y int, args ...interface{})
- func MoveMouse(x, y int)deprecated
- func MoveMouseSmooth(x, y int, args ...interface{}) booldeprecated
- func MoveRelative(x, y int)
- func MoveSmooth(x, y int, args ...interface{}) bool
- func MoveSmoothRelative(x, y int, args ...interface{})
- func MovesClick(x, y int, args ...interface{})
- func Mul(x int) intdeprecated
- func OpenBitmap(gpath string, args ...int) C.MMBitmapRef
- func OpenImg(path string) ([]byte, error)
- func PadHex(hex C.MMRGBHex) string
- func PasteStr(str string) string
- func PidExists(pid int32) (bool, error)
- func Pids() ([]int32, error)
- func PointInBounds(bitmap C.MMBitmapRef, x, y int) bool
- func Read(path string) (image.Image, error)
- func ReadAll() (string, error)
- func ReadBitmap(bitmap C.MMBitmapRef) bool
- func RgbToHex(r, g, b uint8) C.uint32_t
- func Run(path string) ([]byte, error)
- func Save(img image.Image, path string) error
- func SaveBitmap(bitmap C.MMBitmapRef, gpath string, args ...int) string
- func SaveCapture(spath string, args ...int) string
- func SaveImg(b []byte, path string) error
- func SaveJpeg(img image.Image, path string) error
- func SavePng(img image.Image, path string) error
- func Scale() intdeprecated
- func Scale0() intdeprecated
- func ScaleF() float64
- func ScaleX() intdeprecated
- func ScaleY() intdeprecated
- func Scaled(x int) int
- func Scaled0(x int, f float64) int
- func Scroll(x, y int, args ...int)
- func ScrollMouse(x int, direction string)deprecated
- func ScrollRelative(x, y int, args ...int)
- func ScrollSmooth(to int, args ...int)
- func SetActive(win C.MData)
- func SetDelay(d ...int)
- func SetHandle(hwnd int)
- func SetHandlePid(pid int32, args ...int32)
- func SetKeyDelay(delay int)
- func SetKeyboardDelay(delay int)deprecated
- func SetMouseDelay(delay int)
- func SetXDisplayName(name string) string
- func ShowAlert(title, msg string, args ...string) bool
- func Sleep(tm int)
- func Start() chan hook.Eventdeprecated
- func StopEvent()
- func StrToImg(data string) (image.Image, error)
- func SysScale() float64
- func ToBitmapBytes(bit C.MMBitmapRef) []byte
- func ToByteImg(img image.Image, fm ...string) []byte
- func ToCBitmap(bit Bitmap) C.MMBitmapRef
- func ToImage(bit C.MMBitmapRef) image.Image
- func ToMMBitmapRef(bit CBitmap) C.MMBitmapRef
- func ToMMRGBHex(hex CHex) C.MMRGBHex
- func ToRGBA(bit C.MMBitmapRef) *image.RGBA
- func ToRGBAGo(bmp1 Bitmap) *image.RGBA
- func ToStringImg(img image.Image, fm ...string) string
- func ToUC(text string) []string
- func ToUint8p(dst []uint8) *uint8
- func TocharBitmap(bit C.MMBitmapRef) *C.char
- func Toggle(key ...string) int
- func TostringBitmap(bit C.MMBitmapRef) string
- func Try(fun func(), handler func(interface{}))
- func TypeStr(str string, args ...float64)
- func TypeStrDelay(str string, delay int)
- func TypeString(str string, delay ...int)deprecated
- func TypeStringDelayed(str string, delay int)deprecated
- func U32ToHex(hex C.uint32_t) C.MMRGBHex
- func U8ToHex(hex *C.uint8_t) C.MMRGBHex
- func UnicodeType(str uint32)
- func Width(img image.Image) int
- func WriteAll(text string) error
- type Bitmap
- type CBitmap
- type CHex
- type Map
- type Nps
- type Point
- type Rect
- type Size
Constants ¶
const (
// Version get the robotgo version
Version = "v0.100.0.1189, MT. Baker!"
)
Variables ¶
var ( // MouseSleep set the mouse default millisecond sleep time MouseSleep = 0 // KeySleep set the key default millisecond sleep time KeySleep = 0 )
var Keycode = keycode.Keycode
Keycode robotgo hook key's code map
var MouseMap = keycode.MouseMap
MouseMap robotgo hook mouse's code map
var Special = keycode.Special
Special is the special key map
Functions ¶
func ActivePID ¶
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 ¶
ActivePIDC active the window by PID, If args[0] > 0 on the unix platform via a xid to active
func AddEvent ¶
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 ¶
AddEvents add global event hook
robotgo.AddEvents("q") robotgo.AddEvents("q", "ctrl") robotgo.AddEvents("q", "ctrl", "shift")
func AddMouse ¶
AddMouse add mouse event hook
mouse arguments: left, center, right, wheelDown, wheelUp, wheelLeft, wheelRight.
robotgo.AddMouse("left") robotgo.AddMouse("left", 100, 100)
func BitmapClick ¶
func BitmapClick(bitmap C.MMBitmapRef, args ...interface{})
BitmapClick find the bitmap and click
func BitmapFromStr ¶
func BitmapFromStr(str string) C.MMBitmapRef
BitmapFromStr read bitmap from the string
func BitmapStr
deprecated
func BitmapStr(str string) C.MMBitmapRef
Deprecated: use the BitmapFromStr(),
BitmapStr bitmap from string
func CaptureImg ¶ added in v0.100.1
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 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 CopyBitpb
deprecated
func CopyBitpb(bitmap C.MMBitmapRef) bool
Deprecated: CopyBitpb copy bitmap to pasteboard, Wno-deprecated
This function will be removed in version v1.0.0
func CountBitmap ¶
func CountBitmap(bitmap, sbit C.MMBitmapRef, args ...float32) int
CountBitmap count of the bitmap
func CountColor ¶
CountColor count bitmap color
func CountColorCS ¶
CountColorCS count bitmap color by CaptureScreen
func DeepCopyBit ¶
func DeepCopyBit(bitmap C.MMBitmapRef) C.MMBitmapRef
DeepCopyBit deep copy bitmap
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 EventProcess ¶
EventProcess return go hook process
func EventStart ¶
EventStart start global event hook return event channel
func FindBitmap ¶
func FindBitmap(bit C.MMBitmapRef, args ...interface{}) (int, int)
FindBitmap find the bitmap's pos
robotgo.FindBitmap(bitmap, source_bitamp C.MMBitmapRef, tolerance float64) |tolerance| should be in the range 0.0f - 1.0f, denoting how closely the colors in the bitmaps need to match, with 0 being exact and 1 being any.
This method only automatically free the internal bitmap, use `defer robotgo.FreeBitmap(bit)` to free the bitmap
func FindCBitmap ¶
FindCBitmap find bitmap's pos by CBitmap
func FindColor ¶
FindColor find bitmap color
robotgo.FindColor(color CHex, bitmap C.MMBitmapRef, tolerance float)
func FindColorCS ¶
FindColorCS findcolor by CaptureScreen
func FindIds ¶
FindIds finds the all processes named with a subset of "name" (case insensitive), return matched IDs.
func FindPic ¶
FindPic finding the image by path
robotgo.FindPic(path string, source_bitamp C.MMBitmapRef, tolerance float64)
This method only automatically free the internal bitmap, use `defer robotgo.FreeBitmap(bit)` to free the bitmap
func FreeBitmapArr ¶ added in v0.100.1
func FreeBitmapArr(bit ...C.MMBitmapRef)
FreeBitmapArr free and dealloc the C bitmap array
func FreeMMPointArr ¶ added in v0.93.0
func FreeMMPointArr(pointArray C.MMPointArrayRef)
FreeMMPointArr free MMPoint array
func GetBHandle
deprecated
func GetColor ¶
func GetColor(bitmap C.MMBitmapRef, x, y int) C.MMRGBHex
GetColor get the bitmap color
func GetColors ¶
func GetColors(bitmap C.MMBitmapRef, x, y int) string
GetColors get bitmap color retrun string
func GetHandPid ¶
GetHandPid get handle mdata by pid
func GetPixelColor ¶
GetPixelColor get the pixel color return string
func GetPortion ¶
func GetPortion(bit C.MMBitmapRef, x, y, w, h int) C.MMBitmapRef
GetPortion get bitmap portion
func GetPxColor ¶
GetPxColor get the pixel color return C.MMRGBHex
func GetTitle ¶
GetTitle get the window title return string
Examples:
fmt.Println(robotgo.GetTitle()) ids, _ := robotgo.FindIds() robotgo.GetTitle(ids[0])
func GetXidFromPid ¶
GetXidFromPid get the xide from pid
func KeyTap ¶
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 ¶
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 MouseClick
deprecated
func MouseClick(args ...interface{})
Deprecated: use the Click(),
MouseClick click the mouse ¶
robotgo.MouseClick(button string, double bool)
func MouseToggle
deprecated
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 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 MoveMouseSmooth
deprecated
func MoveSmooth ¶
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 OpenBitmap ¶
func OpenBitmap(gpath string, args ...int) C.MMBitmapRef
OpenBitmap open the bitmap return C.MMBitmapRef
robotgo.OpenBitmap(path string, type int)
func PasteStr ¶
PasteStr paste a string, support UTF-8, write the string to clipboard and tap `cmd + v`
func PointInBounds ¶
func PointInBounds(bitmap C.MMBitmapRef, x, y int) bool
PointInBounds bitmap point in bounds
func ReadBitmap ¶
func ReadBitmap(bitmap C.MMBitmapRef) bool
ReadBitmap returns false and sets error if |bitmap| is NULL
func SaveBitmap ¶
func SaveBitmap(bitmap C.MMBitmapRef, gpath string, args ...int) string
SaveBitmap save the bitmap to image
robotgo.SaveBimap(bitmap C.MMBitmapRef, path string, type int)
func SaveCapture ¶
SaveCapture capture screen and save
func Scroll ¶
Scroll scroll the mouse to (x, y)
robotgo.Scroll(x, y, msDelay int)
Examples:
robotgo.Scroll(10, 10)
func ScrollMouse
deprecated
func ScrollRelative ¶ added in v0.100.1
ScrollRelative scroll mouse with relative
Examples:
robotgo.ScrollRelative(10, 10)
func ScrollSmooth ¶ added in v0.100.7
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 SetHandlePid ¶
SetHandlePid set the window handle by pid
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 SetXDisplayName ¶
SetXDisplayName set XDisplay name (Linux)
func ShowAlert ¶
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 ToBitmapBytes ¶
func ToBitmapBytes(bit C.MMBitmapRef) []byte
ToBitmapBytes saves Bitmap to bitmap format in bytes
func ToImage ¶ added in v0.92.0
func ToImage(bit C.MMBitmapRef) image.Image
ToImage convert C.MMBitmapRef to standard image.Image
func ToMMBitmapRef ¶
func ToMMBitmapRef(bit CBitmap) C.MMBitmapRef
ToMMBitmapRef trans CBitmap to C.MMBitmapRef
func ToRGBA ¶ added in v0.99.9
func ToRGBA(bit C.MMBitmapRef) *image.RGBA
ToRGBA convert C.MMBitmapRef to standard image.RGBA
func ToStringImg ¶ added in v0.94.0
ToStringImg convert image.Image to string
func TocharBitmap ¶
func TocharBitmap(bit C.MMBitmapRef) *C.char
TocharBitmap tostring bitmap to C.char
func Toggle ¶ added in v0.100.7
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 TostringBitmap ¶
func TostringBitmap(bit C.MMBitmapRef) string
TostringBitmap tostring bitmap to string
func TypeStr ¶
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 TypeString
deprecated
func TypeStringDelayed
deprecated
Types ¶
type Bitmap ¶
type Bitmap struct { ImgBuf *uint8 Width, Height int Bytewidth int BitsPixel uint8 BytesPerPixel uint8 }
Bitmap is Bitmap struct
func GoCaptureScreen ¶
GoCaptureScreen capture the screen and return bitmap(go struct)
func ImgToBitmap ¶ added in v0.99.9
ImgToBitmap convert the standard image.Image to Bitmap
func RGBAToBitmap ¶ added in v0.99.9
RGBAToBitmap convert the standard image.RGBA to Bitmap
type Point ¶ added in v0.100.3
Point is point struct
func FindAllBitmap ¶ added in v0.100.9
func FindAllBitmap(bit C.MMBitmapRef, args ...interface{}) (posArr []Point)
FindAllBitmap find the all bitmap
func FindAllColor ¶ added in v0.100.9
FindAllColor find the all color
func FindEveryBitmap
deprecated
func FindEveryBitmap(bit C.MMBitmapRef, args ...interface{}) []Point
Deprecated: use the FindAllBitmap(),
FindEveryBitmap find the every bitmap, same with the FindAllBitmap()
func FindEveryColor
deprecated
added in
v0.93.0
type Rect ¶ added in v0.100.3
Rect is rect structure
func GetScreenRect ¶ added in v0.100.3
GetScreenRect get the screen rect (x, y, w, h)
Source Files
¶
Directories
¶
Path | Synopsis |
---|---|
Package clipboard read/write on clipboard
|
Package clipboard read/write on clipboard |
cmd
|
|