robotgo

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2026 License: Apache-2.0 Imports: 28 Imported by: 0

README

Robotgo (Fork)

This is a fork of go-vgo/robotgo maintained at shaolei/robotgo.

Module path: github.com/shaolei/robotgo (NOT github.com/go-vgo/robotgo)

Go Report Card GoDoc GitHub release

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

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


Version & Compatibility

Current Version: v1.0.0

This fork is based on the upstream go-vgo/robotgo but introduces breaking changes that are incompatible with the upstream API. If you are migrating from the upstream version, please read the following carefully.

Key Differences from Upstream
Feature Upstream (go-vgo/robotgo) This Fork (shaolei/robotgo)
Build System CGo (requires C compiler: GCC/MinGW) Pure Go (syscall + purego, no C compiler needed)
Module Path github.com/go-vgo/robotgo github.com/shaolei/robotgo
Keycode Type uint16 uint32 (supports X11 XF86 multimedia keys > 0xFFFF)
Wheel Constants WheelDown, WheelUp, WheelLeft, WheelRight WHEEL_DOWN, WHEEL_UP, WHEEL_LEFT, WHEEL_RIGHT
Color Type Custom colorRGBA struct Standard image/color.RGBA
Platform Files robotgo_mac.go, robotgo_win.go, robotgo_x11.go (CGo) robotgo_darwin.go, robotgo_windows.go, robotgo_linux.go (pure Go)
Bitmap Memory unsafe.Pointer arithmetic unsafe.Slice (Go 1.17+)
Requirements GCC + CGo enabled Go only (no GCC/CGo required)
Breaking Changes (Migration Required)

If you are migrating from github.com/go-vgo/robotgo, you MUST update your code:

1. Change Import Path
// Before
import "github.com/go-vgo/robotgo"

// After
import "github.com/shaolei/robotgo"
2. Keycode Type Change (uint16 → uint32)
// Before
var code uint16 = robotgo.K_Enter

// After
var code uint32 = robotgo.K_Enter

This change was necessary because X11 KeySym values for XF86 multimedia keys (e.g., 0x1008FF12 for XF86AudioMute) exceed the uint16 range (max 0xFFFF).

3. Wheel Constant Names
// Before
robotgo.CheckMouse(robotgo.WheelDown, ...)

// After
robotgo.CheckMouse(robotgo.WHEEL_DOWN, ...)
4. No C Compiler Required

This fork eliminates the CGo dependency entirely:

  • Windows: Uses golang.org/x/sys/windows syscall
  • macOS: Uses github.com/ebitengine/purego for dynamic library loading
  • Linux: Uses X11/XCB Go bindings (github.com/jezek/xgb)

You no longer need GCC, MinGW, or Xcode Command Line Tools to build this library.

What Remains Compatible

The following APIs are fully compatible with the upstream version (no code changes needed beyond import path):

  • Mouse control: Move, Click, Toggle, Scroll, DragSmooth, MoveSmooth
  • Keyboard control: KeyTap, KeyToggle, Type, UnicodeType
  • Screen capture: CaptureScreen, CaptureImg, GetPixelColor, GetScreenSize
  • Bitmap operations: ToImage, Save, FreeBitmap
  • Clipboard: ReadAll, WriteAll
  • Process management: FindIds, ActivePid, Kill, PidExists
  • Window handle: GetTitle, GetHandle, SetActive, MinWindow, MaxWindow, CloseWindow
Not Yet Implemented

The following features from upstream are not yet available in this fork:

  • Global event hook (gohook integration) — requires CGo, not yet ported
  • Bitmap find (bitmap.Find) — requires the vcaesar/bitmap CGo library
  • OCR (GetText) — available but requires gosseract CGo binding and tesseract

Contents

Docs

Requirements:

This fork requires only Go (1.21+). No C compiler is needed.

ALL:
Golang 1.21+
For MacOS:
brew install go

Privacy setting: add Screen Recording and Accessibility under: System Settings > Privacy & Security > Accessibility, Screen & System Audio Recording.

For Windows:
winget install Golang.go

