mirror of
https://github.com/go-vgo/robotgo.git
synced 2025-06-06 08:43:56 +00:00
Merge branch 'master' into master
This commit is contained in:
commit
f0de1b9175
@ -12,11 +12,11 @@
|
|||||||
|
|
||||||
|
|
||||||
>Golang Desktop Automation, Control the mouse, keyboard, bitmap,read the screen,Window Handle and global event listener.
|
>Golang Desktop Automation, Control the mouse, keyboard, bitmap,read the screen,Window Handle and global event listener.
|
||||||
[warn]This is a work in progress.
|
This is a work in progress.
|
||||||
|
|
||||||
##Supported platforms
|
##Supported platforms
|
||||||
|
|
||||||
MacOS, Windows, and Linux(with X11)
|
MacOS, Windows, Linux(with X11)
|
||||||
|
|
||||||
##API Docs
|
##API Docs
|
||||||
|
|
||||||
@ -24,7 +24,7 @@ MacOS, Windows, and Linux(with X11)
|
|||||||
|
|
||||||
##Requirements install
|
##Requirements install
|
||||||
|
|
||||||
Before RobotGo installation, make sure Golang/GCC/zlib & libpng have been installed correctly.
|
Before RobotGo installation, make sure Golang/GCC/zlib/libpng have been installed correctly.
|
||||||
|
|
||||||
####Under MacOS
|
####Under MacOS
|
||||||
```
|
```
|
||||||
|
26
README_zh.md
26
README_zh.md
@ -14,27 +14,16 @@ RobotGo 支持 Mac, Windows, and Linux(X11).
|
|||||||
提Issues请到[Github](https://github.com/go-vgo/robotgo),便于统一管理和即时更新
|
提Issues请到[Github](https://github.com/go-vgo/robotgo),便于统一管理和即时更新
|
||||||
|
|
||||||
|
|
||||||
##[中文文档](https://github.com/go-vgo/robotgo/blob/master/doc_zh.md) [API Document](https://github.com/go-vgo/robotgo/blob/master/doc.md)
|
##[中文文档](https://github.com/go-vgo/robotgo/blob/master/docs/doc_zh.md) [API Document](https://github.com/go-vgo/robotgo/blob/master/docs/doc.md)
|
||||||
英文文档请点击API Document.
|
英文文档请点击API Document.
|
||||||
|
|
||||||
|
- [Requirements](#requirements)
|
||||||
- [Installation](#installation)
|
- [Installation](#installation)
|
||||||
- [Update](#update)
|
- [Update](#update)
|
||||||
- [Requirements](#requirements)
|
|
||||||
- [Examples](#examples)
|
- [Examples](#examples)
|
||||||
- [Future](#future)
|
- [Future](#future)
|
||||||
- [Contributors](#contributors)
|
- [Contributors](#contributors)
|
||||||
|
|
||||||
|
|
||||||
##Installation:
|
|
||||||
```
|
|
||||||
go get github.com/go-vgo/robotgo
|
|
||||||
```
|
|
||||||
It's that easy!
|
|
||||||
|
|
||||||
##Update:
|
|
||||||
```
|
|
||||||
go get -u github.com/go-vgo/robotgo
|
|
||||||
```
|
|
||||||
###Requirements:
|
###Requirements:
|
||||||
(环境要求)
|
(环境要求)
|
||||||
|
|
||||||
@ -86,6 +75,17 @@ sudo apt-get install libxkbcommon-dev
|
|||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
##Installation:
|
||||||
|
```
|
||||||
|
go get github.com/go-vgo/robotgo
|
||||||
|
```
|
||||||
|
It's that easy!
|
||||||
|
|
||||||
|
##Update:
|
||||||
|
```
|
||||||
|
go get -u github.com/go-vgo/robotgo
|
||||||
|
```
|
||||||
|
|
||||||
##[Examples:](https://github.com/go-vgo/robotgo/blob/master/example/main.go)
|
##[Examples:](https://github.com/go-vgo/robotgo/blob/master/example/main.go)
|
||||||
|
|
||||||
###鼠标
|
###鼠标
|
||||||
|
@ -64,6 +64,7 @@
|
|||||||
#####[SetHandle](#SetHandle)
|
#####[SetHandle](#SetHandle)
|
||||||
#####[GetHandle](#GetHandle)
|
#####[GetHandle](#GetHandle)
|
||||||
#####[GetTitle](#GetTitle)
|
#####[GetTitle](#GetTitle)
|
||||||
|
#####[GetPID](#GetPID)
|
||||||
|
|
||||||
###<h3 id="GetVersion">.GetVersion()</h3>
|
###<h3 id="GetVersion">.GetVersion()</h3>
|
||||||
get robotgo version
|
get robotgo version
|
||||||
@ -525,5 +526,15 @@ func main() {
|
|||||||
|
|
||||||
|
|
||||||
####Return:
|
####Return:
|
||||||
Returns Window Title
|
Returns Window Title
|
||||||
|
|
||||||
|
###<h3 id="GetPID">.GetPID()</h3>
|
||||||
|
|
||||||
|
Get the process id
|
||||||
|
|
||||||
|
####Arguments:
|
||||||
|
|
||||||
|
|
||||||
|
####Return:
|
||||||
|
Returns the process id
|
||||||
|
|
@ -67,6 +67,7 @@
|
|||||||
#####[SetHandle](#SetHandle)
|
#####[SetHandle](#SetHandle)
|
||||||
#####[GetHandle](#GetHandle)
|
#####[GetHandle](#GetHandle)
|
||||||
#####[GetTitle](#GetTitle)
|
#####[GetTitle](#GetTitle)
|
||||||
|
#####[GetPID](#GetPID)
|
||||||
|
|
||||||
|
|
||||||
##<h2 id="Keyboard">键盘</h2>
|
##<h2 id="Keyboard">键盘</h2>
|
||||||
@ -540,4 +541,14 @@ func main() {
|
|||||||
|
|
||||||
|
|
||||||
####返回值:
|
####返回值:
|
||||||
返回窗口标题
|
返回窗口标题
|
||||||
|
|
||||||
|
###<h3 id="GetPID">.GetPID()</h3>
|
||||||
|
|
||||||
|
获取进程id
|
||||||
|
|
||||||
|
####参数:
|
||||||
|
|
||||||
|
|
||||||
|
####返回值:
|
||||||
|
返回进程id
|
@ -42,7 +42,7 @@
|
|||||||
int aStop();
|
int aStop();
|
||||||
int aEvent(char *aevent);
|
int aEvent(char *aevent);
|
||||||
|
|
||||||
bool logger_proc(unsigned int level, const char *format, ...) {
|
bool loggerProc(unsigned int level, const char *format, ...) {
|
||||||
bool status = false;
|
bool status = false;
|
||||||
|
|
||||||
va_list args;
|
va_list args;
|
||||||
@ -101,18 +101,18 @@ void dispatch_proc(iohook_event * const event) {
|
|||||||
switch (status) {
|
switch (status) {
|
||||||
// System level errors.
|
// System level errors.
|
||||||
case IOHOOK_ERROR_OUT_OF_MEMORY:
|
case IOHOOK_ERROR_OUT_OF_MEMORY:
|
||||||
logger_proc(LOG_LEVEL_ERROR, "Failed to allocate memory. (%#X)", status);
|
loggerProc(LOG_LEVEL_ERROR, "Failed to allocate memory. (%#X)", status);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case IOHOOK_ERROR_X_RECORD_GET_CONTEXT:
|
case IOHOOK_ERROR_X_RECORD_GET_CONTEXT:
|
||||||
// NOTE This is the only platform specific error that occurs on hook_stop().
|
// NOTE This is the only platform specific error that occurs on hook_stop().
|
||||||
logger_proc(LOG_LEVEL_ERROR, "Failed to get XRecord context. (%#X)", status);
|
loggerProc(LOG_LEVEL_ERROR, "Failed to get XRecord context. (%#X)", status);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// Default error.
|
// Default error.
|
||||||
case IOHOOK_FAILURE:
|
case IOHOOK_FAILURE:
|
||||||
default:
|
default:
|
||||||
logger_proc(LOG_LEVEL_ERROR, "An unknown hook error occurred. (%#X)", status);
|
loggerProc(LOG_LEVEL_ERROR, "An unknown hook error occurred. (%#X)", status);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -210,7 +210,7 @@ int aEvent(char *aevent) {
|
|||||||
// (uint16_t *)
|
// (uint16_t *)
|
||||||
cevent=aevent;
|
cevent=aevent;
|
||||||
// Set the logger callback for library output.
|
// Set the logger callback for library output.
|
||||||
hook_set_logger_proc(&logger_proc);
|
hookSetlogger(&loggerProc);
|
||||||
|
|
||||||
// Set the event callback for IOhook events.
|
// Set the event callback for IOhook events.
|
||||||
hook_set_dispatch_proc(&dispatch_proc);
|
hook_set_dispatch_proc(&dispatch_proc);
|
||||||
@ -225,63 +225,63 @@ int aEvent(char *aevent) {
|
|||||||
|
|
||||||
// System level errors.
|
// System level errors.
|
||||||
case IOHOOK_ERROR_OUT_OF_MEMORY:
|
case IOHOOK_ERROR_OUT_OF_MEMORY:
|
||||||
logger_proc(LOG_LEVEL_ERROR, "Failed to allocate memory. (%#X)", status);
|
loggerProc(LOG_LEVEL_ERROR, "Failed to allocate memory. (%#X)", status);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
||||||
// X11 specific errors.
|
// X11 specific errors.
|
||||||
case IOHOOK_ERROR_X_OPEN_DISPLAY:
|
case IOHOOK_ERROR_X_OPEN_DISPLAY:
|
||||||
logger_proc(LOG_LEVEL_ERROR, "Failed to open X11 display. (%#X)", status);
|
loggerProc(LOG_LEVEL_ERROR, "Failed to open X11 display. (%#X)", status);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case IOHOOK_ERROR_X_RECORD_NOT_FOUND:
|
case IOHOOK_ERROR_X_RECORD_NOT_FOUND:
|
||||||
logger_proc(LOG_LEVEL_ERROR, "Unable to locate XRecord extension. (%#X)", status);
|
loggerProc(LOG_LEVEL_ERROR, "Unable to locate XRecord extension. (%#X)", status);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case IOHOOK_ERROR_X_RECORD_ALLOC_RANGE:
|
case IOHOOK_ERROR_X_RECORD_ALLOC_RANGE:
|
||||||
logger_proc(LOG_LEVEL_ERROR, "Unable to allocate XRecord range. (%#X)", status);
|
loggerProc(LOG_LEVEL_ERROR, "Unable to allocate XRecord range. (%#X)", status);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case IOHOOK_ERROR_X_RECORD_CREATE_CONTEXT:
|
case IOHOOK_ERROR_X_RECORD_CREATE_CONTEXT:
|
||||||
logger_proc(LOG_LEVEL_ERROR, "Unable to allocate XRecord context. (%#X)", status);
|
loggerProc(LOG_LEVEL_ERROR, "Unable to allocate XRecord context. (%#X)", status);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case IOHOOK_ERROR_X_RECORD_ENABLE_CONTEXT:
|
case IOHOOK_ERROR_X_RECORD_ENABLE_CONTEXT:
|
||||||
logger_proc(LOG_LEVEL_ERROR, "Failed to enable XRecord context. (%#X)", status);
|
loggerProc(LOG_LEVEL_ERROR, "Failed to enable XRecord context. (%#X)", status);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
||||||
// Windows specific errors.
|
// Windows specific errors.
|
||||||
case IOHOOK_ERROR_SET_WINDOWS_HOOK_EX:
|
case IOHOOK_ERROR_SET_WINDOWS_HOOK_EX:
|
||||||
logger_proc(LOG_LEVEL_ERROR, "Failed to register low level windows hook. (%#X)", status);
|
loggerProc(LOG_LEVEL_ERROR, "Failed to register low level windows hook. (%#X)", status);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
||||||
// Darwin specific errors.
|
// Darwin specific errors.
|
||||||
case IOHOOK_ERROR_AXAPI_DISABLED:
|
case IOHOOK_ERROR_AXAPI_DISABLED:
|
||||||
logger_proc(LOG_LEVEL_ERROR, "Failed to enable access for assistive devices. (%#X)", status);
|
loggerProc(LOG_LEVEL_ERROR, "Failed to enable access for assistive devices. (%#X)", status);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case IOHOOK_ERROR_CREATE_EVENT_PORT:
|
case IOHOOK_ERROR_CREATE_EVENT_PORT:
|
||||||
logger_proc(LOG_LEVEL_ERROR, "Failed to create apple event port. (%#X)", status);
|
loggerProc(LOG_LEVEL_ERROR, "Failed to create apple event port. (%#X)", status);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case IOHOOK_ERROR_CREATE_RUN_LOOP_SOURCE:
|
case IOHOOK_ERROR_CREATE_RUN_LOOP_SOURCE:
|
||||||
logger_proc(LOG_LEVEL_ERROR, "Failed to create apple run loop source. (%#X)", status);
|
loggerProc(LOG_LEVEL_ERROR, "Failed to create apple run loop source. (%#X)", status);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case IOHOOK_ERROR_GET_RUNLOOP:
|
case IOHOOK_ERROR_GET_RUNLOOP:
|
||||||
logger_proc(LOG_LEVEL_ERROR, "Failed to acquire apple run loop. (%#X)", status);
|
loggerProc(LOG_LEVEL_ERROR, "Failed to acquire apple run loop. (%#X)", status);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case IOHOOK_ERROR_CREATE_OBSERVER:
|
case IOHOOK_ERROR_CREATE_OBSERVER:
|
||||||
logger_proc(LOG_LEVEL_ERROR, "Failed to create apple run loop observer. (%#X)", status);
|
loggerProc(LOG_LEVEL_ERROR, "Failed to create apple run loop observer. (%#X)", status);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// Default error.
|
// Default error.
|
||||||
case IOHOOK_FAILURE:
|
case IOHOOK_FAILURE:
|
||||||
default:
|
default:
|
||||||
logger_proc(LOG_LEVEL_ERROR, "An unknown hook error occurred. (%#X)", status);
|
loggerProc(LOG_LEVEL_ERROR, "An unknown hook error occurred. (%#X)", status);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -295,18 +295,18 @@ int aStop(){
|
|||||||
switch (status) {
|
switch (status) {
|
||||||
// System level errors.
|
// System level errors.
|
||||||
case IOHOOK_ERROR_OUT_OF_MEMORY:
|
case IOHOOK_ERROR_OUT_OF_MEMORY:
|
||||||
logger_proc(LOG_LEVEL_ERROR, "Failed to allocate memory. (%#X)", status);
|
loggerProc(LOG_LEVEL_ERROR, "Failed to allocate memory. (%#X)", status);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case IOHOOK_ERROR_X_RECORD_GET_CONTEXT:
|
case IOHOOK_ERROR_X_RECORD_GET_CONTEXT:
|
||||||
// NOTE This is the only platform specific error that occurs on hook_stop().
|
// NOTE This is the only platform specific error that occurs on hook_stop().
|
||||||
logger_proc(LOG_LEVEL_ERROR, "Failed to get XRecord context. (%#X)", status);
|
loggerProc(LOG_LEVEL_ERROR, "Failed to get XRecord context. (%#X)", status);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// Default error.
|
// Default error.
|
||||||
case IOHOOK_FAILURE:
|
case IOHOOK_FAILURE:
|
||||||
default:
|
default:
|
||||||
// logger_proc(LOG_LEVEL_ERROR, "An unknown hook error occurred. (%#X)", status);
|
// loggerProc(LOG_LEVEL_ERROR, "An unknown hook error occurred. (%#X)", status);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,7 +43,7 @@ static bool default_logger(unsigned int level, const char *format, ...) {
|
|||||||
logger_t logger = &default_logger;
|
logger_t logger = &default_logger;
|
||||||
|
|
||||||
|
|
||||||
IOHOOK_API void hook_set_logger_proc(logger_t logger_proc) {
|
IOHOOK_API void hookSetlogger(logger_t logger_proc) {
|
||||||
if (logger_proc == NULL) {
|
if (logger_proc == NULL) {
|
||||||
logger = &default_logger;
|
logger = &default_logger;
|
||||||
}
|
}
|
||||||
|
@ -151,7 +151,8 @@ func main() {
|
|||||||
fmt.Println("ok@@@", "ok")
|
fmt.Println("ok@@@", "ok")
|
||||||
}
|
}
|
||||||
robotgo.ShowAlert("hello", "robotgo", "Ok", "Cancel")
|
robotgo.ShowAlert("hello", "robotgo", "Ok", "Cancel")
|
||||||
// robotgo.GetPID()
|
pid := robotgo.GetPID() //Get the current process id
|
||||||
|
fmt.Println("pid----", pid)
|
||||||
mdata := robotgo.GetActive() //Get current Window Active
|
mdata := robotgo.GetActive() //Get current Window Active
|
||||||
hwnd := robotgo.GetHandle() //Get current Window Handle
|
hwnd := robotgo.GetHandle() //Get current Window Handle
|
||||||
fmt.Println("hwnd---", hwnd)
|
fmt.Println("hwnd---", hwnd)
|
||||||
|
23
robotgo.go
23
robotgo.go
@ -39,7 +39,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
version string = "v0.42.0.219,Mount Ngauruhoe!"
|
version string = "v0.42.0.225,Mount Ngauruhoe!"
|
||||||
)
|
)
|
||||||
|
|
||||||
//GetVersion get version
|
//GetVersion get version
|
||||||
@ -625,15 +625,12 @@ func Convert(args ...interface{}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
___________ ____ _______ .__ __. .___________.
|
||||||
------------ --- --- ------------ ---- ---- ------------
|
| ____\ \ / / | ____|| \ | | | |
|
||||||
************ *** *** ************ ***** **** ************
|
| |__ \ \/ / | |__ | \| | `---| |----`
|
||||||
---- --- --- ---- ------ ---- ------------
|
| __| \ / | __| | . ` | | |
|
||||||
************ *** *** ************ ************ ****
|
| |____ \ / | |____ | |\ | | |
|
||||||
------------ --- --- ------------ ------------ ----
|
|_______| \__/ |_______||__| \__| |__|
|
||||||
**** ******** **** **** ****** ****
|
|
||||||
------------ ------ ------------ ---- ----- ----
|
|
||||||
************ **** ************ **** **** ****
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
//Map a map
|
//Map a map
|
||||||
@ -777,3 +774,9 @@ func GetTitle() string {
|
|||||||
// Println("title...", gtittle)
|
// Println("title...", gtittle)
|
||||||
return gtittle
|
return gtittle
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//GetPID Get the process id
|
||||||
|
func GetPID() int {
|
||||||
|
pid := C.aGetPID()
|
||||||
|
return int(pid)
|
||||||
|
}
|
||||||
|
@ -57,3 +57,8 @@ char* aGetTitle(){
|
|||||||
// printf("title::::%s\n",title );
|
// printf("title::::%s\n",title );
|
||||||
return title;
|
return title;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32 aGetPID(void){
|
||||||
|
int pid=WGetPID();
|
||||||
|
return pid;
|
||||||
|
}
|
||||||
|
@ -867,3 +867,39 @@ char *GetTitle(){
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32 WGetPID(void){
|
||||||
|
// Check window validity
|
||||||
|
if (!IsValid()) return 0;
|
||||||
|
|
||||||
|
#if defined(IS_MACOSX)
|
||||||
|
|
||||||
|
pid_t pid = 0;
|
||||||
|
// Attempt to retrieve the window pid
|
||||||
|
if (AXUIElementGetPid(mData.AxID, &pid)
|
||||||
|
== kAXErrorSuccess) return pid;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
#elif defined(USE_X11)
|
||||||
|
|
||||||
|
// Ignore X errors
|
||||||
|
XDismissErrors();
|
||||||
|
|
||||||
|
// Get the window PID
|
||||||
|
long* result = (long*)
|
||||||
|
GetWindowProperty(mData, WM_PID,NULL);
|
||||||
|
|
||||||
|
// Check result and convert it
|
||||||
|
if (result == NULL) return 0;
|
||||||
|
int32 pid = (int32) *result;
|
||||||
|
XFree (result); return pid;
|
||||||
|
|
||||||
|
#elif defined(IS_WINDOWS)
|
||||||
|
|
||||||
|
DWORD id = 0;
|
||||||
|
GetWindowThreadProcessId (mData.HWnd, &id);
|
||||||
|
return id;
|
||||||
|
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user