robotgo

package module
v0.0.0-...-f5574b6 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2017 License: Apache-2.0 Imports: 7 Imported by: 0

README

Robotgo

Build Status CircleCI Status Go Report Card GoDoc Release

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

RobotGo supports Mac, Windows, and Linux(X11).

This is a work in progress.

简体中文

Contents

Docs

Requirements:

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

If you do not need bitmap, you can use "github.com/go-vgo/robotgo/robot" or switch to the robot branch, where there is no zlib and libpng dependency.

ALL:
Golang
GCC
zlib & libpng (bitmap)
For Mac OS X:
Xcode Command Line Tools
brew install libpng
brew install zlib
For Windows:
MinGW or other GCC

zlib & libpng (bitmap need it.)
For everything else:
GCC
    
X11 with the XTest extension (also known as the Xtst library)

Event:
    
xcb, xkb, libxkbcommon
Ubuntu:
sudo apt-get install gcc libc6-dev

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

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

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

sudo dnf install libpng-devel

sudo dnf install xsel
sudo dnf install xclip

Installation:

go get github.com/go-vgo/robotgo

It's that easy!

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

Update:

go get -u github.com/go-vgo/robotgo  

Examples:

Mouse
package main

import (
	"github.com/go-vgo/robotgo"
)

func main() {
  robotgo.ScrollMouse(10, "up")
  robotgo.MouseClick("left", true)
  robotgo.MoveMouseSmooth(100, 200, 1.0, 100.0)
} 
Keyboard
package main

import (
  "fmt"

  "github.com/go-vgo/robotgo"
)

func main() {
  robotgo.TypeString("Hello World")
  robotgo.KeyTap("enter")
  robotgo.TypeString("en")
  robotgo.KeyTap("i", "alt", "command")
  arr := []string{"alt", "command"}
  robotgo.KeyTap("i", arr)

  robotgo.WriteAll("Test")
  text, err := robotgo.ReadAll()
  if err == nil {
    fmt.Println(text)
  }
} 
Screen
package main

import (
	"fmt"

	"github.com/go-vgo/robotgo"
)

func main() {
  x, y := robotgo.GetMousePos()
  fmt.Println("pos:", x, y)
  color := robotgo.GetPixelColor(100, 200)
  fmt.Println("color----", color)
} 
Bitmap
package main

import (
	"fmt"

	"github.com/go-vgo/robotgo"
)