No MinGW or GCC required. This fork uses pure Go syscall.

For Linux:
# Go
sudo snap install go --classic

# X11 (required for keyboard/mouse/screen control)
sudo apt install libx11-dev xorg-dev libxtst-dev

# Clipboard
sudo apt install xsel xclip

Installation:

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

import "github.com/shaolei/robotgo"

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

go get github.com/shaolei/robotgo

Update:

go get -u github.com/shaolei/robotgo

Examples:

Mouse
package main

import (
  "fmt"
  "github.com/shaolei/robotgo"
)

func main() {
  robotgo.MouseSleep = 300

  robotgo.Move(100, 100)
  fmt.Println(robotgo.Location())
  robotgo.Move(100, -200) // multi screen supported
  robotgo.MoveSmooth(120, -150)
  fmt.Println(robotgo.Location())

  robotgo.ScrollDir(10, "up")
  robotgo.ScrollDir(20, "right")

  robotgo.Scroll(0, -10)
  robotgo.Scroll(100, 0)

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

  robotgo.Move(10, 20)
  robotgo.MoveRelative(0, -10)
  robotgo.DragSmooth(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/shaolei/robotgo"
)

func main() {
  robotgo.Type("Hello World")
  robotgo.Type("だんしゃり", 0, 1)

  robotgo.KeySleep = 100
  robotgo.KeyTap("enter")
  robotgo.KeyTap("i", "alt", "cmd")

  arr := []string{"alt", "cmd"}
  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"
  "strconv"

  "github.com/shaolei/robotgo"
)

func main() {
  x, y := robotgo.Location()
  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)

  img := robotgo.ToImage(bit)
  robotgo.Save(img, "test.png")

  num := robotgo.DisplaysNum()
  for i := 0; i < num; i++ {
    robotgo.DisplayID = i
    img1, _ := robotgo.CaptureImg()
    path1 := "save_" + strconv.Itoa(i)
    robotgo.Save(img1, path1+".png")
    robotgo.SaveJpeg(img1, path1+".jpeg", 50)

    img2, _ := robotgo.CaptureImg(10, 10, 20, 20)
    robotgo.Save(img2, "test_"+strconv.Itoa(i)+".png")

    x, y, w, h := robotgo.GetDisplayBounds(i)
    img3, err := robotgo.CaptureImg(x, y, w, h)
    fmt.Println("Capture error: ", err)
    robotgo.Save(img3, path1+"_1.png")
  }
}
Window
package main

import (
  "fmt"

  "github.com/shaolei/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.Alert("test", "robotgo")
  if abool {
    fmt.Println("ok@@@ ", "ok")
  }

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

Authors

Upstream Reference

  • Original repository: go-vgo/robotgo
  • RobotGo-Pro — JavaScript, Python, Lua versions, tech support, and newest features (Wayland support, etc.)

License

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

See LICENSE-APACHE, LICENSE.

Documentation

Overview

Package robotgo Go native cross-platform system automation.

No C compiler is required — all platform APIs are called via purego/syscall.

Installation:

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

import "github.com/shaolei/robotgo"

+bulid linux,next

+bulid windows,next

Index

Constants

View Source
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"
	KeyGrave  = "`"
	KeyQuoter = '"'
	KeyQuote  = "'"

	// 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
	Alt         = "alt"
	Lalt        = "lalt"
	Ralt        = "ralt"
	Ctrl        = "ctrl"
	Lctrl       = "lctrl"
	Rctrl       = "rctrl"
	Control     = "control"
	Shift       = "shift"
	Lshift      = "lshift"
	Rshift      = "rshift"
	Capslock    = "capslock"
	Space       = "space"
	Print       = "print"
	Printscreen = "printscreen"
	Insert      = "insert"
	Menu        = "menu"

	AudioMute    = "audio_mute"
	AudioVolDown = "audio_vol_down"
	AudioVolUp   = "audio_vol_up"
	AudioPlay    = "audio_play"
	AudioStop    = "audio_stop"
	AudioPause   = "audio_pause"
	AudioPrev    = "audio_prev"
	AudioNext    = "audio_next"
	AudioRewind  = "audio_rewind"
	AudioForward = "audio_forward"
	AudioRepeat  = "audio_repeat"
	AudioRandom  = "audio_random"

	Num0    = "num0"
	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"
	LightsMonDown   = "lights_mon_down"
	LightsKbdToggle = "lights_kbd_toggle"
	LightsKbdUp     = "lights_kbd_up"
	LightsKbdDown   = "lights_kbd_down"
)

