Merge branch 'master' into master

This commit is contained in:
metalwood 2017-01-24 13:27:43 +08:00 committed by GitHub
commit f0de1b9175
10 changed files with 118 additions and 51 deletions

View File

@ -12,11 +12,11 @@
>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
MacOS, Windows, and Linux(with X11)
MacOS, Windows, Linux(with X11)
##API Docs
@ -24,7 +24,7 @@ MacOS, Windows, and Linux(with X11)
##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
```

View File

@ -14,27 +14,16 @@ RobotGo 支持 Mac, Windows, and Linux(X11).
提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.
- [Requirements](#requirements)
- [Installation](#installation)
- [Update](#update)
- [Requirements](#requirements)
- [Examples](#examples)
- [Future](#future)
- [Contributors](#contributors)
##Installation:
```
go get github.com/go-vgo/robotgo
```
It's that easy!
##Update:
```
go get -u github.com/go-vgo/robotgo
```
###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)
###鼠标

View File

@ -64,6 +64,7 @@
#####[SetHandle](#SetHandle)
#####[GetHandle](#GetHandle)
#####[GetTitle](#GetTitle)
#####[GetPID](#GetPID)
###<h3 id="GetVersion">.GetVersion()</h3>
get robotgo version
@ -525,5 +526,15 @@ func main() {
####Return:
Returns Window Title
Returns Window Title
###<h3 id="GetPID">.GetPID()</h3>
Get the process id
####Arguments:
####Return:
Returns the process id

View File

@ -67,6 +67,7 @@
#####[SetHandle](#SetHandle)
#####[GetHandle](#GetHandle)
#####[GetTitle](#GetTitle)
#####[GetPID](#GetPID)
##<h2 id="Keyboard">键盘</h2>
@ -540,4 +541,14 @@ func main() {
####返回值:
返回窗口标题
返回窗口标题
###<h3 id="GetPID">.GetPID()</h3>
获取进程id
####参数:
####返回值:
返回进程id

View File

@ -42,7 +42,7 @@
int aStop();
int aEvent(char *aevent);
bool logger_proc(unsigned int level, const char *format, ...) {
bool loggerProc(unsigned int level, const char *format, ...) {
bool status = false;
va_list args;
@ -101,18 +101,18 @@ void dispatch_proc(iohook_event * const event) {
switch (status) {
// System level errors.
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;
case IOHOOK_ERROR_X_RECORD_GET_CONTEXT:
// 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;
// Default error.
case IOHOOK_FAILURE:
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;
}
}
@ -210,7 +210,7 @@ int aEvent(char *aevent) {
// (uint16_t *)
cevent=aevent;
// Set the logger callback for library output.
hook_set_logger_proc(&logger_proc);
hookSetlogger(&loggerProc);
// Set the event callback for IOhook events.
hook_set_dispatch_proc(&dispatch_proc);
@ -225,63 +225,63 @@ int aEvent(char *aevent) {
// System level errors.
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;
// X11 specific errors.
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;
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;
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;
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;
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;
// Windows specific errors.
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;
// Darwin specific errors.
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;
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;
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;
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;
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;
// Default error.
case IOHOOK_FAILURE:
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;
}
@ -295,18 +295,18 @@ int aStop(){
switch (status) {
// System level errors.
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;
case IOHOOK_ERROR_X_RECORD_GET_CONTEXT:
// 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;
// Default error.
case IOHOOK_FAILURE:
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;
}

View File

@ -43,7 +43,7 @@ static bool default_logger(unsigned int level, const char *format, ...) {
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) {
logger = &default_logger;
}

View File

@ -151,7 +151,8 @@ func main() {
fmt.Println("ok@@@", "ok")
}
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
hwnd := robotgo.GetHandle() //Get current Window Handle
fmt.Println("hwnd---", hwnd)

View File

@ -39,7 +39,7 @@ import (
)
const (
version string = "v0.42.0.219,Mount Ngauruhoe!"
version string = "v0.42.0.225,Mount Ngauruhoe!"
)
//GetVersion get version
@ -625,15 +625,12 @@ func Convert(args ...interface{}) {
}
/*
------------ --- --- ------------ ---- ---- ------------
************ *** *** ************ ***** **** ************
---- --- --- ---- ------ ---- ------------
************ *** *** ************ ************ ****
------------ --- --- ------------ ------------ ----
**** ******** **** **** ****** ****
------------ ------ ------------ ---- ----- ----
************ **** ************ **** **** ****
___________ ____ _______ .__ __. .___________.
| ____\ \ / / | ____|| \ | | | |
| |__ \ \/ / | |__ | \| | `---| |----`
| __| \ / | __| | . ` | | |
| |____ \ / | |____ | |\ | | |
|_______| \__/ |_______||__| \__| |__|
*/
//Map a map
@ -777,3 +774,9 @@ func GetTitle() string {
// Println("title...", gtittle)
return gtittle
}
//GetPID Get the process id
func GetPID() int {
pid := C.aGetPID()
return int(pid)
}

View File

@ -57,3 +57,8 @@ char* aGetTitle(){
// printf("title::::%s\n",title );
return title;
}
int32 aGetPID(void){
int pid=WGetPID();
return pid;
}

View File

@ -867,3 +867,39 @@ char *GetTitle(){
#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
}