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:
import "github.com/go-vgo/robotgo"
Otherwise, to install the robotgo package, run the command:
go get -u github.com/go-vgo/robotgo
+bulid linux,next
+bulid windows,next
Index ¶
- Constants
- Variables
- func ActiveName(name string) error
- func ActivePid(pid int, args ...int) error
- func ActivePidC(pid int, args ...int) error
- func Alert(title, msg string, args ...string) bool
- func ByteToImg(b []byte) (image.Image, error)
- func Capture(args ...int) (*image.RGBA, error)
- func CaptureImg(args ...int) image.Image
- func CharCodeAt(s string, n int) rune
- func CheckMouse(btn string) C.MMMouseButton
- func Click(args ...interface{})
- func CloseWindow(args ...int)
- func CmdCtrl() string
- func DecodeImg(path string) (image.Image, string, error)
- func DisplaysNum() int
- func Drag(x, y int, args ...string)deprecated
- func DragMouse(x, y int, args ...interface{})deprecated
- func DragSmooth(x, y int, args ...interface{})
- func FindIds(name string) ([]int, error)
- func FindName(pid int) (string, error)
- func FindNames() ([]string, error)
- func FindPath(pid int) (string, error)
- func FreeBitmap(bitmap CBitmap)
- func FreeBitmapArr(bit ...CBitmap)
- func GetActive() C.MData
- func GetBHandle() intdeprecated
- func GetBounds(pid int, args ...int) (int, int, int, int)
- func GetClient(pid int, args ...int) (int, int, int, int)
- func GetDisplayBounds(i int) (x, y, w, h int)
- func GetHWNDByPid(pid int) int
- func GetHandPid(pid int, args ...int) C.MData
- func GetHandle() int
- func GetLocationColor(displayId ...int) string
- func GetMainId() int
- func GetMousePos() (int, int)deprecated
- func GetPid() int
- func GetPixelColor(x, y int, displayId ...int) string
- func GetPxColor(x, y int, displayId ...int) C.MMRGBHex
- func GetScaleSize(displayId ...int) (int, int)
- func GetScreenSize() (int, int)
- func GetText(imgPath string, args ...string) (string, error)
- func GetTitle(args ...int) string
- func GetVersion() string
- func GetXDisplayName() string
- func GetXid(xu *xgbutil.XUtil, pid int) (xproto.Window, error)
- func GetXidFromPid(xu *xgbutil.XUtil, pid int) (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 IsMain(displayId int) bool
- func IsValid() bool
- func KeyDown(key string, args ...interface{}) error
- func KeyPress(key string, args ...interface{}) error
- func KeyTap(key string, args ...interface{}) error
- func KeyToggle(key string, args ...interface{}) error
- func KeyUp(key string, args ...interface{}) error
- func Kill(pid int) error
- func Location() (int, int)
- func MaxWindow(pid int, args ...interface{})
- func MicroSleep(tm float64)deprecated
- func MilliSleep(tm int)
- func MinWindow(pid int, args ...interface{})
- func MouseClick(args ...interface{})deprecated
- func MouseDown(key ...interface{}) error
- func MouseUp(key ...interface{}) error
- func Move(x, y int, displayId ...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 MoveScale(x, y int, displayId ...int) (int, 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 OpenImg(path string) ([]byte, error)
- func PadHex(hex C.MMRGBHex) string
- func PadHexs(hex CHex) string
- func PasteStr(str string) error
- func PidExists(pid int) (bool, error)
- func Pids() ([]int, error)
- func Read(path string) (image.Image, error)
- func ReadAll() (string, error)
- func RgbToHex(r, g, b uint8) C.uint32_t
- func Run(path string) ([]byte, error)
- func Save(img image.Image, path string, quality ...int) error
- func SaveImg(b []byte, path string) error
- func SaveJpeg(img image.Image, path string, quality ...int) error
- func SavePng(img image.Image, path string) error
- func Scale0() intdeprecated
- func Scale1() intdeprecated
- func ScaleF(displayId ...int) float64
- func ScaleX() intdeprecated
- func Scaled(x int, displayId ...int) int
- func Scaled0(x int, f float64) int
- func Scaled1(x int, f float64) int
- func Scroll(x, y int, args ...int)
- func ScrollDir(x int, direction ...interface{})
- 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 int, args ...int)
- func SetXDisplayName(name string) error
- func Sleep(tm int)
- func StrToImg(data string) (image.Image, error)
- func SysScale(displayId ...int) float64
- func ToByteImg(img image.Image, fm ...string) []byte
- func ToImage(bit CBitmap) image.Image
- func ToInterfaces(fields []string) []interface{}
- func ToMMBitmapRef(bit CBitmap) C.MMBitmapRef
- func ToMMRGBHex(hex CHex) C.MMRGBHex
- func ToRGBA(bit CBitmap) *image.RGBA
- func ToRGBAGo(bmp1 Bitmap) *image.RGBA
- func ToStringImg(img image.Image, fm ...string) string
- func ToStrings(fields []interface{}) []string
- func ToUC(text string) []string
- func ToUint8p(dst []uint8) *uint8
- func Toggle(key ...interface{}) error
- func Try(fun func(), handler func(interface{}))
- func TypeStr(str string, args ...int)
- func TypeStrDelay(str string, delay int)
- 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, args ...int)
- 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 ( // KeyA define key "a" KeyA = "a" KeyB = "b" KeyC = "c" KeyD = "d" KeyE = "e" KeyF = "f" KeyG = "g" KeyH = "h" KeyI = "i" KeyJ = "j" KeyK = "k" KeyL = "l" KeyM = "m" KeyN = "n" KeyO = "o" KeyP = "p" KeyQ = "q" KeyR = "r" KeyS = "s" KeyT = "t" KeyU = "u" KeyV = "v" KeyW = "w" KeyX = "x" KeyY = "y" KeyZ = "z" // CapA = "A" CapB = "B" CapC = "C" CapD = "D" CapE = "E" CapF = "F" CapG = "G" CapH = "H" CapI = "I" CapJ = "J" CapK = "K" CapL = "L" CapM = "M" CapN = "N" CapO = "O" CapP = "P" CapQ = "Q" CapR = "R" CapS = "S" CapT = "T" CapU = "U" CapV = "V" CapW = "W" CapX = "X" CapY = "Y" CapZ = "Z" // Key0 = "0" Key1 = "1" Key2 = "2" Key3 = "3" Key4 = "4" Key5 = "5" Key6 = "6" Key7 = "7" Key8 = "8" Key9 = "9" // Backspace backspace key string Backspace = "backspace" Delete = "delete" Enter = "enter" Tab = "tab" Esc = "esc" Escape = "escape" Up = "up" // Up arrow key Down = "down" // Down arrow key Right = "right" // Right arrow key Left = "left" // Left arrow key Home = "home" End = "end" Pageup = "pageup" Pagedown = "pagedown" F1 = "f1" F2 = "f2" F3 = "f3" F4 = "f4" F5 = "f5" F6 = "f6" F7 = "f7" F8 = "f8" F9 = "f9" F10 = "f10" F11 = "f11" F12 = "f12" F13 = "f13" F14 = "f14" F15 = "f15" F16 = "f16" F17 = "f17" F18 = "f18" F19 = "f19" F20 = "f20" F21 = "f21" F22 = "f22" F23 = "f23" F24 = "f24" Cmd = "cmd" // is the "win" key for windows Lcmd = "lcmd" // left command Rcmd = "rcmd" // right command // "command" Alt = "alt" Lalt = "lalt" // left alt Ralt = "ralt" // right alt Ctrl = "ctrl" Lctrl = "lctrl" // left ctrl Rctrl = "rctrl" // right ctrl Control = "control" Shift = "shift" Lshift = "lshift" // left shift Rshift = "rshift" // right shift // "right_shift" Capslock = "capslock" Space = "space" Print = "print" Printscreen = "printscreen" // No Mac support Insert = "insert" Menu = "menu" // Windows only AudioMute = "audio_mute" // Mute the volume AudioVolDown = "audio_vol_down" // Lower the volume AudioVolUp = "audio_vol_up" // Increase the volume AudioPlay = "audio_play" AudioStop = "audio_stop" AudioPause = "audio_pause" AudioPrev = "audio_prev" // Previous Track AudioNext = "audio_next" // Next Track AudioRewind = "audio_rewind" // Linux only AudioForward = "audio_forward" // Linux only AudioRepeat = "audio_repeat" // Linux only AudioRandom = "audio_random" // Linux only Num0 = "num0" // numpad 0 Num1 = "num1" Num2 = "num2" Num3 = "num3" Num4 = "num4" Num5 = "num5" Num6 = "num6" Num7 = "num7" Num8 = "num8" Num9 = "num9" NumLock = "num_lock" NumDecimal = "num." NumPlus = "num+" NumMinus = "num-" NumMul = "num*" NumDiv = "num/" NumClear = "num_clear" NumEnter = "num_enter" NumEqual = "num_equal" LightsMonUp = "lights_mon_up" // Turn up monitor brightness No Windows support LightsMonDown = "lights_mon_down" // Turn down monitor brightness No Windows support LightsKbdToggle = "lights_kbd_toggle" // Toggle keyboard backlight on/off No Windows support LightsKbdUp = "lights_kbd_up" // Turn up keyboard backlight brightness No Windows support LightsKbdDown = "lights_kbd_down" )
Defining a bunch of constants.
const ( // Mleft mouse left button Mleft = "left" Mright = "right" Center = "center" WheelDown = "wheelDown" WheelUp = "wheelUp" WheelLeft = "wheelLeft" WheelRight = "wheelRight" )
const (
// Version get the robotgo version
Version = "v1.00.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 // DisplayID set the screen display id DisplayID = -1 // NotPid used the hwnd not pid in windows NotPid bool // Scale option the os screen scale Scale bool )
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 Alert ¶
Alert show a alert window Displays alert with the attributes. If cancel button is not given, only the default button is displayed
Examples:
robotgo.Alert("hi", "window", "ok", "cancel")
func CaptureImg ¶
CaptureImg capture the screen and return image.Image
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 CmdCtrl ¶
func CmdCtrl() string
CmdCtrl If the operating system is macOS, return the key string "cmd", otherwise return the key string "ctrl
func DragSmooth ¶
func DragSmooth(x, y int, args ...interface{})
DragSmooth drag the mouse like smooth to (x, y)
Examples:
robotgo.DragSmooth(10, 10)
func FindIds ¶
FindIds finds the all processes named with a subset of "name" (case insensitive), return matched IDs.
func FreeBitmapArr ¶
func FreeBitmapArr(bit ...CBitmap)
FreeBitmapArr free and dealloc the C bitmap array
func GetBHandle
deprecated
func GetDisplayBounds ¶
GetScreenBound gets the display screen bounds
func GetLocationColor ¶
GetLocationColor get the location pos's color
func GetMousePos
deprecated
func GetPixelColor ¶
GetPixelColor get the pixel color return string
func GetPxColor ¶
GetPxColor get the pixel color return C.MMRGBHex
func GetScaleSize ¶
GetScaleSize get the screen scale size
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 xid from pid
func KeyTap ¶
KeyTap taps the keyboard code;
See keys supported:
https://github.com/go-vgo/robotgo/blob/master/docs/keys.md#keys
Examples:
robotgo.KeySleep = 100 // 100 millisecond robotgo.KeyTap("a") robotgo.KeyTap("i", "alt", "command") arr := []string{"alt", "command"} robotgo.KeyTap("i", arr) robotgo.KeyTap("k", pid int)
func KeyToggle ¶
KeyToggle toggles the keyboard, if there not have args default is "down"
See keys:
https://github.com/go-vgo/robotgo/blob/master/docs/keys.md#keys
Examples:
robotgo.KeyToggle("a") robotgo.KeyToggle("a", "up") robotgo.KeyToggle("a", "up", "alt", "cmd") robotgo.KeyToggle("k", pid int)
func MicroSleep
deprecated
func MouseClick
deprecated
func MouseClick(args ...interface{})
Deprecated: use the Click(),
MouseClick click the mouse ¶
robotgo.MouseClick(button string, double bool)
func Move ¶
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 PasteStr ¶
PasteStr paste a string (support UTF-8), write the string to clipboard and tap `cmd + v`
func Scroll ¶
Scroll scroll the mouse to (x, y)
robotgo.Scroll(x, y, msDelay int)
Examples:
robotgo.Scroll(10, 10)
func ScrollDir ¶
func ScrollDir(x int, direction ...interface{})
ScrollDir scroll the mouse with direction to (x, "up") supported: "up", "down", "left", "right"
Examples:
robotgo.ScrollDir(10, "down") robotgo.ScrollDir(10, "up")
func ScrollRelative ¶
ScrollRelative scroll mouse with relative
Examples:
robotgo.ScrollRelative(10, 10)
func ScrollSmooth ¶
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 SetDelay ¶
func SetDelay(d ...int)
SetDelay sets the key and mouse delay robotgo.SetDelay(100) option the robotgo.KeySleep and robotgo.MouseSleep = d
func SetHandlePid ¶
SetHandlePid set the window handle by pid
func SetXDisplayName ¶
SetXDisplayName set XDisplay name (Linux)
func ToInterfaces ¶
func ToInterfaces(fields []string) []interface{}
ToInterfaces convert []string to []interface{}
func ToMMBitmapRef ¶
func ToMMBitmapRef(bit CBitmap) C.MMBitmapRef
ToMMBitmapRef trans CBitmap to C.MMBitmapRef
func ToStringImg ¶
ToStringImg convert image.Image to string
func ToStrings ¶
func ToStrings(fields []interface{}) []string
ToStrings convert []interface{} to []string
func Toggle ¶
func Toggle(key ...interface{}) error
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 TypeStr ¶
TypeStr send a string (supported UTF-8)
robotgo.TypeStr(string: "The string to send", int: pid, "milli_sleep time", "x11 option")
Examples:
robotgo.TypeStr("abc@123, Hi galaxy, こんにちは") robotgo.TypeStr("To be or not to be, this is questions.", pid int)
func TypeStrDelay ¶
TypeStrDelay type string with delayed And you can use robotgo.KeySleep = 100 to delayed not this function
func TypeStringDelayed
deprecated
Types ¶
type Bitmap ¶
type Bitmap struct { ImgBuf *uint8 Width, Height int Bytewidth int BitsPixel uint8 BytesPerPixel uint8 }
Bitmap define the go Bitmap struct
The common type conversion of bitmap:
https://github.com/go-vgo/robotgo/blob/master/docs/keys.md#type-conversion
func ImgToBitmap ¶
ImgToBitmap convert the standard image.Image to Bitmap
func RGBAToBitmap ¶
RGBAToBitmap convert the standard image.RGBA to Bitmap
type CBitmap ¶
type CBitmap C.MMBitmapRef
CBitmap define CBitmap as C.MMBitmapRef type
func CaptureScreen ¶
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 ImgToCBitmap ¶
ImgToCBitmap trans image.Image to CBitmap
type Rect ¶
Rect is rect structure
func GetScreenRect ¶
GetScreenRect get the screen rect (x, y, w, h)