Defining a bunch of constants.

View Source
const (
	// Mleft mouse left button
	Mleft      = "left"
	Mright     = "right"
	Center     = "center"
	WheelDown  = "wheelDown"
	WheelUp    = "wheelUp"
	WheelLeft  = "wheelLeft"
	WheelRight = "wheelRight"
)
View Source
const (
	LEFT_BUTTON   uint16 = 0
	RIGHT_BUTTON  uint16 = 1
	CENTER_BUTTON uint16 = 2
	WHEEL_DOWN    uint16 = 3
	WHEEL_UP      uint16 = 4
	WHEEL_LEFT    uint16 = 5
	WHEEL_RIGHT   uint16 = 6
)

Mouse button constants (replacing C.MMMouseButton)

View Source
const (
	MOD_NONE    uint64 = 0
	MOD_ALT     uint64 = 0x08 // Mod1Mask
	MOD_CONTROL uint64 = 0x04 // ControlMask
	MOD_SHIFT   uint64 = 0x01 // ShiftMask
	MOD_META    uint64 = 0x40 // Mod4Mask
)

Key modifier flags (replacing C.MMKeyFlags / C.MOD_*)

View Source
const (
	K_NOT_A_KEY         uint32 = 0xFF
	K_BACKSPACE         uint32 = 0x16   // XK_BackSpace
	K_DELETE            uint32 = 0xFFFF // XK_Delete
	K_RETURN            uint32 = 0xFF0D // XK_Return
	K_TAB               uint32 = 0xFF09 // XK_Tab
	K_ESCAPE            uint32 = 0xFF1B // XK_Escape
	K_UP                uint32 = 0xFF52 // XK_Up
	K_DOWN              uint32 = 0xFF54 // XK_Down
	K_RIGHT             uint32 = 0xFF53 // XK_Right
	K_LEFT              uint32 = 0xFF51 // XK_Left
	K_HOME              uint32 = 0xFF50 // XK_Home
	K_END               uint32 = 0xFF57 // XK_End
	K_PAGEUP            uint32 = 0xFF55 // XK_Page_Up
	K_PAGEDOWN          uint32 = 0xFF56 // XK_Page_Down
	K_F1                uint32 = 0xFFBE
	K_F2                uint32 = 0xFFBF
	K_F3                uint32 = 0xFFC0
	K_F4                uint32 = 0xFFC1
	K_F5                uint32 = 0xFFC2
	K_F6                uint32 = 0xFFC3
	K_F7                uint32 = 0xFFC4
	K_F8                uint32 = 0xFFC5
	K_F9                uint32 = 0xFFC6
	K_F10               uint32 = 0xFFC7
	K_F11               uint32 = 0xFFC8
	K_F12               uint32 = 0xFFC9
	K_F13               uint32 = 0xFFCA
	K_F14               uint32 = 0xFFCB
	K_F15               uint32 = 0xFFCC
	K_F16               uint32 = 0xFFCD
	K_F17               uint32 = 0xFFCE
	K_F18               uint32 = 0xFFCF
	K_F19               uint32 = 0xFFD0
	K_F20               uint32 = 0xFFD1
	K_F21               uint32 = 0xFFD2
	K_F22               uint32 = 0xFFD3
	K_F23               uint32 = 0xFFD4
	K_F24               uint32 = 0xFFD5
	K_META              uint32 = 0xFFEB // XK_Super_L
	K_LMETA             uint32 = 0xFFEB
	K_RMETA             uint32 = 0xFFEC
	K_ALT               uint32 = 0xFFE9 // XK_Alt_L
	K_LALT              uint32 = 0xFFE9
	K_RALT              uint32 = 0xFFEA
	K_CONTROL           uint32 = 0xFFE3 // XK_Control_L
	K_LCONTROL          uint32 = 0xFFE3
	K_RCONTROL          uint32 = 0xFFE4
	K_SHIFT             uint32 = 0xFFE1 // XK_Shift_L
	K_LSHIFT            uint32 = 0xFFE1
	K_RSHIFT            uint32 = 0xFFE2
	K_CAPSLOCK          uint32 = 0xFFE5
	K_SPACE             uint32 = 0x0020
	K_PRINTSCREEN       uint32 = 0xFF61 // XK_Print
	K_INSERT            uint32 = 0xFF63 // XK_Insert
	K_MENU              uint32 = 0xFF67 // XK_Menu
	K_AUDIO_VOLUME_MUTE uint32 = 0x1008FF12
	K_AUDIO_VOLUME_DOWN uint32 = 0x1008FF11
	K_AUDIO_VOLUME_UP   uint32 = 0x1008FF13
	K_AUDIO_PLAY        uint32 = 0x1008FF14
	K_AUDIO_STOP        uint32 = 0x1008FF15
	K_AUDIO_PAUSE       uint32 = 0x1008FF31
	K_AUDIO_PREV        uint32 = 0x1008FF16
	K_AUDIO_NEXT        uint32 = 0x1008FF17
	K_AUDIO_REWIND      uint32 = 0x1008FF3E
	K_AUDIO_FORWARD     uint32 = 0x1008FF3F
	K_AUDIO_REPEAT      uint32 = 0x1008FF3B
	K_AUDIO_RANDOM      uint32 = 0x1008FF3C
	K_NUMPAD_0          uint32 = 0xFFB0
	K_NUMPAD_1          uint32 = 0xFFB1
	K_NUMPAD_2          uint32 = 0xFFB2
	K_NUMPAD_3          uint32 = 0xFFB3
	K_NUMPAD_4          uint32 = 0xFFB4
	K_NUMPAD_5          uint32 = 0xFFB5
	K_NUMPAD_6          uint32 = 0xFFB6
	K_NUMPAD_7          uint32 = 0xFFB7
	K_NUMPAD_8          uint32 = 0xFFB8
	K_NUMPAD_9          uint32 = 0xFFB9
	K_NUMPAD_LOCK       uint32 = 0xFF7F
	K_NUMPAD_DECIMAL    uint32 = 0xFFAE
	K_NUMPAD_PLUS       uint32 = 0xFFAB
	K_NUMPAD_MINUS      uint32 = 0xFFAD
	K_NUMPAD_MUL        uint32 = 0xFFAA
	K_NUMPAD_DIV        uint32 = 0xFFAF
	K_NUMPAD_CLEAR      uint32 = 0xFFBD
	K_NUMPAD_ENTER      uint32 = 0xFF8D
	K_NUMPAD_EQUAL      uint32 = 0xFFBD
	K_LIGHTS_MON_UP     uint32 = 0x1008FF02
	K_LIGHTS_MON_DOWN   uint32 = 0x1008FF03
	K_LIGHTS_KBD_TOGGLE uint32 = 0x1008FF04
	K_LIGHTS_KBD_UP     uint32 = 0x1008FF05
	K_LIGHTS_KBD_DOWN   uint32 = 0x1008FF06
)

