package module
Version: v0.100.10 Latest Latest

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

Go to latest
Published: Dec 14, 2021 License: Apache-2.0 Imports: 22 Imported by: 233



Build Status CircleCI Status Build Status Appveyor Go Report Card GoDoc GitHub release

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

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

Chinese Simplified




ADB, packaging android adb API.

Robotn, binding JavaScript and other, support more language.


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


For Mac OS X:

Xcode Command Line Tools (And Privacy setting: #277 )

xcode-select --install
For Windows:

MinGW-w64 (Use recommended)

Or the other GCC (But you should compile the "libpng" with yourself. 
Or you can removed the bitmap.go. 

In the plans, the bitmap.go will moves to the bitmap dir, but break the API. )
For everything else:
GCC, libpng

X11 with the XTest extension (also known as the Xtst library)


xcb, xkb, libxkbcommon
# gcc
sudo apt install gcc libc6-dev

sudo apt install libx11-dev xorg-dev libxtst-dev libpng++-dev

sudo apt install xcb libxcb-xkb-dev x11-xkb-utils libx11-xcb-dev libxkbcommon-x11-dev libxkbcommon-dev

sudo apt install xsel xclip
sudo dnf install libxkbcommon-devel libXtst-devel libxkbcommon-x11-devel xorg-x11-xkb-utils-devel

sudo dnf install libpng-devel

sudo dnf install xsel xclip


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

import ""

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

go get

png.h: No such file or directory? Please see issues/47.


go get -u

Note go1.10.x C file compilation cache problem, golang #24355. go mod vendor problem, golang #26366.


package main

import (

func main() {
  // robotgo.ScrollMouse(10, "up")
  robotgo.Scroll(0, -10)
  robotgo.Scroll(100, 0)

  robotgo.ScrollSmooth(-10, 6)
  // robotgo.ScrollRelative(10, -100)

  robotgo.MouseSleep = 100
  robotgo.Move(10, 20)
  robotgo.MoveRelative(0, -10)
  robotgo.Drag(10, 10)

  robotgo.Click("left", true)
  robotgo.MoveSmooth(100, 200, 1.0, 10.0)

  robotgo.Toggle("left", "up")
package main

import (


func main() {
  robotgo.TypeStr("Hello World")
  robotgo.TypeStr("だんしゃり", 1.0)
  // robotgo.TypeStr("テストする")

  robotgo.TypeStr("Hi galaxy. こんにちは世界.")

  // ustr := uint32(robotgo.CharCodeAt("Test", 0))
  // robotgo.UnicodeType(ustr)

  robotgo.KeySleep = 100
  // robotgo.TypeStr("en")
  robotgo.KeyTap("i", "alt", "command")

  arr := []string{"alt", "command"}
  robotgo.KeyTap("i", arr)

  robotgo.KeyToggle("a", "up")

  text, err := robotgo.ReadAll()
  if err == nil {
package main

import (


func main() {
  x, y := robotgo.GetMousePos()
  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)
  robotgo.SaveBitmap(bit, "test_1.png")

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

import (


func main() {
  bitmap := robotgo.CaptureScreen(10, 20, 30, 40)
  // use `defer robotgo.FreeBitmap(bit)` to free the bitmap
  defer robotgo.FreeBitmap(bitmap)

  fmt.Println("bitmap...", bitmap)
  img := robotgo.ToImage(bitmap)
  robotgo.SavePng(img, "test_1.png")

  bit2 := robotgo.ToCBitmap(robotgo.ImgToBitmap(img))
  fx, fy := robotgo.FindBitmap(bit2)
  fmt.Println("FindBitmap------ ", fx, fy)
  robotgo.Move(fx, fy)

  arr := robotgo.FindAllBitmap(bit2)
  fmt.Println("Find all bitmap: ", arr)
  robotgo.SaveBitmap(bitmap, "test.png")

  fx, fy = robotgo.FindBitmap(bitmap)
  fmt.Println("FindBitmap------ ", fx, fy)

  robotgo.SaveBitmap(bitmap, "test.png")
package main

import (


func main() {

func opencv() {
  name := "test.png"
  name1 := "test_001.png"
  robotgo.SaveCapture(name1, 10, 10, 30, 30)

  fmt.Print("gcv find image: ")
  fmt.Println(gcv.FindImgFile(name1, name))
  fmt.Println(gcv.FindAllImgFile(name1, name))

  bit := robotgo.OpenBitmap(name1)
  defer robotgo.FindBitmap(bit)
  fmt.Print("find bitmap: ")

  // bit0 := robotgo.CaptureScreen()
  // img := robotgo.ToImage(bit0)
  // bit1 := robotgo.CaptureScreen(10, 10, 30, 30)
  // img1 := robotgo.ToImage(bit1)
  // defer robotgo.FreeBitmapArr(bit0, bit1)
  img := robotgo.CaptureImg()
  img1 := robotgo.CaptureImg(10, 10, 30, 30)

  fmt.Print("gcv find image: ")
  fmt.Println(gcv.FindImg(img1, img))

  res := gcv.FindAllImg(img1, img)
  fmt.Println(res[0].TopLeft.Y, res[0].Rects.TopLeft.X, res)
  x, y := res[0].TopLeft.X, res[0].TopLeft.Y
  robotgo.Move(x, y-rand.Intn(5))

  res = gcv.FindAll(img1, img) // use find template and sift
  fmt.Println("find all: ", res)
  res1 := gcv.Find(img1, img)
  fmt.Println("find: ", res1)

  img2, _, _ := robotgo.DecodeImg("test_001.png")
  x, y = gcv.FindX(img2, img)
  fmt.Println(x, y)
package main

import (

  hook ""

func main() {

func add() {
  fmt.Println("--- Please press ctrl + shift + q to stop hook ---")
  robotgo.EventHook(hook.KeyDown, []string{"q", "ctrl", "shift"}, func(e hook.Event) {

  fmt.Println("--- Please press w---")
  robotgo.EventHook(hook.KeyDown, []string{"w"}, func(e hook.Event) {

  s := robotgo.EventStart()

func low() {
	evChan := hook.Start()
	defer hook.End()

	for ev := range evChan {
		fmt.Println("hook: ", ev)

func event() {
  ok := robotgo.AddEvents("q", "ctrl", "shift")
  if ok {
    fmt.Println("add events...")

  keve := robotgo.AddEvent("k")
  if keve {
    fmt.Println("you press... ", "k")

  mleft := robotgo.AddEvent("mleft")
  if mleft {
    fmt.Println("you press... ", "mouse left button")
package main

import (


func main() {
  fpid, err := robotgo.FindIds("Google")
  if err == nil {
    fmt.Println("pids... ", fpid)

    if len(fpid) > 0 {



  isExist, err := robotgo.PidExists(100)
  if err == nil && isExist {
    fmt.Println("pid exists is", isExist)


  abool := robotgo.ShowAlert("test", "robotgo")
  if abool {
 	  fmt.Println("ok@@@ ", "ok")

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


Windows64 to windows32
go build main.go
Other to windows

Install Requirements (Ubuntu):

sudo apt install gcc-multilib
sudo apt install gcc-mingw-w64
# fix err: zlib.h: No such file or directory
sudo apt install libz-mingw-w64-dev

Build the binary:

GOOS=windows GOARCH=amd64 CGO_ENABLED=1 CC=x86_64-w64-mingw32-gcc CXX=x86_64-w64-mingw32-g++ go build -x ./
// CC=mingw-w64\x86_64-7.2.0-win32-seh-rt_v5-rev1\mingw64\bin\gcc.exe
// CXX=mingw-w64\x86_64-7.2.0-win32-seh-rt_v5-rev1\mingw64\bin\g++.exe

Some discussions and questions, please see issues/228, issues/143.



  • Update Find an image on screen, read pixels from an image
  • Update Window Handle
  • Try support Android, maybe support IOS



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




Package robotgo Go native cross-platform system automation.

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

See Requirements:

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

import ""


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

go get -u



View Source
const (
	// Version get the robotgo version
	Version = "v0.100.0.1189, MT. Baker!"


View Source
var (
	// MouseSleep set the mouse default millisecond sleep time
	MouseSleep = 0
	// KeySleep set the key default millisecond sleep time
	KeySleep = 0
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


func ActiveName

func ActiveName(name string) error

ActiveName active the window by name



func ActivePID

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

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

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

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

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

func AddMousePos(x, y int16) bool

AddMousePos add listen mouse event pos hook

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 ByteToImg added in v0.93.2

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

ByteToImg convert []byte to image.Image

func CaptureImg added in v0.100.1

func CaptureImg(args image.Image

CaptureImg capture the screen and return image.Image

func CaptureScreen

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

func CharCodeAt(s string, n int) rune

CharCodeAt char code at utf-8

func CheckMouse

func CheckMouse(btn string) C.MMMouseButton

CheckMouse check the mouse button

func Click

func Click(args ...interface{})

Click click the mouse button

robotgo.Click(button string, double bool)


robotgo.Click() // default is left button

func CloseWindow

func CloseWindow(args ...int32)

CloseWindow close the window

func Convert

func Convert(opath, spath string, args string

Convert convert the bitmap

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

func CopyBitPB

func CopyBitPB(bitmap C.MMBitmapRef) bool

CopyBitPB copy bitmap to pasteboard

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

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

CountColor count bitmap color

func CountColorCS

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

CountColorCS count bitmap color by CaptureScreen

func DecodeImg

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

DecodeImg decode the image to image.Image and return

func DeepCopyBit

func DeepCopyBit(bitmap C.MMBitmapRef) C.MMBitmapRef

DeepCopyBit deep copy bitmap

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)


robotgo.DragSmooth(10, 10)

func End deprecated

func End()

Deprecated: use the EventEnd(),

End removes global event hook

func EventEnd

func EventEnd()

EventEnd removes global event hook

func EventHook

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

EventHook register gohook event

func EventProcess

func EventProcess(events chan hook.Event) chan bool

EventProcess return go hook process

func EventStart

func EventStart() chan hook.Event

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

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

FindCBitmap find bitmap's pos by CBitmap

func FindColor

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

FindColor find bitmap color

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

func FindColorCS

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

FindColorCS findcolor by CaptureScreen

func FindIds

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

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

func FindName

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

FindPath find the process path by the process pid

func FindPic

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

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 FreeBitmap

func FreeBitmap(bitmap C.MMBitmapRef)

FreeBitmap free and dealloc the C 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 GetActive

func GetActive() C.MData

GetActive get the active window

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

GetBounds get the window bounds

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

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

GetHandPid get handle mdata by pid

func GetHandle

func GetHandle() int

GetHandle get the window handle

func GetImgSize

func GetImgSize(imgPath string) (int, int)

GetImgSize get the image size

func GetMouseColor

func GetMouseColor() string

GetMouseColor get the mouse pos's color

func GetMousePos

func GetMousePos() (int, int)

GetMousePos get the mouse's portion return x, y

func GetPID

func GetPID() int32

GetPID get the process id return int32

func GetPixelColor

func GetPixelColor(x, y int) string

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

func GetPxColor(x, y int) C.MMRGBHex

GetPxColor get the pixel color return C.MMRGBHex

func GetScaleSize

func GetScaleSize() (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 ...int32) string

GetTitle get the window title return string



ids, _ := robotgo.FindIds()

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 int32) (xproto.Window, error)

GetXId get the xid return window and error

func GetXidFromPid

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

GetXidFromPid get the xide from pid

func GoString

func GoString(char *C.char) string

GoString trans C.char to string

func Height added in v0.100.2

func Height(img image.Image) int

Height return the image.Image height

func HexToRgb

func HexToRgb(hex uint32) *C.uint8_t

HexToRgb trans hex to rgb

func ImgSize added in v0.100.2

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 IsValid

func IsValid() bool

IsValid valid the window

func KeyDown added in v0.100.0

func KeyDown(key string)

KeyDown press down a key

func KeyPress added in v0.100.0

func KeyPress(key string)

KeyPress press key string

func KeyTap

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

KeyTap tap the keyboard code;

See keys:


robotgo.KeySleep = 100 // 100 millisecond
robotgo.KeyTap("i", "alt", "command")

arr := []string{"alt", "command"}
robotgo.KeyTap("i", arr)

func KeyToggle

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

KeyToggle toggle the keyboard, if there not have args default is "down"

See keys:


robotgo.KeyToggle("a", "up")

robotgo.KeyToggle("a", "up", "alt", "cmd")

func KeyUp added in v0.100.0

func KeyUp(key string)

KeyUp press up a key

func Kill

func Kill(pid int32) error

Kill kill the process by PID

func MaxWindow

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

MaxWindow set the window max

func MicroSleep

func MicroSleep(tm float64)

MicroSleep time C.microsleep(tm)

func MilliSleep

func MilliSleep(tm int)

MilliSleep sleep tm milli second

func MinWindow

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

MinWindow set the window min

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 MouseToggle(togKey string, args ...interface{}) int

Deprecated: use the Toggle(),

MouseToggle toggle the mouse


robotgo.MouseToggle("down", "right")
robotgo.MouseToggle("up", "right")

func Move

func Move(x, y int)

Move move the mouse to (x, y)


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)


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


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 OpenBitmap

func OpenBitmap(gpath string, args C.MMBitmapRef

OpenBitmap open the bitmap return C.MMBitmapRef

robotgo.OpenBitmap(path string, type int)

func OpenImg

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

OpenImg open the image return []byte

func PadHex

func PadHex(hex C.MMRGBHex) string

PadHex trans C.MMRGBHex to string

func PasteStr

func PasteStr(str string) string

PasteStr paste a string, support UTF-8, write the string to clipboard and tap `cmd + v`

func PidExists

func PidExists(pid int32) (bool, error)

PidExists determine whether the process exists

func Pids

func Pids() ([]int32, error)

Pids get the all process id

func PointInBounds

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

PointInBounds bitmap point in bounds

func Read added in v0.100.0

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 ReadBitmap

func ReadBitmap(bitmap C.MMBitmapRef) bool

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

func RgbToHex

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

RgbToHex trans rgb to hex

func Run added in v0.100.9

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

Run run a cmd shell

func Save added in v0.100.0

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

Save create a image file with the image.Image

func SaveBitmap

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

func SaveCapture(spath string, args string

SaveCapture capture screen and save

func SaveImg

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

SaveImg save the image by []byte

func SaveJpeg added in v0.100.0

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

SaveJpeg save the image by image.Image

func SavePng added in v0.92.0

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

SavePng save the image by image.Image

func Scale deprecated

func Scale() int

Deprecated: use the ScaledF(),

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

func Scale0 deprecated added in v0.100.1

func Scale0() int

Deprecated: use the ScaledF(),

Scale0 return ScaleX() / 0.96, drop

func ScaleF added in v0.100.8

func ScaleF() float64

ScaleF get the system scale val

func ScaleX deprecated

func ScaleX() int

Deprecated: use the ScaledF(),

ScaleX get the primary display horizontal DPI scale factor, drop

func ScaleY deprecated

func ScaleY() int

Deprecated: use the ScaledF(),

ScaleY get primary display vertical DPI scale factor, drop

func Scaled

func Scaled(x int) int

Scaled get the screen scaled size

func Scaled0 added in v0.100.8

func Scaled0(x int, f float64) int

Scaled0 return int(x * f)

func Scroll

func Scroll(x, y int, args

Scroll scroll the mouse to (x, y)

robotgo.Scroll(x, y, msDelay int)


robotgo.Scroll(10, 10)

func ScrollMouse deprecated

func ScrollMouse(x int, direction string)

Deprecated: use the Scroll(),

ScrollMouse scroll the mouse to (x, "up")


robotgo.ScrollMouse(10, "down")
robotgo.ScrollMouse(10, "up")

func ScrollRelative added in v0.100.1

func ScrollRelative(x, y int, args

ScrollRelative scroll mouse with relative


robotgo.ScrollRelative(10, 10)

func ScrollSmooth added in v0.100.7

func ScrollSmooth(to int, args

ScrollSmooth scroll the mouse smooth, default scroll 5 times and sleep 100 millisecond

robotgo.ScrollSmooth(toy, num, sleep, tox)


robotgo.ScrollSmooth(-10, 6, 200, -10)

func SetActive

func SetActive(win C.MData)

SetActive set the window active

func SetDelay

func SetDelay(d

SetDelay set the key and mouse delay

func SetHandle

func SetHandle(hwnd int)

SetHandle set the window handle

func SetHandlePid

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

SetHandlePid set the window handle by pid

func SetKeyDelay

func SetKeyDelay(delay int)

SetKeyDelay set keyboard delay

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 SetMouseDelay

func SetMouseDelay(delay int)

SetMouseDelay set mouse delay

func SetXDisplayName

func SetXDisplayName(name string) string

SetXDisplayName set XDisplay name (Linux)

func ShowAlert

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

ShowAlert show a alert window Displays alert with the attributes. If cancel button is not given, only the default button is displayed


robotgo.ShowAlert("hi", "window", "ok", "cancel")

func Sleep

func Sleep(tm int)

Sleep time.Sleep tm second

func Start deprecated

func Start() chan hook.Event

Deprecated: use the EventStart(),

Start start global event hook return event channel

func StopEvent

func StopEvent()

StopEvent stop event listener, use by AddEvent()

func StrToImg added in v0.94.0

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

StrToImg convert base64 string to image.Image

func SysScale

func SysScale() float64

SysScale get the sys scale

func ToBitmapBytes

func ToBitmapBytes(bit C.MMBitmapRef) []byte

ToBitmapBytes saves Bitmap to bitmap format in bytes

func ToByteImg added in v0.94.0

func ToByteImg(img image.Image, fm ...string) []byte

ToByteImg convert image.Image to []byte

func ToCBitmap

func ToCBitmap(bit Bitmap) C.MMBitmapRef

ToCBitmap trans Bitmap to C.MMBitmapRef

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 ToMMRGBHex

func ToMMRGBHex(hex CHex) C.MMRGBHex

ToMMRGBHex trans CHex to C.MMRGBHex

func ToRGBA added in v0.99.9

func ToRGBA(bit C.MMBitmapRef) *image.RGBA

ToRGBA convert C.MMBitmapRef to standard image.RGBA

func ToRGBAGo added in v0.99.9

func ToRGBAGo(bmp1 Bitmap) *image.RGBA

ToRGBAGo convert Bitmap to standard image.RGBA

func ToStringImg added in v0.94.0

func ToStringImg(img image.Image, fm ...string) string

ToStringImg convert image.Image to string

func ToUC added in v0.99.1

func ToUC(text string) []string

ToUC trans string to unicode []string

func ToUint8p added in v0.99.9

func ToUint8p(dst []uint8) *uint8

ToUint8p convert the []uint8 to uint8 pointer

func TocharBitmap

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

TocharBitmap tostring bitmap to C.char

func Toggle added in v0.100.7

func Toggle(key ...string) int

Toggle toggle the mouse, support button:

	"left", "center", "right",
 "wheelDown", "wheelUp", "wheelLeft", "wheelRight"


robotgo.Toggle("left") // default is down
robotgo.Toggle("left", "up")

func TostringBitmap

func TostringBitmap(bit C.MMBitmapRef) string

TostringBitmap tostring bitmap to string

func Try

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

Try handler(err)

func TypeStr

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

TypeStr send a string, support UTF-8

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


robotgo.TypeStr("abc@123, hi, こんにちは")

func TypeStrDelay

func TypeStrDelay(str string, delay int)

TypeStrDelay type string delayed

func TypeString deprecated

func TypeString(str string, delay

Deprecated: use the TypeStr(),

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

This function will be removed in version v1.0.0

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 U32ToHex

func U32ToHex(hex C.uint32_t) C.MMRGBHex

U32ToHex trans C.uint32_t to C.MMRGBHex

func U8ToHex

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

U8ToHex trans *C.uint8_t to C.MMRGBHex

func UnicodeType

func UnicodeType(str uint32)

UnicodeType tap uint32 unicode

func Width added in v0.100.2

func Width(img image.Image) int

Width return the image.Image width

func WriteAll

func WriteAll(text string) error

WriteAll write string to clipboard


type Bitmap

type Bitmap struct {
	ImgBuf        *uint8
	Width, Height int

	Bytewidth     int
	BitsPixel     uint8
	BytesPerPixel uint8

Bitmap is Bitmap struct

func GoCaptureScreen

func GoCaptureScreen(args Bitmap

GoCaptureScreen capture the screen and return bitmap(go struct)

func ImgToBitmap added in v0.99.9

func ImgToBitmap(m image.Image) (bit Bitmap)

ImgToBitmap convert the standard image.Image to Bitmap

func RGBAToBitmap added in v0.99.9

func RGBAToBitmap(r1 *image.RGBA) (bit Bitmap)

RGBAToBitmap convert the standard image.RGBA to Bitmap

func ToBitmap

func ToBitmap(bit C.MMBitmapRef) Bitmap

ToBitmap trans C.MMBitmapRef to Bitmap

type CBitmap

type CBitmap C.MMBitmapRef

CBitmap define CBitmap as C.MMBitmapRef type

type CHex

type CHex C.MMRGBHex

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

func UintToHex

func UintToHex(u uint32) CHex

UintToHex trans uint32 to robotgo.CHex

type Map

type Map map[string]interface{}

Map a map[string]interface{}

type Nps

type Nps struct {
	Pid  int32
	Name string

Nps process struct

func Process

func Process() ([]Nps, error)

Process get the all process struct

type Point added in v0.100.3

type Point struct {
	X int
	Y int

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

func FindAllColor(color CHex, args ...interface{}) (posArr []Point)

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

func FindEveryColor(color CHex, args ...interface{}) []Point

Deprecated: use the FindAllColor(),

FindEveryColor find the every color, same with the FindAllColor()

type Rect added in v0.100.3

type Rect struct {

Rect is rect structure

func GetScreenRect added in v0.100.3

func GetScreenRect(displayId Rect

GetScreenRect get the screen rect (x, y, w, h)

type Size added in v0.100.3

type Size struct {
	W, H int

Size is size structure


Path Synopsis
Package clipboard read/write on clipboard
Package clipboard read/write on clipboard

Jump to

Keyboard shortcuts

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