Merge pull request #539 from go-vgo/bitmap-pr

Unified name and Update godoc, fixed typo
This commit is contained in:
Evans 2022-11-01 10:32:12 -07:00 committed by GitHub
commit fc5dac6f8a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 108 additions and 76 deletions

View File

@ -53,7 +53,7 @@ Golang
GCC
```
#### For Mac OS X:
#### For MacOS:
Xcode Command Line Tools (And Privacy setting: [#277](https://github.com/go-vgo/robotgo/issues/277) )
@ -163,8 +163,8 @@ import (
func main() {
robotgo.MouseSleep = 100
robotgo.ScrollMouse(10, "up")
robotgo.ScrollMouse(20, "right")
robotgo.ScrollDir(10, "up")
robotgo.ScrollDir(20, "right")
robotgo.Scroll(0, -10)
robotgo.Scroll(100, 0)
@ -242,7 +242,7 @@ import (
)
func main() {
x, y := robotgo.GetMousePos()
x, y := robotgo.Location()
fmt.Println("pos: ", x, y)
color := robotgo.GetPixelColor(100, 200)
@ -455,7 +455,7 @@ func main() {
robotgo.KeyToggle("a", fpid[0])
robotgo.KeyToggle("a", fpid[0], "up")
robotgo.ActivePID(fpid[0])
robotgo.ActivePid(fpid[0])
robotgo.Kill(fpid[0])
}
@ -519,9 +519,9 @@ Some discussions and questions, please see [issues/228](https://github.com/go-vg
## Plans
- Refactor some C code to Go (such as x11, windows)
- Better multiscreen support
- Waylad supports
- Wayland support
- Update Window Handle
- Try support Android and IOS
- Try to support Android and IOS
## Contributors

View File

@ -1,5 +1,7 @@
# Robotgo
## !!! Warning: this page not updated !!!
[![Build Status](https://github.com/go-vgo/robotgo/workflows/Go/badge.svg)](https://github.com/go-vgo/robotgo/commits/master)
[![CircleCI Status](https://circleci.com/gh/go-vgo/robotgo.svg?style=shield)](https://circleci.com/gh/go-vgo/robotgo)
[![Build Status](https://travis-ci.org/go-vgo/robotgo.svg)](https://travis-ci.org/go-vgo/robotgo)
@ -67,7 +69,7 @@ xcode-select --install
```
Or the other GCC (But you should compile the "libpng" with yourself.
Or you can removed the bitmap.go )
Or you can removed the bitmap.go.)
```
#### For everything else (Linux 等其他系统):

View File

@ -22,12 +22,12 @@
return TRUE;
}
HWND GetHwndByPId(DWORD dwProcessId) {
HWND GetHwndByPid(DWORD dwProcessId) {
WNDINFO info = {0};
info.hWnd = NULL;
info.dwPid = dwProcessId;
EnumWindows(EnumWindowsProc, (LPARAM)&info);
// printf("%d\n", info.hWnd);
return info.hWnd;
}
#endif

View File

@ -55,7 +55,7 @@ func click() {
func get() {
// gets the mouse coordinates
x, y := robotgo.GetMousePos()
x, y := robotgo.Location()
fmt.Println("pos:", x, y)
if x == 456 && y == 586 {
fmt.Println("mouse...", "586")
@ -66,8 +66,8 @@ func get() {
func toggleAndScroll() {
// scrolls the mouse either up
robotgo.ScrollMouse(10, "up")
robotgo.ScrollMouse(10, "right")
robotgo.ScrollDir(10, "up")
robotgo.ScrollDir(10, "right")
robotgo.Scroll(100, 10)
robotgo.Scroll(0, -10)

View File

@ -28,7 +28,7 @@ func alert() {
func get() {
// get the current process id
pid := robotgo.GetPID()
pid := robotgo.GetPid()
fmt.Println("pid----", pid)
// get current Window Active
@ -64,7 +64,7 @@ func findIds() {
fmt.Println("pids...", fpid)
if len(fpid) > 0 {
err = robotgo.ActivePID(fpid[0])
err = robotgo.ActivePid(fpid[0])
if err != nil {
fmt.Println(err)
}
@ -87,7 +87,7 @@ func findIds() {
}
func active() {
robotgo.ActivePID(100)
robotgo.ActivePid(100)
// robotgo.Sleep(2)
robotgo.ActiveName("code")
robotgo.Sleep(1)

28
key.go
View File

@ -201,7 +201,7 @@ const (
LightsKbdDown = "lights_kbd_down"
)
// keyNames define MMKeyCode map
// keyNames define a map of key names to MMKeyCode
var keyNames = map[string]C.MMKeyCode{
"backspace": C.K_BACKSPACE,
"delete": C.K_DELETE,
@ -441,7 +441,7 @@ func keyToggles(k string, keyArr []string, pid int) error {
*/
// ToInterfaces []string to []interface{}
// ToInterfaces convert []string to []interface{}
func ToInterfaces(fields []string) []interface{} {
res := make([]interface{}, 0, len(fields))
for _, s := range fields {
@ -450,7 +450,7 @@ func ToInterfaces(fields []string) []interface{} {
return res
}
// ToStrings []interface{} to []string
// ToStrings convert []interface{} to []string
func ToStrings(fields []interface{}) []string {
res := make([]string, 0, len(fields))
for _, s := range fields {
@ -467,19 +467,20 @@ func toErr(str *C.char) error {
return errors.New(gstr)
}
// KeyTap tap the keyboard code;
// KeyTap taps 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 KeyTap(key string, args ...interface{}) error {
var keyArr []string
@ -512,17 +513,18 @@ func KeyTap(key string, args ...interface{}) error {
return keyTaps(key, keyArr, pid)
}
// KeyToggle toggle the keyboard, if there not have args default is "down"
// 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
//
// Examples:
//
// robotgo.KeyToggle("a")
// robotgo.KeyToggle("a", "up")
//
// robotgo.KeyToggle("a", "up", "alt", "cmd")
//
func KeyToggle(key string, args ...interface{}) error {
if len(key) > 0 && unicode.IsUpper([]rune(key)[0]) {
@ -633,13 +635,13 @@ func inputUTF(str string) {
C.free(unsafe.Pointer(cstr))
}
// TypeStr send a string, supported UTF-8
// TypeStr send a string (supported UTF-8)
//
// robotgo.TypeStr(string: "The string to send", int: pid, "milli_sleep time", "x11 option")
//
// Examples:
// robotgo.TypeStr("abc@123, Hi galaxy, こんにちは")
//
// robotgo.TypeStr("abc@123, Hi galaxy, こんにちは")
func TypeStr(str string, args ...int) {
var tm, tm1 = 0, 7
@ -681,7 +683,7 @@ func TypeStr(str string, args ...int) {
MilliSleep(KeySleep)
}
// PasteStr paste a string, support UTF-8,
// PasteStr paste a string (support UTF-8),
// write the string to clipboard and tap `cmd + v`
func PasteStr(str string) error {
err := clipboard.WriteAll(str)
@ -696,7 +698,7 @@ func PasteStr(str string) error {
return KeyTap("v", "control")
}
// TypeStrDelay type string delayed
// TypeStrDelay type string with delayed
func TypeStrDelay(str string, delay int) {
TypeStr(str)
MilliSleep(delay)
@ -704,7 +706,7 @@ func TypeStrDelay(str string, delay int) {
// Deprecated: use the TypeStr(),
//
// TypeStringDelayed type string delayed, Wno-deprecated
// # TypeStringDelayed type string delayed, Wno-deprecated
//
// This function will be removed in version v1.0.0
func TypeStringDelayed(str string, delay int) {
@ -712,7 +714,7 @@ func TypeStringDelayed(str string, delay int) {
TypeStrDelay(str, delay)
}
// SetDelay set the key and mouse delay
// SetDelay sets the key and mouse delay
func SetDelay(d ...int) {
v := 10
if len(d) > 0 {

View File

@ -192,7 +192,7 @@ void clickMouse(MMMouseButton button){
toggleMouse(false, button);
}
/* Special function for sending double clicks, needed for Mac OS X. */
/* Special function for sending double clicks, needed for MacOS. */
void doubleClick(MMMouseButton button){
#if defined(IS_MACOSX)
/* Double click for Mac. */

View File

@ -33,6 +33,9 @@ func TestGetScreenSize(t *testing.T) {
rect := robotgo.GetScreenRect()
fmt.Println("Get screen rect: ", rect)
x, y = robotgo.Location()
fmt.Println("Get location: ", x, y)
}
func TestGetSysScale(t *testing.T) {

View File

@ -9,20 +9,22 @@
// except according to those terms.
/*
Package robotgo Go native cross-platform system automation.
Please make sure Golang, GCC is installed correctly before installing RobotGo;
See Requirements:
https://github.com/go-vgo/robotgo#requirements
Installation:
With Go module support (Go 1.11+), just import:
import "github.com/go-vgo/robotgo"
Otherwise, to install the robotgo package, run the command:
go get -u github.com/go-vgo/robotgo
*/
package robotgo
@ -236,8 +238,8 @@ func getNumDisplays() int {
return int(C.get_num_displays())
}
// GetHwndByPId get the hwnd by pid
func GetHwndByPId(pid int) int {
// GetHWNDByPid get the hwnd by pid
func GetHWNDByPid(pid int) int {
return int(C.get_hwnd_by_pid(C.uintptr(pid)))
}
@ -513,8 +515,9 @@ func MoveMouse(x, y int) {
// Move move the mouse to (x, y)
//
// Examples:
// robotgo.MouseSleep = 100 // 100 millisecond
// robotgo.Move(10, 10)
//
// robotgo.MouseSleep = 100 // 100 millisecond
// robotgo.Move(10, 10)
func Move(x, y int) {
// if runtime.GOOS == "windows" {
// f := ScaleF()
@ -560,6 +563,7 @@ func Drag(x, y int, args ...string) {
// DragSmooth drag the mouse like smooth to (x, y)
//
// Examples:
//
// robotgo.DragSmooth(10, 10)
func DragSmooth(x, y int, args ...interface{}) {
Toggle("left")
@ -582,6 +586,7 @@ func MoveMouseSmooth(x, y int, args ...interface{}) bool {
// robotgo.MoveSmooth(x, y int, low, high float64, mouseDelay int)
//
// Examples:
//
// robotgo.MoveSmooth(10, 10)
// robotgo.MoveSmooth(10, 10, 1.0, 2.0)
func MoveSmooth(x, y int, args ...interface{}) bool {
@ -619,7 +624,7 @@ func MoveSmooth(x, y int, args ...interface{}) bool {
// MoveArgs get the mouse relative args
func MoveArgs(x, y int) (int, int) {
mx, my := GetMousePos()
mx, my := Location()
mx = mx + x
my = my + y
@ -637,8 +642,15 @@ func MoveSmoothRelative(x, y int, args ...interface{}) {
MoveSmooth(mx, my, args...)
}
// Deprecated: use the function Location()
//
// GetMousePos get the mouse's position return x, y
func GetMousePos() (int, int) {
return Location()
}
// Location get the mouse location position return x, y
func Location() (int, int) {
pos := C.getMousePos()
x := int(pos.x)
y := int(pos.y)
@ -648,7 +660,7 @@ func GetMousePos() (int, int) {
// Deprecated: use the Click(),
//
// MouseClick click the mouse
// # MouseClick click the mouse
//
// robotgo.MouseClick(button string, double bool)
func MouseClick(args ...interface{}) {
@ -660,7 +672,8 @@ func MouseClick(args ...interface{}) {
// robotgo.Click(button string, double bool)
//
// Examples:
// robotgo.Click() // default is left button
//
// robotgo.Click() // default is left button
// robotgo.Click("right")
// robotgo.Click("wheelLeft")
func Click(args ...interface{}) {
@ -691,6 +704,7 @@ func Click(args ...interface{}) {
// robotgo.MoveClick(x, y int, button string, double bool)
//
// Examples:
//
// robotgo.MouseSleep = 100
// robotgo.MoveClick(10, 10)
func MoveClick(x, y int, args ...interface{}) {
@ -709,10 +723,12 @@ func MovesClick(x, y int, args ...interface{}) {
}
// Toggle toggle the mouse, support button:
// "left", "center", "right",
// "wheelDown", "wheelUp", "wheelLeft", "wheelRight"
//
// "left", "center", "right",
// "wheelDown", "wheelUp", "wheelLeft", "wheelRight"
//
// Examples:
//
// robotgo.Toggle("left") // default is down
// robotgo.Toggle("left", "up")
func Toggle(key ...string) error {
@ -749,6 +765,7 @@ func MouseUp(key ...string) error {
// robotgo.Scroll(x, y, msDelay int)
//
// Examples:
//
// robotgo.Scroll(10, 10)
func Scroll(x, y int, args ...int) {
var msDelay = 10
@ -763,16 +780,17 @@ func Scroll(x, y int, args ...int) {
MilliSleep(MouseSleep + msDelay)
}
// ScrollMouse scroll the mouse to (x, "up")
// ScrollDir scroll the mouse with direction to (x, "up")
// supported: "up", "down", "left", "right"
//
// Examples:
// robotgo.ScrollMouse(10, "down")
// robotgo.ScrollMouse(10, "up")
func ScrollMouse(x int, direction ...string) {
//
// robotgo.ScrollDir(10, "down")
// robotgo.ScrollDir(10, "up")
func ScrollDir(x int, direction ...interface{}) {
d := "down"
if len(direction) > 0 {
d = direction[0]
d = direction[0].(string)
}
if d == "down" {
@ -797,6 +815,7 @@ func ScrollMouse(x int, direction ...string) {
// robotgo.ScrollSmooth(toy, num, sleep, tox)
//
// Examples:
//
// robotgo.ScrollSmooth(-10)
// robotgo.ScrollSmooth(-10, 6, 200, -10)
func ScrollSmooth(to int, args ...int) {
@ -828,6 +847,7 @@ func ScrollSmooth(to int, args ...int) {
// ScrollRelative scroll mouse with relative
//
// Examples:
//
// robotgo.ScrollRelative(10, 10)
func ScrollRelative(x, y int, args ...int) {
mx, my := MoveArgs(x, y)
@ -987,7 +1007,7 @@ func GetHandle() int {
// Deprecated: use the GetHandle(),
//
// GetBHandle get the window handle, Wno-deprecated
// # GetBHandle get the window handle, Wno-deprecated
//
// This function will be removed in version v1.0.0
func GetBHandle() int {
@ -1008,6 +1028,7 @@ func cgetTitle(hwnd, isHwnd int32) string {
// GetTitle get the window title return string
//
// Examples:
//
// fmt.Println(robotgo.GetTitle())
//
// ids, _ := robotgo.FindIds()
@ -1026,8 +1047,8 @@ func GetTitle(args ...int32) string {
return internalGetTitle(args[0])
}
// GetPID get the process id return int32
func GetPID() int32 {
// GetPid get the process id return int32
func GetPid() int32 {
pid := C.get_PID()
return int32(pid)
}
@ -1054,9 +1075,9 @@ func internalActive(pid int32, hwnd int) {
C.active_PID(C.uintptr(pid), C.uintptr(hwnd))
}
// ActivePID active the window by PID,
// ActivePid active the window by Pid,
// If args[0] > 0 on the Windows platform via a window handle to active
// func ActivePID(pid int32, args ...int) {
// func ActivePid(pid int32, args ...int) {
// var hwnd int
// if len(args) > 0 {
// hwnd = args[0]
@ -1068,11 +1089,12 @@ func internalActive(pid int32, hwnd int) {
// ActiveName active the window by name
//
// Examples:
// robotgo.ActiveName("chrome")
//
// robotgo.ActiveName("chrome")
func ActiveName(name string) error {
pids, err := FindIds(name)
if err == nil && len(pids) > 0 {
return ActivePID(pids[0])
return ActivePid(pids[0])
}
return err

View File

@ -18,7 +18,7 @@ package robotgo
*/
import "C"
// GetMianId get the main display id
// GetMainId get the main display id
func GetMainId() int {
return int(C.CGMainDisplayID())
}

View File

@ -44,14 +44,15 @@ func internalGetTitle(pid int32, args ...int32) string {
return gtitle
}
// ActivePID active the window by PID,
// ActivePid active the window by PID,
//
// If args[0] > 0 on the Windows platform via a window handle to active
//
// Examples:
//
// ids, _ := robotgo.FindIds()
// robotgo.ActivePID(ids[0])
func ActivePID(pid int32, args ...int) error {
// robotgo.ActivePid(ids[0])
func ActivePid(pid int32, args ...int) error {
var hwnd int
if len(args) > 0 {
hwnd = args[0]
@ -71,6 +72,7 @@ func DisplaysNum() int {
// If cancel button is not given, only the default button is displayed
//
// Examples:
//
// robotgo.Alert("hi", "window", "ok", "cancel")
func Alert(title, msg string, args ...string) bool {
return showAlert(title, msg, args...)

View File

@ -68,8 +68,8 @@ func TestDragMouse(t *testing.T) {
}
func TestScrollMouse(t *testing.T) {
ScrollMouse(120, "up")
ScrollMouse(100, "right")
ScrollDir(120, "up")
ScrollDir(100, "right")
Scroll(0, 120)
MilliSleep(100)

View File

@ -57,7 +57,7 @@ func GetMain() win.HWND {
return win.GetActiveWindow()
}
// GetMianId get the main display id
// GetMainId get the main display id
func GetMainId() int {
return int(GetMain())
}

View File

@ -34,7 +34,7 @@ func GetBounds(pid int32, args ...int) (int, int, int, int) {
return internalGetBounds(pid, hwnd)
}
xid, err := GetXId(xu, pid)
xid, err := GetXid(xu, pid)
if err != nil {
log.Println("Get Xid from Pid errors is: ", err)
return 0, 0, 0, 0
@ -51,7 +51,7 @@ func GetClient(pid int32, args ...int) (int, int, int, int) {
return internalGetClient(pid, hwnd)
}
xid, err := GetXId(xu, pid)
xid, err := GetXid(xu, pid)
if err != nil {
log.Println("Get Xid from Pid errors is: ", err)
return 0, 0, 0, 0
@ -68,7 +68,7 @@ func internalGetTitle(pid int32, args ...int32) string {
return cgetTitle(pid, hwnd)
}
xid, err := GetXId(xu, pid)
xid, err := GetXid(xu, pid)
if err != nil {
log.Println("Get Xid from Pid errors is: ", err)
return ""
@ -77,9 +77,9 @@ func internalGetTitle(pid int32, args ...int32) string {
return cgetTitle(int32(xid), hwnd)
}
// ActivePIDC active the window by PID,
// ActivePidC active the window by Pid,
// If args[0] > 0 on the unix platform via a xid to active
func ActivePIDC(pid int32, args ...int) error {
func ActivePidC(pid int32, args ...int) error {
var hwnd int
if len(args) > 0 {
hwnd = args[0]
@ -87,7 +87,7 @@ func ActivePIDC(pid int32, args ...int) error {
return nil
}
xid, err := GetXId(xu, pid)
xid, err := GetXid(xu, pid)
if err != nil {
log.Println("Get Xid from Pid errors is: ", err)
return err
@ -97,11 +97,11 @@ func ActivePIDC(pid int32, args ...int) error {
return nil
}
// ActivePID active the window by PID,
// 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 ActivePID(pid int32, args ...int) error {
func ActivePid(pid int32, args ...int) error {
if xu == nil {
var err error
xu, err = xgbutil.NewConn()
@ -133,8 +133,8 @@ func ActivePID(pid int32, args ...int) error {
return nil
}
// GetXId get the xid return window and error
func GetXId(xu *xgbutil.XUtil, pid int32) (xproto.Window, error) {
// GetXid get the xid return window and error
func GetXid(xu *xgbutil.XUtil, pid int32) (xproto.Window, error) {
if xu == nil {
var err error
xu, err = xgbutil.NewConn()
@ -148,7 +148,7 @@ func GetXId(xu *xgbutil.XUtil, pid int32) (xproto.Window, error) {
return xid, err
}
// GetXidFromPid get the xide from pid
// GetXidFromPid get the xid from pid
func GetXidFromPid(xu *xgbutil.XUtil, pid int32) (xproto.Window, error) {
windows, err := ewmh.ClientListGet(xu)
if err != nil {
@ -214,6 +214,7 @@ func GetMainId() int {
// If cancel button is not given, only the default button is displayed
//
// Examples:
//
// robotgo.Alert("hi", "window", "ok", "cancel")
func Alert(title, msg string, args ...string) bool {
defaultBtn, cancelBtn := alertArgs(args...)

View File

@ -99,7 +99,7 @@ uint32_t get_num_displays() {
uintptr get_hwnd_by_pid(uintptr pid) {
#if defined(IS_WINDOWS)
HWND hwnd = GetHwndByPId(pid);
HWND hwnd = GetHwndByPid(pid);
return (uintptr)hwnd;
#else
return 0;

View File

@ -24,7 +24,7 @@ void min_window(uintptr pid, bool state, uintptr isHwnd){
// SetState((Window)pid, STATE_MINIMIZE, state);
#elif defined(IS_WINDOWS)
if (isHwnd == 0) {
HWND hwnd = GetHwndByPId(pid);
HWND hwnd = GetHwndByPid(pid);
win_min(hwnd, state);
} else {
win_min((HWND)pid, state);
@ -41,7 +41,7 @@ void max_window(uintptr pid, bool state, uintptr isHwnd){
// SetState((Window)pid, STATE_MAXIMIZE, state);
#elif defined(IS_WINDOWS)
if (isHwnd == 0) {
HWND hwnd = GetHwndByPId(pid);
HWND hwnd = GetHwndByPid(pid);
win_max(hwnd, state);
} else {
win_max((HWND)pid, state);

View File

@ -130,7 +130,7 @@ Bounds get_bounds(uintptr pid, uintptr isHwnd){
#elif defined(IS_WINDOWS)
HWND hwnd;
if (isHwnd == 0) {
hwnd= GetHwndByPId(pid);
hwnd= GetHwndByPid(pid);
} else {
hwnd = (HWND)pid;
}
@ -195,7 +195,7 @@ Bounds get_client(uintptr pid, uintptr isHwnd) {
#elif defined(IS_WINDOWS)
HWND hwnd;
if (isHwnd == 0) {
hwnd = GetHwndByPId(pid);
hwnd = GetHwndByPid(pid);
} else {
hwnd = (HWND)pid;
}

View File

@ -60,7 +60,7 @@ MData set_handle_pid(uintptr pid, uintptr isHwnd){
#elif defined(IS_WINDOWS)
// win.HWnd = (HWND)pid; // Handle to a window HWND
if (isHwnd == 0) {
win.HWnd = GetHwndByPId(pid);
win.HWnd = GetHwndByPid(pid);
} else {
win.HWnd = (HWND)pid;
}