Virtual key codes (replacing C.MMKeyCode / C.K_*) Linux X11 keycodes - using uint32 for X11 KeySym values (XF86 multimedia keys exceed uint16 range)

View Source
const (
	// Version get the robotgo version
	Version = "v1.00.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 = 10

	// 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
)
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 int, args ...int) error

ActivePid active the window by Pid

func ActivePidC

func ActivePidC(pid int, args ...int) error

ActivePidC active the window by Pid

func Alert

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

Alert show a alert window

func ByteToImg

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

ByteToImg convert []byte to image.Image

func Capture

func Capture(args ...int) (*image.RGBA, error)

Capture capture the screenshot, use the CaptureImg default

func CaptureImg

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

CaptureImg capture the screen and return image.Image, error

func CharCodeAt

func CharCodeAt(s string, n int) rune

CharCodeAt char code at utf-8

func CheckMouse

func CheckMouse(btn string) uint16

CheckMouse check the mouse button

func Click

func Click(args ...interface{}) error

Click click the mouse button and return error

robotgo.Click(button string, double bool)

Examples:

err := robotgo.Click() // default is left button
err := robotgo.Click("right")

func ClickV1

func ClickV1(args ...interface{})

ClickV1 click the mouse button

robotgo.Click(button string, double bool)

Examples:

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

