robotgo: Index | Files | Directories

package robotgo

import ""

Package robotgo Go native cross-platform system automation.

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

See Requirements:


go get -u


Package Files

hook.go keycode.go ps.go robotgo.go robotgo_adb.go robotgo_unix.go


const (
    // Version get the robotgo version
    Version = "v0.91.0.1089, MT. Rainier!"


var Keycode = uMap{
    "`": 41,
    "1": 2,
    "2": 3,
    "3": 4,
    "4": 5,
    "5": 6,
    "6": 7,
    "7": 8,
    "8": 9,
    "9": 10,
    "0": 11,
    "-": 12,
    "+": 13,

    "q":  16,
    "w":  17,
    "e":  18,
    "r":  19,
    "t":  20,
    "y":  21,
    "u":  22,
    "i":  23,
    "o":  24,
    "p":  25,
    "[":  26,
    "]":  27,
    "\\": 43,

    "a": 30,
    "s": 31,
    "d": 32,
    "f": 33,
    "g": 34,
    "h": 35,
    "j": 36,
    "k": 37,
    "l": 38,
    ";": 39,
    "'": 40,

    "z": 44,
    "x": 45,
    "c": 46,
    "v": 47,
    "b": 48,
    "n": 49,
    "m": 50,
    ",": 51,
    ".": 52,
    "/": 53,

    "f1":  59,
    "f2":  60,
    "f3":  61,
    "f4":  62,
    "f5":  63,
    "f6":  64,
    "f7":  65,
    "f8":  66,
    "f9":  67,
    "f10": 68,
    "f11": 69,
    "f12": 70,

    "esc":     1,
    "delete":  14,
    "tab":     15,
    "ctrl":    29,
    "control": 29,
    "alt":     56,
    "space":   57,
    "shift":   42,
    "rshift":  54,
    "enter":   28,

    "cmd":     3675,
    "command": 3675,
    "rcmd":    3676,
    "ralt":    3640,

    "up":    57416,
    "down":  57424,
    "left":  57419,
    "right": 57421,

Keycode robotgo hook key's code map

var MouseMap = uMap{
    "left":       1,
    "right":      2,
    "center":     3,
    "wheelDown":  4,
    "wheelUp":    5,
    "wheelLeft":  6,
    "wheelRight": 7,

MouseMap robotgo hook mouse's code map

func ActiveName Uses

func ActiveName(name string) error

ActiveName active window by name

func ActivePID Uses

func ActivePID(pid int32, args 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 Uses

func ActivePIDC(pid int32, args error

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

func AddEvent Uses

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 Uses

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 Uses

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 Uses

func AddMousePos(x, y int16) bool

AddMousePos add listen mouse event pos hook

func BitmapClick Uses

func BitmapClick(bitmap C.MMBitmapRef, args ...interface{})

BitmapClick find the bitmap and click

func BitmapFromStr Uses

func BitmapFromStr(str string) C.MMBitmapRef

BitmapFromStr bitmap from string

func BitmapStr Uses

func BitmapStr(str string) C.MMBitmapRef

BitmapStr bitmap from string

func CaptureScreen Uses

func CaptureScreen(args 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 Uses

func CharCodeAt(s string, n int) rune

CharCodeAt char code at utf-8

func CheckMouse Uses

func CheckMouse(btn string) C.MMMouseButton

CheckMouse check the mouse button

func Click Uses

func Click(args ...interface{})

Click click the mouse

robotgo.Click(button string, double bool)

func CloseWindow Uses

func CloseWindow(args ...int32)

CloseWindow close the window

func Convert Uses

func Convert(opath, spath string, args

Convert convert the bitmap

robotgo.Convert(opath, spath string, type int)

func CopyBitPB Uses

func CopyBitPB(bitmap C.MMBitmapRef) bool

CopyBitPB copy bitmap to pasteboard

func CopyBitpb Uses

func CopyBitpb(bitmap C.MMBitmapRef) bool

CopyBitpb copy bitmap to pasteboard, Wno-deprecated

func CountBitmap Uses

func CountBitmap(bitmap, sbit C.MMBitmapRef, args ...float32) int

CountBitmap count of the bitmap

func CountColor Uses

func CountColor(color CHex, args ...interface{}) int

CountColor count bitmap color

func CountColorCS Uses

func CountColorCS(color CHex, x, y, w, h int, args ...float64) int

CountColorCS count bitmap color by CaptureScreen

func DecodeImg Uses

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

DecodeImg decode the image to image.Image and return

func DeepCopyBit Uses

func DeepCopyBit(bitmap C.MMBitmapRef) C.MMBitmapRef

DeepCopyBit deep copy bitmap

func Drag Uses

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

Drag drag the mouse

func DragMouse Uses

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

DragMouse drag the mouse

func DragSmooth Uses

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

DragSmooth drag the mouse smooth

func End Uses

func End()

End removes global event hook

func EventEnd Uses

func EventEnd()

EventEnd removes global event hook

func EventHook Uses

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

EventHook register gohook event

func EventProcess Uses

func EventProcess(events chan hook.Event) chan bool

EventProcess return go hook process

func EventStart Uses

func EventStart() chan hook.Event

EventStart start global event hook return event channel

func FindBitmap Uses

func FindBitmap(bit C.MMBitmapRef, args ...interface{}) (int, int)

FindBitmap find the bitmap's pos

	robotgo.FindBitmap(bitmap, subbitamp 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 Uses

func FindCBitmap(bmp CBitmap, args ...interface{}) (int, int)

FindCBitmap find bitmap's pos by CBitmap

func FindColor Uses

func FindColor(color CHex, args ...interface{}) (int, int)

FindColor find bitmap color

robotgo.FindColor(color CHex, bitmap C.MMBitmapRef, tolerance float)

func FindColorCS Uses

func FindColorCS(color CHex, x, y, w, h int, args ...float64) (int, int)

FindColorCS findcolor by CaptureScreen

func FindEveryBitmap Uses

func FindEveryBitmap(bit C.MMBitmapRef, args ...interface{}) (int, int)

FindEveryBitmap find the every bitmap

func FindIds Uses

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

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

func FindName Uses

func FindName(pid int32) (string, error)

FindName find the process name by the process id

func FindNames Uses

func FindNames() ([]string, error)

FindNames find the all process name

func FindPath Uses

func FindPath(pid int32) (string, error)

FindPath find the process path by the process pid

func FindPic Uses

func FindPic(path string, args ...interface{}) (int, int)

FindPic finding the image by path

robotgo.FindPic(path string, subbitamp C.MMBitmapRef, tolerance float64)

This method only automatically free the internal bitmap, use `defer robotgo.FreeBitmap(bit)` to free the bitmap

func FreeBitmap Uses

func FreeBitmap(bitmap C.MMBitmapRef)

FreeBitmap free and dealloc bitmap

func GetActive Uses

func GetActive() C.MData

GetActive get the active window

func GetBHandle Uses

func GetBHandle() int

GetBHandle get the window handle, Wno-deprecated

func GetBounds Uses

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

GetBounds get the window bounds

func GetColor Uses

func GetColor(bitmap C.MMBitmapRef, x, y int) C.MMRGBHex

GetColor get bitmap color

func GetColors Uses

func GetColors(bitmap C.MMBitmapRef, x, y int) string

GetColors get bitmap color retrun string

func GetHandPid Uses

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

GetHandPid get handle mdata by pid

func GetHandle Uses

func GetHandle() int

GetHandle get the window handle

func GetImgSize Uses

func GetImgSize(imgPath string) (int, int)

GetImgSize get the image size

func GetMouseColor Uses

func GetMouseColor() string

GetMouseColor get the mouse pos's color

func GetMousePos Uses

func GetMousePos() (int, int)

GetMousePos get mouse's portion

func GetPID Uses

func GetPID() int32

GetPID get the process id

func GetPixelColor Uses

func GetPixelColor(x, y int) string

GetPixelColor get pixel color return string

func GetPortion Uses

func GetPortion(bit C.MMBitmapRef, x, y, w, h int) C.MMBitmapRef

GetPortion get bitmap portion

func GetPxColor Uses

func GetPxColor(x, y int) C.MMRGBHex

GetPxColor get pixel color return C.MMRGBHex

func GetScaleSize Uses

func GetScaleSize() (int, int)

GetScaleSize get the screen scale size

func GetScreenSize Uses

func GetScreenSize() (int, int)

GetScreenSize get the screen size

func GetText Uses

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

GetText get the image text by tesseract ocr

robotgo.GetText(imgPath, lang string)

func GetTitle Uses

func GetTitle(args ...int32) string

GetTitle get the window title

func GetVersion Uses

func GetVersion() string

GetVersion get the robotgo version

func GetXDisplayName Uses

func GetXDisplayName() string

GetXDisplayName get XDisplay name (Linux)

func GetXId Uses

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

GetXId get the xid return window and error

func GetXidFromPid Uses

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

GetXidFromPid get the xide from pid

func GoString Uses

func GoString(char *C.char) string

GoString teans C.char to string

func HexToRgb Uses

func HexToRgb(hex uint32) *C.uint8_t

HexToRgb trans hex to rgb

func Is64Bit Uses

func Is64Bit() bool

Is64Bit determine whether the sys is 64bit

func IsValid Uses

func IsValid() bool

IsValid valid the window

func KeyTap Uses

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

KeyTap tap the keyboard code;

See keys:

func KeyToggle Uses

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

KeyToggle toggle the keyboard

See keys:

func Kill Uses

func Kill(pid int32) error

Kill kill the process by PID

func MaxWindow Uses

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

MaxWindow set the window max

func MicroSleep Uses

func MicroSleep(tm float64)

MicroSleep time C.microsleep(tm)

func MilliSleep Uses

func MilliSleep(tm int)

MilliSleep sleep tm milli second

func MinWindow Uses

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

MinWindow set the window min

func MouseClick Uses

func MouseClick(args ...interface{})

MouseClick click the mouse

robotgo.MouseClick(button string, double bool)

func MouseToggle Uses

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

MouseToggle toggle the mouse

func Move Uses

func Move(x, y int)

Move move the mouse

func MoveArgs Uses

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

MoveArgs move mose relative args

func MoveClick Uses

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

MoveClick move and click the mouse

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

func MoveMouse Uses

func MoveMouse(x, y int)

MoveMouse move the mouse

func MoveMouseSmooth Uses

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

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

func MoveRelative Uses

func MoveRelative(x, y int)

MoveRelative move mose relative

func MoveSmooth Uses

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)

func MoveSmoothRelative Uses

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

MoveSmoothRelative move mose smooth relative

func MovesClick Uses

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

MovesClick move smooth and click the mouse

func Mul Uses

func Mul(x int) int

Mul mul the scale

func OpenBitmap Uses

func OpenBitmap(gpath string, args C.MMBitmapRef

OpenBitmap open the bitmap return C.MMBitmapRef

robotgo.OpenBitmap(path string, type int)

func OpenImg Uses

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

OpenImg open the image return []byte

func PadHex Uses

func PadHex(hex C.MMRGBHex) string

PadHex trans C.MMRGBHex to string

func PasteStr Uses

func PasteStr(str string) string

PasteStr paste a string, support UTF-8

func PidExists Uses

func PidExists(pid int32) (bool, error)

PidExists determine whether the process exists

func Pids Uses

func Pids() ([]int32, error)

Pids get the all process id

func PointInBounds Uses

func PointInBounds(bitmap C.MMBitmapRef, x, y int) bool

PointInBounds bitmap point in bounds

func ReadAll Uses

func ReadAll() (string, error)

ReadAll read string from clipboard

func ReadBitmap Uses

func ReadBitmap(bitmap C.MMBitmapRef) bool

ReadBitmap returns false and sets error if |bitmap| is NULL

func RgbToHex Uses

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

RgbToHex trans rgb to hex

func SaveBitmap Uses

func SaveBitmap(bitmap C.MMBitmapRef, gpath string, args string

SaveBitmap save the bitmap to image

robotgo.SaveBimap(bitmap C.MMBitmapRef, path string, type int)

func SaveCapture Uses

func SaveCapture(spath string, args

SaveCapture capture screen and save

func SaveImg Uses

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

SaveImg save the image by []byte

func SavePng Uses

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

SavePng save the image by image.Image

func Scale Uses

func Scale() int

Scale get the screen scale

func ScaleX Uses

func ScaleX() int

ScaleX get primary display horizontal DPI scale factor

func ScaleY Uses

func ScaleY() int

ScaleY get primary display vertical DPI scale factor

func Scaled Uses

func Scaled(x int) int

Scaled x * sys-scale

func Scroll Uses

func Scroll(x, y int, args

Scroll scroll the mouse with x, y

robotgo.Scroll(x, y, msDelay int)

func ScrollMouse Uses

func ScrollMouse(x int, direction string)

ScrollMouse scroll the mouse

func SetActive Uses

func SetActive(win C.MData)

SetActive set the window active

func SetDelay Uses

func SetDelay(d

SetDelay set the key and mouse delay

func SetHandle Uses

func SetHandle(hwnd int)

SetHandle set the window handle

func SetHandlePid Uses

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

SetHandlePid set the window handle by pid

func SetKeyDelay Uses

func SetKeyDelay(delay int)

SetKeyDelay set keyboard delay

func SetKeyboardDelay Uses

func SetKeyboardDelay(delay int)

SetKeyboardDelay set keyboard delay, Wno-deprecated, this function will be removed in version v1.0.0

func SetMouseDelay Uses

func SetMouseDelay(delay int)

SetMouseDelay set mouse delay

func SetXDisplayName Uses

func SetXDisplayName(name string) string

SetXDisplayName set XDisplay name (Linux)

func ShowAlert Uses

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

ShowAlert show a alert window

func Sleep Uses

func Sleep(tm int)

Sleep time.Sleep tm second

func Start Uses

func Start() chan hook.Event

Start start global event hook return event channel

func StopEvent Uses

func StopEvent()

StopEvent stop event listener

func SysScale Uses

func SysScale() float64

SysScale get the sys scale

func ToBitmapBytes Uses

func ToBitmapBytes(bit C.MMBitmapRef) []byte

ToBitmapBytes saves Bitmap to bitmap format in bytes

func ToCBitmap Uses

func ToCBitmap(bit Bitmap) C.MMBitmapRef

ToCBitmap trans Bitmap to C.MMBitmapRef

func ToImage Uses

func ToImage(bit C.MMBitmapRef) image.Image

ToImage convert C.MMBitmapRef to standard image.Image

func ToMMBitmapRef Uses

func ToMMBitmapRef(bit CBitmap) C.MMBitmapRef

ToMMBitmapRef trans CBitmap to C.MMBitmapRef

func ToMMRGBHex Uses

func ToMMRGBHex(hex CHex) C.MMRGBHex

ToMMRGBHex trans CHex to C.MMRGBHex

func TocharBitmap Uses

func TocharBitmap(bit C.MMBitmapRef) *C.char

TocharBitmap tostring bitmap to C.char

func TostringBitmap Uses

func TostringBitmap(bit C.MMBitmapRef) string

TostringBitmap tostring bitmap to string

func Try Uses

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

Try handler(err)

func TypeStr Uses

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

TypeStr send a string, support UTF-8

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

func TypeStrDelay Uses

func TypeStrDelay(str string, delay int)

TypeStrDelay type string delayed

func TypeString Uses

func TypeString(str string, delay

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

func TypeStringDelayed Uses

func TypeStringDelayed(str string, delay int)

TypeStringDelayed type string delayed, Wno-deprecated

func U32ToHex Uses

func U32ToHex(hex C.uint32_t) C.MMRGBHex

U32ToHex trans C.uint32_t to C.MMRGBHex

func U8ToHex Uses

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

U8ToHex teans *C.uint8_t to C.MMRGBHex

func UnicodeType Uses

func UnicodeType(str uint32)

UnicodeType tap uint32 unicode

func WriteAll Uses

func WriteAll(text string) error

WriteAll write string to clipboard

type Bitmap Uses

type Bitmap struct {
    ImgBuf        *uint8
    Width, Height int

    Bytewidth     int
    BitsPixel     uint8
    BytesPerPixel uint8

Bitmap is Bitmap struct

func GoCaptureScreen Uses

func GoCaptureScreen(args Bitmap

GoCaptureScreen capture the screen and return bitmap(go struct)

func ToBitmap Uses

func ToBitmap(bit C.MMBitmapRef) Bitmap

ToBitmap trans C.MMBitmapRef to Bitmap

type CBitmap Uses

type CBitmap C.MMBitmapRef

CBitmap define CBitmap as C.MMBitmapRef type

type CHex Uses

type CHex C.MMRGBHex

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

func UintToHex Uses

func UintToHex(u uint32) CHex

UintToHex trans uint32 to robotgo.CHex

type MPoint Uses

type MPoint struct {
    // contains filtered or unexported fields

MPoint is MPoint struct

type Map Uses

type Map map[string]interface{}

Map a map[string]interface{}

type Nps Uses

type Nps struct {
    Pid  int32
    Name string

Nps process struct

func Process Uses

func Process() ([]Nps, error)

Process get the all process struct


clipboardPackage clipboard read/write on clipboard

Package robotgo imports 20 packages (graph) and is imported by 80 packages. Updated 2020-11-18. Refresh now. Tools for package owners.