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
- 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 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 DecodeImg(path string) (image.Image, string, error)
- 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 FindIds(name string) ([]int32, error)
- func FindName(pid int32) (string, error)
- func FindNames() ([]string, error)
- func FindPath(pid int32) (string, error)
- func FreeBitmap(bitmap C.MMBitmapRef)
- func GetActive() C.MData
- func GetBHandle() intdeprecated
- func GetBounds(pid int32, args ...int) (int, int, int, int)
- func GetHandPid(pid int32, args ...int32) C.MData
- func GetHandle() int
- func GetMouseColor() string
- func GetMousePos() (int, int)
- func GetPID() int32
- func GetPixelColor(x, y int) string
- 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 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 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) error
- 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 ToByteImg(img image.Image, fm ...string) []byte
- func ToImage(bit C.MMBitmapRef) image.Image
- 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 Toggle(key ...string) int
- 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 CaptureImg ¶
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 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 FindIds ¶
FindIds finds the all processes named with a subset of "name" (case insensitive), return matched IDs.
func GetBHandle
deprecated
func GetHandPid ¶
GetHandPid get handle mdata by pid
func GetPixelColor ¶
GetPixelColor get the pixel color return string
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 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 ScrollMouse
deprecated
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 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 ToImage ¶
func ToImage(bit C.MMBitmapRef) image.Image
ToImage convert C.MMBitmapRef to standard image.Image
func ToRGBA ¶
func ToRGBA(bit C.MMBitmapRef) *image.RGBA
ToRGBA convert C.MMBitmapRef to standard image.RGBA
func ToStringImg ¶
ToStringImg convert image.Image to string
func Toggle ¶
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, 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 ¶
ImgToBitmap convert the standard image.Image to Bitmap
func RGBAToBitmap ¶
RGBAToBitmap convert the standard image.RGBA to Bitmap
type Rect ¶
Rect is rect structure
func GetScreenRect ¶
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
|
|