func CloseMainDisplay

func CloseMainDisplay()

CloseMainDisplay close the main X11 display

func CloseWindow

func CloseWindow(args ...int)

CloseWindow close the window

func CmdCtrl

func CmdCtrl() string

CmdCtrl If the operating system is macOS, return the key string "cmd", otherwise return the key string "ctrl

func CmdV

func CmdV() error

CmdV tap key command + v or control + v

func DecodeImg

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

DecodeImg decode the image to image.Image and return

func DisplaysNum

func DisplaysNum() int

DisplaysNum get the count of displays

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 FindIds

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

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

func FindName

func FindName(pid int) (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 int) (string, error)

FindPath find the process path by the process pid

func FreeBitmap

func FreeBitmap(bitmap CBitmap)

FreeBitmap free and dealloc the bitmap

func FreeBitmapArr

func FreeBitmapArr(bit ...CBitmap)

FreeBitmapArr free and dealloc the bitmap array

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 int, args ...int) (int, int, int, int)

GetBounds get the window bounds

func GetClient

func GetClient(pid int, args ...int) (int, int, int, int)

GetClient get the window client bounds

func GetDisplayBounds

func GetDisplayBounds(i int) (x, y, w, h int)

GetDisplayBounds gets the display screen bounds

func GetHWNDByPid

func GetHWNDByPid(pid int) int

GetHWNDByPid get the hwnd by pid

func GetHandle

func GetHandle() int

GetHandle get the window handle

func GetLocationColor

func GetLocationColor(displayId ...int) string

GetLocationColor get the location pos's color

func GetMainId

func GetMainId() int

GetMainId get the main display id

func GetMousePos deprecated

func GetMousePos() (int, int)

Deprecated: use the function Location()

GetMousePos get the mouse's position return x, y

func GetPid

func GetPid() int

GetPid get the process id return int32

func GetPixelColor

func GetPixelColor(x, y int, displayId ...int) string

GetPixelColor get the pixel color return string

func GetScaleSize

func GetScaleSize(displayId ...int) (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 ...int) 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 int) (xproto.Window, error)

GetXid get the xid return window and error

func GetXidByPid

func GetXidByPid(xu *xgbutil.XUtil, pid int) (xproto.Window, error)

GetXidByPid get the xid from pid

func GetXidFromPid deprecated

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

Deprecated: use the GetXidByPid(),

GetXidFromPid get the xid from pid

func GoString

func GoString(char *int8) string

GoString trans *int8 to string (replaces C.GoString)

func Height

func Height(img image.Image) int

Height return the image.Image height

func HexToRgb

func HexToRgb(hex uint32) (r, g, b uint8)

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 IsMain

func IsMain(displayId int) bool

IsMain is main display

func IsValid

func IsValid() bool

IsValid valid the window

func KeyDown

func KeyDown(key string, args ...interface{}) error

KeyDown press down a key

func KeyPress

func KeyPress(key string, args ...interface{}) error

KeyPress press key string

func KeyTap

func KeyTap(key string, args ...interface{}) error

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

func KeyToggle(key string, args ...interface{}) error

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 KeyUp

func KeyUp(key string, args ...interface{}) error

KeyUp press up a key

func Kill

func Kill(pid int) error

Kill kill the process by PID

func Location

func Location() (int, int)

Location get the mouse location position return x, y

func MaxWindow

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

MaxWindow set the window max

func MicroSleep deprecated

func MicroSleep(tm float64)

Deprecated: use the MilliSleep(),

