mirror of
https://github.com/go-vgo/robotgo.git
synced 2025-05-30 22:13:54 +00:00
Merge pull request #539 from go-vgo/bitmap-pr
Unified name and Update godoc, fixed typo
This commit is contained in:
commit
fc5dac6f8a
14
README.md
14
README.md
@ -53,7 +53,7 @@ Golang
|
|||||||
GCC
|
GCC
|
||||||
```
|
```
|
||||||
|
|
||||||
#### For Mac OS X:
|
#### For MacOS:
|
||||||
|
|
||||||
Xcode Command Line Tools (And Privacy setting: [#277](https://github.com/go-vgo/robotgo/issues/277) )
|
Xcode Command Line Tools (And Privacy setting: [#277](https://github.com/go-vgo/robotgo/issues/277) )
|
||||||
|
|
||||||
@ -163,8 +163,8 @@ import (
|
|||||||
func main() {
|
func main() {
|
||||||
robotgo.MouseSleep = 100
|
robotgo.MouseSleep = 100
|
||||||
|
|
||||||
robotgo.ScrollMouse(10, "up")
|
robotgo.ScrollDir(10, "up")
|
||||||
robotgo.ScrollMouse(20, "right")
|
robotgo.ScrollDir(20, "right")
|
||||||
|
|
||||||
robotgo.Scroll(0, -10)
|
robotgo.Scroll(0, -10)
|
||||||
robotgo.Scroll(100, 0)
|
robotgo.Scroll(100, 0)
|
||||||
@ -242,7 +242,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
x, y := robotgo.GetMousePos()
|
x, y := robotgo.Location()
|
||||||
fmt.Println("pos: ", x, y)
|
fmt.Println("pos: ", x, y)
|
||||||
|
|
||||||
color := robotgo.GetPixelColor(100, 200)
|
color := robotgo.GetPixelColor(100, 200)
|
||||||
@ -455,7 +455,7 @@ func main() {
|
|||||||
robotgo.KeyToggle("a", fpid[0])
|
robotgo.KeyToggle("a", fpid[0])
|
||||||
robotgo.KeyToggle("a", fpid[0], "up")
|
robotgo.KeyToggle("a", fpid[0], "up")
|
||||||
|
|
||||||
robotgo.ActivePID(fpid[0])
|
robotgo.ActivePid(fpid[0])
|
||||||
|
|
||||||
robotgo.Kill(fpid[0])
|
robotgo.Kill(fpid[0])
|
||||||
}
|
}
|
||||||
@ -519,9 +519,9 @@ Some discussions and questions, please see [issues/228](https://github.com/go-vg
|
|||||||
## Plans
|
## Plans
|
||||||
- Refactor some C code to Go (such as x11, windows)
|
- Refactor some C code to Go (such as x11, windows)
|
||||||
- Better multiscreen support
|
- Better multiscreen support
|
||||||
- Waylad supports
|
- Wayland support
|
||||||
- Update Window Handle
|
- Update Window Handle
|
||||||
- Try support Android and IOS
|
- Try to support Android and IOS
|
||||||
|
|
||||||
## Contributors
|
## Contributors
|
||||||
|
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
# Robotgo
|
# Robotgo
|
||||||
|
|
||||||
|
## !!! Warning: this page not updated !!!
|
||||||
|
|
||||||
[](https://github.com/go-vgo/robotgo/commits/master)
|
[](https://github.com/go-vgo/robotgo/commits/master)
|
||||||
[](https://circleci.com/gh/go-vgo/robotgo)
|
[](https://circleci.com/gh/go-vgo/robotgo)
|
||||||
[](https://travis-ci.org/go-vgo/robotgo)
|
[](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 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 等其他系统):
|
#### For everything else (Linux 等其他系统):
|
||||||
|
@ -22,12 +22,12 @@
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
HWND GetHwndByPId(DWORD dwProcessId) {
|
HWND GetHwndByPid(DWORD dwProcessId) {
|
||||||
WNDINFO info = {0};
|
WNDINFO info = {0};
|
||||||
info.hWnd = NULL;
|
info.hWnd = NULL;
|
||||||
info.dwPid = dwProcessId;
|
info.dwPid = dwProcessId;
|
||||||
EnumWindows(EnumWindowsProc, (LPARAM)&info);
|
EnumWindows(EnumWindowsProc, (LPARAM)&info);
|
||||||
// printf("%d\n", info.hWnd);
|
|
||||||
return info.hWnd;
|
return info.hWnd;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
@ -55,7 +55,7 @@ func click() {
|
|||||||
|
|
||||||
func get() {
|
func get() {
|
||||||
// gets the mouse coordinates
|
// gets the mouse coordinates
|
||||||
x, y := robotgo.GetMousePos()
|
x, y := robotgo.Location()
|
||||||
fmt.Println("pos:", x, y)
|
fmt.Println("pos:", x, y)
|
||||||
if x == 456 && y == 586 {
|
if x == 456 && y == 586 {
|
||||||
fmt.Println("mouse...", "586")
|
fmt.Println("mouse...", "586")
|
||||||
@ -66,8 +66,8 @@ func get() {
|
|||||||
|
|
||||||
func toggleAndScroll() {
|
func toggleAndScroll() {
|
||||||
// scrolls the mouse either up
|
// scrolls the mouse either up
|
||||||
robotgo.ScrollMouse(10, "up")
|
robotgo.ScrollDir(10, "up")
|
||||||
robotgo.ScrollMouse(10, "right")
|
robotgo.ScrollDir(10, "right")
|
||||||
|
|
||||||
robotgo.Scroll(100, 10)
|
robotgo.Scroll(100, 10)
|
||||||
robotgo.Scroll(0, -10)
|
robotgo.Scroll(0, -10)
|
||||||
|
@ -28,7 +28,7 @@ func alert() {
|
|||||||
|
|
||||||
func get() {
|
func get() {
|
||||||
// get the current process id
|
// get the current process id
|
||||||
pid := robotgo.GetPID()
|
pid := robotgo.GetPid()
|
||||||
fmt.Println("pid----", pid)
|
fmt.Println("pid----", pid)
|
||||||
|
|
||||||
// get current Window Active
|
// get current Window Active
|
||||||
@ -64,7 +64,7 @@ func findIds() {
|
|||||||
|
|
||||||
fmt.Println("pids...", fpid)
|
fmt.Println("pids...", fpid)
|
||||||
if len(fpid) > 0 {
|
if len(fpid) > 0 {
|
||||||
err = robotgo.ActivePID(fpid[0])
|
err = robotgo.ActivePid(fpid[0])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
}
|
}
|
||||||
@ -87,7 +87,7 @@ func findIds() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func active() {
|
func active() {
|
||||||
robotgo.ActivePID(100)
|
robotgo.ActivePid(100)
|
||||||
// robotgo.Sleep(2)
|
// robotgo.Sleep(2)
|
||||||
robotgo.ActiveName("code")
|
robotgo.ActiveName("code")
|
||||||
robotgo.Sleep(1)
|
robotgo.Sleep(1)
|
||||||
|
28
key.go
28
key.go
@ -201,7 +201,7 @@ const (
|
|||||||
LightsKbdDown = "lights_kbd_down"
|
LightsKbdDown = "lights_kbd_down"
|
||||||
)
|
)
|
||||||
|
|
||||||
// keyNames define MMKeyCode map
|
// keyNames define a map of key names to MMKeyCode
|
||||||
var keyNames = map[string]C.MMKeyCode{
|
var keyNames = map[string]C.MMKeyCode{
|
||||||
"backspace": C.K_BACKSPACE,
|
"backspace": C.K_BACKSPACE,
|
||||||
"delete": C.K_DELETE,
|
"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{} {
|
func ToInterfaces(fields []string) []interface{} {
|
||||||
res := make([]interface{}, 0, len(fields))
|
res := make([]interface{}, 0, len(fields))
|
||||||
for _, s := range fields {
|
for _, s := range fields {
|
||||||
@ -450,7 +450,7 @@ func ToInterfaces(fields []string) []interface{} {
|
|||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
// ToStrings []interface{} to []string
|
// ToStrings convert []interface{} to []string
|
||||||
func ToStrings(fields []interface{}) []string {
|
func ToStrings(fields []interface{}) []string {
|
||||||
res := make([]string, 0, len(fields))
|
res := make([]string, 0, len(fields))
|
||||||
for _, s := range fields {
|
for _, s := range fields {
|
||||||
@ -467,19 +467,20 @@ func toErr(str *C.char) error {
|
|||||||
return errors.New(gstr)
|
return errors.New(gstr)
|
||||||
}
|
}
|
||||||
|
|
||||||
// KeyTap tap the keyboard code;
|
// KeyTap taps the keyboard code;
|
||||||
//
|
//
|
||||||
// See keys:
|
// See keys:
|
||||||
|
//
|
||||||
// https://github.com/go-vgo/robotgo/blob/master/docs/keys.md
|
// https://github.com/go-vgo/robotgo/blob/master/docs/keys.md
|
||||||
//
|
//
|
||||||
// Examples:
|
// Examples:
|
||||||
|
//
|
||||||
// robotgo.KeySleep = 100 // 100 millisecond
|
// robotgo.KeySleep = 100 // 100 millisecond
|
||||||
// robotgo.KeyTap("a")
|
// robotgo.KeyTap("a")
|
||||||
// robotgo.KeyTap("i", "alt", "command")
|
// robotgo.KeyTap("i", "alt", "command")
|
||||||
//
|
//
|
||||||
// arr := []string{"alt", "command"}
|
// arr := []string{"alt", "command"}
|
||||||
// robotgo.KeyTap("i", arr)
|
// robotgo.KeyTap("i", arr)
|
||||||
//
|
|
||||||
func KeyTap(key string, args ...interface{}) error {
|
func KeyTap(key string, args ...interface{}) error {
|
||||||
var keyArr []string
|
var keyArr []string
|
||||||
|
|
||||||
@ -512,17 +513,18 @@ func KeyTap(key string, args ...interface{}) error {
|
|||||||
return keyTaps(key, keyArr, pid)
|
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:
|
// See keys:
|
||||||
|
//
|
||||||
// https://github.com/go-vgo/robotgo/blob/master/docs/keys.md
|
// https://github.com/go-vgo/robotgo/blob/master/docs/keys.md
|
||||||
//
|
//
|
||||||
// Examples:
|
// Examples:
|
||||||
|
//
|
||||||
// robotgo.KeyToggle("a")
|
// robotgo.KeyToggle("a")
|
||||||
// robotgo.KeyToggle("a", "up")
|
// robotgo.KeyToggle("a", "up")
|
||||||
//
|
//
|
||||||
// robotgo.KeyToggle("a", "up", "alt", "cmd")
|
// robotgo.KeyToggle("a", "up", "alt", "cmd")
|
||||||
//
|
|
||||||
func KeyToggle(key string, args ...interface{}) error {
|
func KeyToggle(key string, args ...interface{}) error {
|
||||||
|
|
||||||
if len(key) > 0 && unicode.IsUpper([]rune(key)[0]) {
|
if len(key) > 0 && unicode.IsUpper([]rune(key)[0]) {
|
||||||
@ -633,13 +635,13 @@ func inputUTF(str string) {
|
|||||||
C.free(unsafe.Pointer(cstr))
|
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")
|
// robotgo.TypeStr(string: "The string to send", int: pid, "milli_sleep time", "x11 option")
|
||||||
//
|
//
|
||||||
// Examples:
|
// Examples:
|
||||||
// robotgo.TypeStr("abc@123, Hi galaxy, こんにちは")
|
|
||||||
//
|
//
|
||||||
|
// robotgo.TypeStr("abc@123, Hi galaxy, こんにちは")
|
||||||
func TypeStr(str string, args ...int) {
|
func TypeStr(str string, args ...int) {
|
||||||
var tm, tm1 = 0, 7
|
var tm, tm1 = 0, 7
|
||||||
|
|
||||||
@ -681,7 +683,7 @@ func TypeStr(str string, args ...int) {
|
|||||||
MilliSleep(KeySleep)
|
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`
|
// write the string to clipboard and tap `cmd + v`
|
||||||
func PasteStr(str string) error {
|
func PasteStr(str string) error {
|
||||||
err := clipboard.WriteAll(str)
|
err := clipboard.WriteAll(str)
|
||||||
@ -696,7 +698,7 @@ func PasteStr(str string) error {
|
|||||||
return KeyTap("v", "control")
|
return KeyTap("v", "control")
|
||||||
}
|
}
|
||||||
|
|
||||||
// TypeStrDelay type string delayed
|
// TypeStrDelay type string with delayed
|
||||||
func TypeStrDelay(str string, delay int) {
|
func TypeStrDelay(str string, delay int) {
|
||||||
TypeStr(str)
|
TypeStr(str)
|
||||||
MilliSleep(delay)
|
MilliSleep(delay)
|
||||||
@ -704,7 +706,7 @@ func TypeStrDelay(str string, delay int) {
|
|||||||
|
|
||||||
// Deprecated: use the TypeStr(),
|
// 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
|
// This function will be removed in version v1.0.0
|
||||||
func TypeStringDelayed(str string, delay int) {
|
func TypeStringDelayed(str string, delay int) {
|
||||||
@ -712,7 +714,7 @@ func TypeStringDelayed(str string, delay int) {
|
|||||||
TypeStrDelay(str, delay)
|
TypeStrDelay(str, delay)
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetDelay set the key and mouse delay
|
// SetDelay sets the key and mouse delay
|
||||||
func SetDelay(d ...int) {
|
func SetDelay(d ...int) {
|
||||||
v := 10
|
v := 10
|
||||||
if len(d) > 0 {
|
if len(d) > 0 {
|
||||||
|
@ -192,7 +192,7 @@ void clickMouse(MMMouseButton button){
|
|||||||
toggleMouse(false, 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){
|
void doubleClick(MMMouseButton button){
|
||||||
#if defined(IS_MACOSX)
|
#if defined(IS_MACOSX)
|
||||||
/* Double click for Mac. */
|
/* Double click for Mac. */
|
||||||
|
@ -33,6 +33,9 @@ func TestGetScreenSize(t *testing.T) {
|
|||||||
|
|
||||||
rect := robotgo.GetScreenRect()
|
rect := robotgo.GetScreenRect()
|
||||||
fmt.Println("Get screen rect: ", rect)
|
fmt.Println("Get screen rect: ", rect)
|
||||||
|
|
||||||
|
x, y = robotgo.Location()
|
||||||
|
fmt.Println("Get location: ", x, y)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGetSysScale(t *testing.T) {
|
func TestGetSysScale(t *testing.T) {
|
||||||
|
66
robotgo.go
66
robotgo.go
@ -9,20 +9,22 @@
|
|||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
||||||
Package robotgo Go native cross-platform system automation.
|
Package robotgo Go native cross-platform system automation.
|
||||||
|
|
||||||
Please make sure Golang, GCC is installed correctly before installing RobotGo;
|
Please make sure Golang, GCC is installed correctly before installing RobotGo;
|
||||||
|
|
||||||
See Requirements:
|
See Requirements:
|
||||||
|
|
||||||
https://github.com/go-vgo/robotgo#requirements
|
https://github.com/go-vgo/robotgo#requirements
|
||||||
|
|
||||||
Installation:
|
Installation:
|
||||||
|
|
||||||
With Go module support (Go 1.11+), just import:
|
With Go module support (Go 1.11+), just import:
|
||||||
|
|
||||||
import "github.com/go-vgo/robotgo"
|
import "github.com/go-vgo/robotgo"
|
||||||
|
|
||||||
Otherwise, to install the robotgo package, run the command:
|
Otherwise, to install the robotgo package, run the command:
|
||||||
|
|
||||||
go get -u github.com/go-vgo/robotgo
|
go get -u github.com/go-vgo/robotgo
|
||||||
*/
|
*/
|
||||||
package robotgo
|
package robotgo
|
||||||
@ -236,8 +238,8 @@ func getNumDisplays() int {
|
|||||||
return int(C.get_num_displays())
|
return int(C.get_num_displays())
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetHwndByPId get the hwnd by pid
|
// GetHWNDByPid get the hwnd by pid
|
||||||
func GetHwndByPId(pid int) int {
|
func GetHWNDByPid(pid int) int {
|
||||||
return int(C.get_hwnd_by_pid(C.uintptr(pid)))
|
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)
|
// Move move the mouse to (x, y)
|
||||||
//
|
//
|
||||||
// Examples:
|
// Examples:
|
||||||
// robotgo.MouseSleep = 100 // 100 millisecond
|
//
|
||||||
// robotgo.Move(10, 10)
|
// robotgo.MouseSleep = 100 // 100 millisecond
|
||||||
|
// robotgo.Move(10, 10)
|
||||||
func Move(x, y int) {
|
func Move(x, y int) {
|
||||||
// if runtime.GOOS == "windows" {
|
// if runtime.GOOS == "windows" {
|
||||||
// f := ScaleF()
|
// f := ScaleF()
|
||||||
@ -560,6 +563,7 @@ func Drag(x, y int, args ...string) {
|
|||||||
// DragSmooth drag the mouse like smooth to (x, y)
|
// DragSmooth drag the mouse like smooth to (x, y)
|
||||||
//
|
//
|
||||||
// Examples:
|
// Examples:
|
||||||
|
//
|
||||||
// robotgo.DragSmooth(10, 10)
|
// robotgo.DragSmooth(10, 10)
|
||||||
func DragSmooth(x, y int, args ...interface{}) {
|
func DragSmooth(x, y int, args ...interface{}) {
|
||||||
Toggle("left")
|
Toggle("left")
|
||||||
@ -582,6 +586,7 @@ func MoveMouseSmooth(x, y int, args ...interface{}) bool {
|
|||||||
// robotgo.MoveSmooth(x, y int, low, high float64, mouseDelay int)
|
// robotgo.MoveSmooth(x, y int, low, high float64, mouseDelay int)
|
||||||
//
|
//
|
||||||
// Examples:
|
// Examples:
|
||||||
|
//
|
||||||
// robotgo.MoveSmooth(10, 10)
|
// robotgo.MoveSmooth(10, 10)
|
||||||
// robotgo.MoveSmooth(10, 10, 1.0, 2.0)
|
// robotgo.MoveSmooth(10, 10, 1.0, 2.0)
|
||||||
func MoveSmooth(x, y int, args ...interface{}) bool {
|
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
|
// MoveArgs get the mouse relative args
|
||||||
func MoveArgs(x, y int) (int, int) {
|
func MoveArgs(x, y int) (int, int) {
|
||||||
mx, my := GetMousePos()
|
mx, my := Location()
|
||||||
mx = mx + x
|
mx = mx + x
|
||||||
my = my + y
|
my = my + y
|
||||||
|
|
||||||
@ -637,8 +642,15 @@ func MoveSmoothRelative(x, y int, args ...interface{}) {
|
|||||||
MoveSmooth(mx, my, args...)
|
MoveSmooth(mx, my, args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Deprecated: use the function Location()
|
||||||
|
//
|
||||||
// GetMousePos get the mouse's position return x, y
|
// GetMousePos get the mouse's position return x, y
|
||||||
func GetMousePos() (int, int) {
|
func GetMousePos() (int, int) {
|
||||||
|
return Location()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Location get the mouse location position return x, y
|
||||||
|
func Location() (int, int) {
|
||||||
pos := C.getMousePos()
|
pos := C.getMousePos()
|
||||||
x := int(pos.x)
|
x := int(pos.x)
|
||||||
y := int(pos.y)
|
y := int(pos.y)
|
||||||
@ -648,7 +660,7 @@ func GetMousePos() (int, int) {
|
|||||||
|
|
||||||
// Deprecated: use the Click(),
|
// Deprecated: use the Click(),
|
||||||
//
|
//
|
||||||
// MouseClick click the mouse
|
// # MouseClick click the mouse
|
||||||
//
|
//
|
||||||
// robotgo.MouseClick(button string, double bool)
|
// robotgo.MouseClick(button string, double bool)
|
||||||
func MouseClick(args ...interface{}) {
|
func MouseClick(args ...interface{}) {
|
||||||
@ -660,7 +672,8 @@ func MouseClick(args ...interface{}) {
|
|||||||
// robotgo.Click(button string, double bool)
|
// robotgo.Click(button string, double bool)
|
||||||
//
|
//
|
||||||
// Examples:
|
// Examples:
|
||||||
// robotgo.Click() // default is left button
|
//
|
||||||
|
// robotgo.Click() // default is left button
|
||||||
// robotgo.Click("right")
|
// robotgo.Click("right")
|
||||||
// robotgo.Click("wheelLeft")
|
// robotgo.Click("wheelLeft")
|
||||||
func Click(args ...interface{}) {
|
func Click(args ...interface{}) {
|
||||||
@ -691,6 +704,7 @@ func Click(args ...interface{}) {
|
|||||||
// robotgo.MoveClick(x, y int, button string, double bool)
|
// robotgo.MoveClick(x, y int, button string, double bool)
|
||||||
//
|
//
|
||||||
// Examples:
|
// Examples:
|
||||||
|
//
|
||||||
// robotgo.MouseSleep = 100
|
// robotgo.MouseSleep = 100
|
||||||
// robotgo.MoveClick(10, 10)
|
// robotgo.MoveClick(10, 10)
|
||||||
func MoveClick(x, y int, args ...interface{}) {
|
func MoveClick(x, y int, args ...interface{}) {
|
||||||
@ -709,10 +723,12 @@ func MovesClick(x, y int, args ...interface{}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Toggle toggle the mouse, support button:
|
// Toggle toggle the mouse, support button:
|
||||||
// "left", "center", "right",
|
//
|
||||||
// "wheelDown", "wheelUp", "wheelLeft", "wheelRight"
|
// "left", "center", "right",
|
||||||
|
// "wheelDown", "wheelUp", "wheelLeft", "wheelRight"
|
||||||
//
|
//
|
||||||
// Examples:
|
// Examples:
|
||||||
|
//
|
||||||
// robotgo.Toggle("left") // default is down
|
// robotgo.Toggle("left") // default is down
|
||||||
// robotgo.Toggle("left", "up")
|
// robotgo.Toggle("left", "up")
|
||||||
func Toggle(key ...string) error {
|
func Toggle(key ...string) error {
|
||||||
@ -749,6 +765,7 @@ func MouseUp(key ...string) error {
|
|||||||
// robotgo.Scroll(x, y, msDelay int)
|
// robotgo.Scroll(x, y, msDelay int)
|
||||||
//
|
//
|
||||||
// Examples:
|
// Examples:
|
||||||
|
//
|
||||||
// robotgo.Scroll(10, 10)
|
// robotgo.Scroll(10, 10)
|
||||||
func Scroll(x, y int, args ...int) {
|
func Scroll(x, y int, args ...int) {
|
||||||
var msDelay = 10
|
var msDelay = 10
|
||||||
@ -763,16 +780,17 @@ func Scroll(x, y int, args ...int) {
|
|||||||
MilliSleep(MouseSleep + msDelay)
|
MilliSleep(MouseSleep + msDelay)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ScrollMouse scroll the mouse to (x, "up")
|
// ScrollDir scroll the mouse with direction to (x, "up")
|
||||||
// supported: "up", "down", "left", "right"
|
// supported: "up", "down", "left", "right"
|
||||||
//
|
//
|
||||||
// Examples:
|
// Examples:
|
||||||
// robotgo.ScrollMouse(10, "down")
|
//
|
||||||
// robotgo.ScrollMouse(10, "up")
|
// robotgo.ScrollDir(10, "down")
|
||||||
func ScrollMouse(x int, direction ...string) {
|
// robotgo.ScrollDir(10, "up")
|
||||||
|
func ScrollDir(x int, direction ...interface{}) {
|
||||||
d := "down"
|
d := "down"
|
||||||
if len(direction) > 0 {
|
if len(direction) > 0 {
|
||||||
d = direction[0]
|
d = direction[0].(string)
|
||||||
}
|
}
|
||||||
|
|
||||||
if d == "down" {
|
if d == "down" {
|
||||||
@ -797,6 +815,7 @@ func ScrollMouse(x int, direction ...string) {
|
|||||||
// robotgo.ScrollSmooth(toy, num, sleep, tox)
|
// robotgo.ScrollSmooth(toy, num, sleep, tox)
|
||||||
//
|
//
|
||||||
// Examples:
|
// Examples:
|
||||||
|
//
|
||||||
// robotgo.ScrollSmooth(-10)
|
// robotgo.ScrollSmooth(-10)
|
||||||
// robotgo.ScrollSmooth(-10, 6, 200, -10)
|
// robotgo.ScrollSmooth(-10, 6, 200, -10)
|
||||||
func ScrollSmooth(to int, args ...int) {
|
func ScrollSmooth(to int, args ...int) {
|
||||||
@ -828,6 +847,7 @@ func ScrollSmooth(to int, args ...int) {
|
|||||||
// ScrollRelative scroll mouse with relative
|
// ScrollRelative scroll mouse with relative
|
||||||
//
|
//
|
||||||
// Examples:
|
// Examples:
|
||||||
|
//
|
||||||
// robotgo.ScrollRelative(10, 10)
|
// robotgo.ScrollRelative(10, 10)
|
||||||
func ScrollRelative(x, y int, args ...int) {
|
func ScrollRelative(x, y int, args ...int) {
|
||||||
mx, my := MoveArgs(x, y)
|
mx, my := MoveArgs(x, y)
|
||||||
@ -987,7 +1007,7 @@ func GetHandle() int {
|
|||||||
|
|
||||||
// Deprecated: use the GetHandle(),
|
// 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
|
// This function will be removed in version v1.0.0
|
||||||
func GetBHandle() int {
|
func GetBHandle() int {
|
||||||
@ -1008,6 +1028,7 @@ func cgetTitle(hwnd, isHwnd int32) string {
|
|||||||
// GetTitle get the window title return string
|
// GetTitle get the window title return string
|
||||||
//
|
//
|
||||||
// Examples:
|
// Examples:
|
||||||
|
//
|
||||||
// fmt.Println(robotgo.GetTitle())
|
// fmt.Println(robotgo.GetTitle())
|
||||||
//
|
//
|
||||||
// ids, _ := robotgo.FindIds()
|
// ids, _ := robotgo.FindIds()
|
||||||
@ -1026,8 +1047,8 @@ func GetTitle(args ...int32) string {
|
|||||||
return internalGetTitle(args[0])
|
return internalGetTitle(args[0])
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetPID get the process id return int32
|
// GetPid get the process id return int32
|
||||||
func GetPID() int32 {
|
func GetPid() int32 {
|
||||||
pid := C.get_PID()
|
pid := C.get_PID()
|
||||||
return int32(pid)
|
return int32(pid)
|
||||||
}
|
}
|
||||||
@ -1054,9 +1075,9 @@ func internalActive(pid int32, hwnd int) {
|
|||||||
C.active_PID(C.uintptr(pid), C.uintptr(hwnd))
|
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
|
// 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
|
// var hwnd int
|
||||||
// if len(args) > 0 {
|
// if len(args) > 0 {
|
||||||
// hwnd = args[0]
|
// hwnd = args[0]
|
||||||
@ -1068,11 +1089,12 @@ func internalActive(pid int32, hwnd int) {
|
|||||||
// ActiveName active the window by name
|
// ActiveName active the window by name
|
||||||
//
|
//
|
||||||
// Examples:
|
// Examples:
|
||||||
// robotgo.ActiveName("chrome")
|
//
|
||||||
|
// robotgo.ActiveName("chrome")
|
||||||
func ActiveName(name string) error {
|
func ActiveName(name string) error {
|
||||||
pids, err := FindIds(name)
|
pids, err := FindIds(name)
|
||||||
if err == nil && len(pids) > 0 {
|
if err == nil && len(pids) > 0 {
|
||||||
return ActivePID(pids[0])
|
return ActivePid(pids[0])
|
||||||
}
|
}
|
||||||
|
|
||||||
return err
|
return err
|
||||||
|
@ -18,7 +18,7 @@ package robotgo
|
|||||||
*/
|
*/
|
||||||
import "C"
|
import "C"
|
||||||
|
|
||||||
// GetMianId get the main display id
|
// GetMainId get the main display id
|
||||||
func GetMainId() int {
|
func GetMainId() int {
|
||||||
return int(C.CGMainDisplayID())
|
return int(C.CGMainDisplayID())
|
||||||
}
|
}
|
||||||
|
@ -44,14 +44,15 @@ func internalGetTitle(pid int32, args ...int32) string {
|
|||||||
return gtitle
|
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
|
// If args[0] > 0 on the Windows platform via a window handle to active
|
||||||
//
|
//
|
||||||
// Examples:
|
// Examples:
|
||||||
|
//
|
||||||
// ids, _ := robotgo.FindIds()
|
// ids, _ := robotgo.FindIds()
|
||||||
// robotgo.ActivePID(ids[0])
|
// robotgo.ActivePid(ids[0])
|
||||||
func ActivePID(pid int32, args ...int) error {
|
func ActivePid(pid int32, args ...int) error {
|
||||||
var hwnd int
|
var hwnd int
|
||||||
if len(args) > 0 {
|
if len(args) > 0 {
|
||||||
hwnd = args[0]
|
hwnd = args[0]
|
||||||
@ -71,6 +72,7 @@ func DisplaysNum() int {
|
|||||||
// If cancel button is not given, only the default button is displayed
|
// If cancel button is not given, only the default button is displayed
|
||||||
//
|
//
|
||||||
// Examples:
|
// Examples:
|
||||||
|
//
|
||||||
// robotgo.Alert("hi", "window", "ok", "cancel")
|
// robotgo.Alert("hi", "window", "ok", "cancel")
|
||||||
func Alert(title, msg string, args ...string) bool {
|
func Alert(title, msg string, args ...string) bool {
|
||||||
return showAlert(title, msg, args...)
|
return showAlert(title, msg, args...)
|
||||||
|
@ -68,8 +68,8 @@ func TestDragMouse(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestScrollMouse(t *testing.T) {
|
func TestScrollMouse(t *testing.T) {
|
||||||
ScrollMouse(120, "up")
|
ScrollDir(120, "up")
|
||||||
ScrollMouse(100, "right")
|
ScrollDir(100, "right")
|
||||||
|
|
||||||
Scroll(0, 120)
|
Scroll(0, 120)
|
||||||
MilliSleep(100)
|
MilliSleep(100)
|
||||||
|
@ -57,7 +57,7 @@ func GetMain() win.HWND {
|
|||||||
return win.GetActiveWindow()
|
return win.GetActiveWindow()
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetMianId get the main display id
|
// GetMainId get the main display id
|
||||||
func GetMainId() int {
|
func GetMainId() int {
|
||||||
return int(GetMain())
|
return int(GetMain())
|
||||||
}
|
}
|
||||||
|
@ -34,7 +34,7 @@ func GetBounds(pid int32, args ...int) (int, int, int, int) {
|
|||||||
return internalGetBounds(pid, hwnd)
|
return internalGetBounds(pid, hwnd)
|
||||||
}
|
}
|
||||||
|
|
||||||
xid, err := GetXId(xu, pid)
|
xid, err := GetXid(xu, pid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("Get Xid from Pid errors is: ", err)
|
log.Println("Get Xid from Pid errors is: ", err)
|
||||||
return 0, 0, 0, 0
|
return 0, 0, 0, 0
|
||||||
@ -51,7 +51,7 @@ func GetClient(pid int32, args ...int) (int, int, int, int) {
|
|||||||
return internalGetClient(pid, hwnd)
|
return internalGetClient(pid, hwnd)
|
||||||
}
|
}
|
||||||
|
|
||||||
xid, err := GetXId(xu, pid)
|
xid, err := GetXid(xu, pid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("Get Xid from Pid errors is: ", err)
|
log.Println("Get Xid from Pid errors is: ", err)
|
||||||
return 0, 0, 0, 0
|
return 0, 0, 0, 0
|
||||||
@ -68,7 +68,7 @@ func internalGetTitle(pid int32, args ...int32) string {
|
|||||||
return cgetTitle(pid, hwnd)
|
return cgetTitle(pid, hwnd)
|
||||||
}
|
}
|
||||||
|
|
||||||
xid, err := GetXId(xu, pid)
|
xid, err := GetXid(xu, pid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("Get Xid from Pid errors is: ", err)
|
log.Println("Get Xid from Pid errors is: ", err)
|
||||||
return ""
|
return ""
|
||||||
@ -77,9 +77,9 @@ func internalGetTitle(pid int32, args ...int32) string {
|
|||||||
return cgetTitle(int32(xid), hwnd)
|
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
|
// 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
|
var hwnd int
|
||||||
if len(args) > 0 {
|
if len(args) > 0 {
|
||||||
hwnd = args[0]
|
hwnd = args[0]
|
||||||
@ -87,7 +87,7 @@ func ActivePIDC(pid int32, args ...int) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
xid, err := GetXId(xu, pid)
|
xid, err := GetXid(xu, pid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("Get Xid from Pid errors is: ", err)
|
log.Println("Get Xid from Pid errors is: ", err)
|
||||||
return err
|
return err
|
||||||
@ -97,11 +97,11 @@ func ActivePIDC(pid int32, args ...int) error {
|
|||||||
return nil
|
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 Windows platform via a window handle to active,
|
||||||
// If args[0] > 0 on the unix platform via a xid 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 {
|
if xu == nil {
|
||||||
var err error
|
var err error
|
||||||
xu, err = xgbutil.NewConn()
|
xu, err = xgbutil.NewConn()
|
||||||
@ -133,8 +133,8 @@ func ActivePID(pid int32, args ...int) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetXId get the xid return window and error
|
// GetXid get the xid return window and error
|
||||||
func GetXId(xu *xgbutil.XUtil, pid int32) (xproto.Window, error) {
|
func GetXid(xu *xgbutil.XUtil, pid int32) (xproto.Window, error) {
|
||||||
if xu == nil {
|
if xu == nil {
|
||||||
var err error
|
var err error
|
||||||
xu, err = xgbutil.NewConn()
|
xu, err = xgbutil.NewConn()
|
||||||
@ -148,7 +148,7 @@ func GetXId(xu *xgbutil.XUtil, pid int32) (xproto.Window, error) {
|
|||||||
return xid, err
|
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) {
|
func GetXidFromPid(xu *xgbutil.XUtil, pid int32) (xproto.Window, error) {
|
||||||
windows, err := ewmh.ClientListGet(xu)
|
windows, err := ewmh.ClientListGet(xu)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -214,6 +214,7 @@ func GetMainId() int {
|
|||||||
// If cancel button is not given, only the default button is displayed
|
// If cancel button is not given, only the default button is displayed
|
||||||
//
|
//
|
||||||
// Examples:
|
// Examples:
|
||||||
|
//
|
||||||
// robotgo.Alert("hi", "window", "ok", "cancel")
|
// robotgo.Alert("hi", "window", "ok", "cancel")
|
||||||
func Alert(title, msg string, args ...string) bool {
|
func Alert(title, msg string, args ...string) bool {
|
||||||
defaultBtn, cancelBtn := alertArgs(args...)
|
defaultBtn, cancelBtn := alertArgs(args...)
|
||||||
|
@ -99,7 +99,7 @@ uint32_t get_num_displays() {
|
|||||||
|
|
||||||
uintptr get_hwnd_by_pid(uintptr pid) {
|
uintptr get_hwnd_by_pid(uintptr pid) {
|
||||||
#if defined(IS_WINDOWS)
|
#if defined(IS_WINDOWS)
|
||||||
HWND hwnd = GetHwndByPId(pid);
|
HWND hwnd = GetHwndByPid(pid);
|
||||||
return (uintptr)hwnd;
|
return (uintptr)hwnd;
|
||||||
#else
|
#else
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -24,7 +24,7 @@ void min_window(uintptr pid, bool state, uintptr isHwnd){
|
|||||||
// SetState((Window)pid, STATE_MINIMIZE, state);
|
// SetState((Window)pid, STATE_MINIMIZE, state);
|
||||||
#elif defined(IS_WINDOWS)
|
#elif defined(IS_WINDOWS)
|
||||||
if (isHwnd == 0) {
|
if (isHwnd == 0) {
|
||||||
HWND hwnd = GetHwndByPId(pid);
|
HWND hwnd = GetHwndByPid(pid);
|
||||||
win_min(hwnd, state);
|
win_min(hwnd, state);
|
||||||
} else {
|
} else {
|
||||||
win_min((HWND)pid, state);
|
win_min((HWND)pid, state);
|
||||||
@ -41,7 +41,7 @@ void max_window(uintptr pid, bool state, uintptr isHwnd){
|
|||||||
// SetState((Window)pid, STATE_MAXIMIZE, state);
|
// SetState((Window)pid, STATE_MAXIMIZE, state);
|
||||||
#elif defined(IS_WINDOWS)
|
#elif defined(IS_WINDOWS)
|
||||||
if (isHwnd == 0) {
|
if (isHwnd == 0) {
|
||||||
HWND hwnd = GetHwndByPId(pid);
|
HWND hwnd = GetHwndByPid(pid);
|
||||||
win_max(hwnd, state);
|
win_max(hwnd, state);
|
||||||
} else {
|
} else {
|
||||||
win_max((HWND)pid, state);
|
win_max((HWND)pid, state);
|
||||||
|
@ -130,7 +130,7 @@ Bounds get_bounds(uintptr pid, uintptr isHwnd){
|
|||||||
#elif defined(IS_WINDOWS)
|
#elif defined(IS_WINDOWS)
|
||||||
HWND hwnd;
|
HWND hwnd;
|
||||||
if (isHwnd == 0) {
|
if (isHwnd == 0) {
|
||||||
hwnd= GetHwndByPId(pid);
|
hwnd= GetHwndByPid(pid);
|
||||||
} else {
|
} else {
|
||||||
hwnd = (HWND)pid;
|
hwnd = (HWND)pid;
|
||||||
}
|
}
|
||||||
@ -195,7 +195,7 @@ Bounds get_client(uintptr pid, uintptr isHwnd) {
|
|||||||
#elif defined(IS_WINDOWS)
|
#elif defined(IS_WINDOWS)
|
||||||
HWND hwnd;
|
HWND hwnd;
|
||||||
if (isHwnd == 0) {
|
if (isHwnd == 0) {
|
||||||
hwnd = GetHwndByPId(pid);
|
hwnd = GetHwndByPid(pid);
|
||||||
} else {
|
} else {
|
||||||
hwnd = (HWND)pid;
|
hwnd = (HWND)pid;
|
||||||
}
|
}
|
||||||
|
@ -60,7 +60,7 @@ MData set_handle_pid(uintptr pid, uintptr isHwnd){
|
|||||||
#elif defined(IS_WINDOWS)
|
#elif defined(IS_WINDOWS)
|
||||||
// win.HWnd = (HWND)pid; // Handle to a window HWND
|
// win.HWnd = (HWND)pid; // Handle to a window HWND
|
||||||
if (isHwnd == 0) {
|
if (isHwnd == 0) {
|
||||||
win.HWnd = GetHwndByPId(pid);
|
win.HWnd = GetHwndByPid(pid);
|
||||||
} else {
|
} else {
|
||||||
win.HWnd = (HWND)pid;
|
win.HWnd = (HWND)pid;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user