func main() {
  bitmap := robotgo.CaptureScreen(10, 20, 30, 40)
  fmt.Println("...", bitmap)

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

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

import (
	"fmt"

	"github.com/go-vgo/robotgo"
)

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

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

import (
	"fmt"

	"github.com/go-vgo/robotgo"
)

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

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

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

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

Plans

  • Update Find an image on screen, read pixels from an image
  • Update Window Handle
  • Support UTF-8, transitional plan: TypeStr
  • Try support Android, maybe support IOS
  • Remove zlib/libpng dependencies

Donate

Supporting robotgo, buy me a coffee.

Paypal

Donate money by paypal to my account vzvway@gmail.com

Contributors

License

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.

See LICENSE-APACHE, LICENSE-MIT.

Documentation

Overview

Package robotgo Go native cross-platform system automation.

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

See Requirements:

https://github.com/go-vgo/robotgo#requirements

Installation:

go get -u github.com/go-vgo/robotgo

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ActivePID

func ActivePID(pid int32)

ActivePID window active by PID

func AddEvent

func AddEvent(aeve string) int

AddEvent add event listener

func BitmapStr

func BitmapStr(str string) C.MMBitmapRef

BitmapStr bitmap from string

func CaptureScreen

func CaptureScreen(args ...int) C.MMBitmapRef

CaptureScreen capture the screen return bitmap(c struct)

func Click

func Click(args ...interface{})

Click click the mouse

func CloseWindow

func CloseWindow()

CloseWindow close the window

func Convert

func Convert(args ...interface{})

Convert convert bitmap

func CopyBitpb

func CopyBitpb(bitmap C.MMBitmapRef) bool

CopyBitpb copy bitmap to pasteboard

func DeepCopyBit

func DeepCopyBit(bitmap C.MMBitmapRef) C.MMBitmapRef

DeepCopyBit deep copy bitmap

func Drag

func Drag(x, y int)

Drag drag the mouse

func DragMouse

func DragMouse(x, y int)

DragMouse drag the mouse

func FindBit

func FindBit(args ...interface{}) (int, int)

FindBit find the bitmap, Wno-deprecated

func FindBitmap

func FindBitmap(args ...interface{}) (int, int)

FindBitmap find the bitmap

func FindColor

func FindColor(bitmap C.MMBitmapRef, color C.MMRGBHex, args ...float32) (int, int)

FindColor find bitmap color

func FindEveryBitmap

func FindEveryBitmap(args ...interface{}) (int, int)

FindEveryBitmap find the every bitmap

func FindIds

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

FindIds find the process id by the process name

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 FreeBitmap

func FreeBitmap(bitmap C.MMBitmapRef)

FreeBitmap free and dealloc bitmap

func GetActive

func GetActive() C.MData

GetActive get the active window

func GetBHandle

func GetBHandle() int

GetBHandle get the window handle

func GetColor

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

GetColor get bitmap color

func GetHandle

func GetHandle() int

GetHandle get the window handle

func GetMousePos

func GetMousePos() (int, int)

GetMousePos get mouse portion

func GetPID

func GetPID() int

GetPID get the process id

func GetPixelColor

func GetPixelColor(x, y int) string

GetPixelColor get pixel color

func GetPortion

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

GetPortion get portion

func GetScreenSize

func GetScreenSize() (int, int)

GetScreenSize get screen size

func GetTitle

func GetTitle() string

GetTitle get the window title

func GetVersion

func GetVersion() string

GetVersion get version

func GetXDisplayName

func GetXDisplayName() string

GetXDisplayName get XDisplay name

func IsValid

func IsValid() bool

IsValid valid the window

func KeyTap

func KeyTap(args ...interface{})

KeyTap tap the keyboard;

See keys:

https://github.com/go-vgo/robotgo/blob/master/docs/keys.md

func KeyToggle

func KeyToggle(args ...string) string

KeyToggle toggle the keyboard

See keys:

https://github.com/go-vgo/robotgo/blob/master/docs/keys.md

func LEvent

func LEvent(aeve string) int

LEvent add event listener, Wno-deprecated

func MouseClick

func MouseClick(args ...interface{})

MouseClick click the mouse

func MouseToggle

func MouseToggle(args ...interface{})

MouseToggle toggle the mouse

func Move

func Move(x, y int)

Move move the mouse

func MoveClick

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

MoveClick move and click the mouse

func MoveMouse

func MoveMouse(x, y int)

MoveMouse move the mouse

func MoveMouseSmooth

func MoveMouseSmooth(x, y int, args ...float64)

MoveMouseSmooth move the mouse smooth

func MoveSmooth

func MoveSmooth(x, y int, args ...float64)

MoveSmooth move the mouse smooth

func OpenBitmap

func OpenBitmap(args ...interface{}) C.MMBitmapRef

OpenBitmap open the bitmap

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

func SaveBitmap(args ...interface{}) string

SaveBitmap save the bitmap

func ScrollMouse

func ScrollMouse(x int, y string)

ScrollMouse scroll the mouse

func SetActive

func SetActive(win C.MData)

SetActive set the window active

func SetHandle

func SetHandle(hwnd int)

SetHandle set the window handle

func SetKeyDelay

func SetKeyDelay(x int)

SetKeyDelay set keyboard delay

func SetKeyboardDelay

func SetKeyboardDelay(x int)

SetKeyboardDelay set keyboard delay, Wno-deprecated

func SetMouseDelay

func SetMouseDelay(x int)

SetMouseDelay set mouse delay

func SetXDisplayName

func SetXDisplayName(name string) string

SetXDisplayName set XDisplay name

func ShowAlert

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

ShowAlert show a alert window

func StopEvent

func StopEvent()

StopEvent stop event listener

func TostringBitmap

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

TostringBitmap tostring bitmap

func Try

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

Try handler(err)

func TypeStr

func TypeStr(str string)

TypeStr type string, support UTF-8

func TypeStrDelay

func TypeStrDelay(x string, y int)

TypeStrDelay type string delayed

func TypeString

func TypeString(x string)

TypeString type string

func TypeStringDelayed

func TypeStringDelayed(x string, y int)

TypeStringDelayed type string delayed, Wno-deprecated

func WriteAll

func WriteAll(text string)

WriteAll write string to clipboard

Types

type Bitmap

type Bitmap struct {
	ImageBuffer   *uint8
	Width         int
	Height        int
	Bytewidth     int
	BitsPerPixel  uint8
	BytesPerPixel uint8
}

Bitmap is Bitmap struct

func BCaptureScreen

func BCaptureScreen(args ...int) Bitmap

BCaptureScreen capture the screen and return bitmap(go struct), Wno-deprecated

func GoCaptureScreen

func GoCaptureScreen(args ...int) Bitmap

GoCaptureScreen capture the screen and return bitmap(go struct)

type MPoint

type MPoint struct {
	// contains filtered or unexported fields
}

MPoint is MPoint struct

type Map

type Map map[string]interface{}

Map a map

type Nps

type Nps struct {
	Pid  int32
	Name string
}

Nps process struct

func Process

func Process() ([]Nps, error)

Process get the all process struct

Directories

Path Synopsis
Package clipboard read/write on clipboard
Package clipboard read/write on clipboard
key
Package robotgo Go native cross-platform system automation.
Package robotgo Go native cross-platform system automation.

Jump to

Keyboard shortcuts

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