MicroSleep time microsecond sleep

func MilliSleep

func MilliSleep(tm int)

MilliSleep sleep tm milli second

func MinWindow

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

MinWindow set the window min

func MouseButtonString

func MouseButtonString(btn uint16) string

MouseButtonString converts a mouse button to a readable name.

func MouseClick deprecated

func MouseClick(args ...interface{})

Deprecated: use the Click(),

MouseClick click the mouse

robotgo.MouseClick(button string, double bool)

func MouseDown

func MouseDown(key ...interface{}) error

MouseDown send mouse down event

func MouseUp

func MouseUp(key ...interface{}) error

MouseUp send mouse up event

func Move

func Move(x, y int, displayId ...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 MoveScale

func MoveScale(x, y int, displayId ...int) (int, int)

MoveScale calculate the os scale factor x, y

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 MultiClick

func MultiClick(button string, count int, click ...bool) error

MultiClick performs multiple clicks and returns error

robotgo.MultiClick(button string, count int)

func OpenImg

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

OpenImg open the image return []byte

func PadHex

func PadHex(hex CHex) string

PadHex trans CHex to string

func PadHexs

func PadHexs(hex CHex) string

PadHexs trans CHex to string

func Paste

func Paste(str string) error

Paste paste a string (supported UTF-8), write the string to clipboard and tap `cmd + v`

func PasteStr deprecated

func PasteStr(str string) error

PasteStr paste a string

Deprecated: use the Paste()

func PidExists

func PidExists(pid int) (bool, error)

PidExists determine whether the process exists

func Pids

func Pids() ([]int, 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) uint32

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, quality ...int) error

Save create a image file with the image.Image

func SaveCapture

func SaveCapture(path string, args ...int) error

SaveCapture capture screen and save the screenshot to 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, quality ...int) 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 Scale0 deprecated

func Scale0() int

Deprecated: use the ScaledF(),

Scale0 return ScaleX() / 0.96, drop

func Scale1 deprecated

func Scale1() int

Deprecated: use the ScaledF(),

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

func ScaleF

func ScaleF(displayId ...int) float64

ScaleF get the system scale value

func ScaleX deprecated

func ScaleX() int

Deprecated: use the ScaledF(),

ScaleX get the primary display horizontal DPI scale factor, drop

func Scaled

func Scaled(x int, displayId ...int) int

Scaled get the screen scaled return scale size

func Scaled0

func Scaled0(x int, f float64) int

Scaled0 return int(x * f)

func Scaled1

func Scaled1(x int, f float64) int

Scaled1 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 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

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 Handle)

SetActive set the window active

func SetActiveC

func SetActiveC(win MData)

SetActiveC set the window active (MData version)

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 SetHandle

func SetHandle(hwnd int)

SetHandle set the window handle

func SetHandlePid

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

SetHandlePid set the window handle by pid

func SetXDisplayName

func SetXDisplayName(name string) error

SetXDisplayName set XDisplay name (Linux)

func Sleep

func Sleep(tm int)

Sleep time.Sleep tm second

func StrToImg

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

StrToImg convert base64 string to image.Image

func SysScale

func SysScale(displayId ...int) 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 CBitmap) image.Image

ToImage convert CBitmap to standard image.Image

func ToInterfaces

func ToInterfaces(fields []string) []interface{}

ToInterfaces convert []string to []interface{}

func ToMMRGBHex

func ToMMRGBHex(hex CHex) uint32

ToMMRGBHex trans CHex to uint32

func ToRGBA

func ToRGBA(bit CBitmap) *image.RGBA

ToRGBA convert CBitmap 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 ToStrings

func ToStrings(fields []interface{}) []string

ToStrings convert []interface{} 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 ...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 Try

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

Try handler(err)

func Type

func Type(str string, args ...int)

Type type a string (supported UTF-8)

robotgo.Type(string: "The string to send", int: pid, "milli_sleep time", "x11 option")

Examples:

robotgo.Type("abc@123, Hi galaxy, こんにちは")
robotgo.Type("To be or not to be, this is questions.", pid int)

func TypeDelay

func TypeDelay(str string, delay int)

TypeDelay type string with delayed And you can use robotgo.KeySleep = 100 to delayed not this function

func TypeStr deprecated

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

TypeStr tap a string

Deprecated: use the Type()

func TypeStrDelay deprecated

func TypeStrDelay(str string, delay int)

TypeStrDelay type string width delay

Deprecated: use the TypeDelay()

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 UnicodeType

func UnicodeType(str uint32, args ...int)

UnicodeType tap the 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 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 CaptureGo

func CaptureGo(args ...int) Bitmap

CaptureGo 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 CBitmap) Bitmap

ToBitmap trans CBitmap to Bitmap

type CBitmap

type CBitmap *MMBitmap

CBitmap define CBitmap as MMBitmap pointer type

func ByteToCBitmap

func ByteToCBitmap(by []byte) CBitmap

ByteToCBitmap trans []byte to CBitmap

func CaptureScreen

func CaptureScreen(args ...int) CBitmap

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

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

func ImgToCBitmap

func ImgToCBitmap(img image.Image) CBitmap

ImgToCBitmap trans image.Image to CBitmap

func ToCBitmap

func ToCBitmap(bit Bitmap) CBitmap

ToCBitmap trans Bitmap to CBitmap

type CHex

type CHex uint32

CHex define CHex as rgb Hex type (uint32)

func GetPxColor

func GetPxColor(x, y int, displayId ...int) CHex

GetPxColor get the pixel color return CHex

func U8ToHex

func U8ToHex(hex *uint8) CHex

U8ToHex trans *uint8 to CHex

func U32ToHex

func U32ToHex(hex uint32) CHex

U32ToHex trans uint32 to CHex

func UintToHex

func UintToHex(u uint32) CHex

UintToHex trans uint32 to robotgo.CHex

type Handle

type Handle MData

Handle define window Handle as MData type

func GetActive

func GetActive() Handle

GetActive get the active window

func GetHandById

func GetHandById(id int, args ...int) Handle

GetHandById get handle mdata by id

func GetHandByPid

func GetHandByPid(pid int, args ...int) Handle

GetHandByPid get handle mdata by pid

func GetHandPid deprecated

func GetHandPid(pid int, args ...int) Handle

Deprecated: use the GetHandByPid(),

GetHandPid get handle mdata by pid

type MData

type MData struct {
	XWin uintptr
}

MData represents window identification data (platform-specific)

func GetActiveC

func GetActiveC() MData

GetActiveC get the active window

func GetHandByPidC

func GetHandByPidC(pid int, args ...int) MData

GetHandByPidC get handle mdata by pid (returns MData)

type MMBitmap

type MMBitmap struct {
	ImageBuffer   *uint8
	Width         int32
	Height        int32
	Bytewidth     int32
	BitsPerPixel  uint8
	BytesPerPixel uint8
	// contains filtered or unexported fields
}

MMBitmap represents a bitmap in memory (replacing C.MMBitmapRef)

func ToMMBitmapRef

func ToMMBitmapRef(bit CBitmap) *MMBitmap

ToMMBitmapRef trans CBitmap to *MMBitmap (identity)

type Map

type Map map[string]interface{}

Map a map[string]interface{}

type Nps

type Nps struct {
	Pid  int
	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 GetDisplayRect

func GetDisplayRect(i int) Rect

GetDisplayRect gets the display rect

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
https://github.com/golang/go/issues/26366
https://github.com/golang/go/issues/26366
Package clipboard read/write on clipboard
Package clipboard read/write on clipboard
cmd/gocopy command
cmd/gopaste command
example command
key command
mouse command
scale command
screen command
window command
internal
darwin
Package darwin provides macOS API bindings using purego, eliminating the need for cgo.
Package darwin provides macOS API bindings using purego, eliminating the need for cgo.
win32
Package win32 provides Windows API bindings using purego/syscall, eliminating the need for cgo.
Package win32 provides Windows API bindings using purego/syscall, eliminating the need for cgo.

Jump to

Keyboard shortcuts

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