From bbc0c8e2a783aa498732d3d5fc1b297c4e37c5a2 Mon Sep 17 00:00:00 2001 From: vCaesar Date: Wed, 18 Jan 2017 20:34:35 +0800 Subject: [PATCH 1/7] Add Getpid --- robotgo.go | 6 ++++++ window/goWindow.h | 5 +++++ window/window.h | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+) diff --git a/robotgo.go b/robotgo.go index 9367c89..96cdf7b 100644 --- a/robotgo.go +++ b/robotgo.go @@ -777,3 +777,9 @@ func GetTitle() string { // Println("title...", gtittle) return gtittle } + +//GetPID Get the process id +func GetPID() int { + pid := C.aGetPID() + return int(pid) +} diff --git a/window/goWindow.h b/window/goWindow.h index fe0617b..4a7d3ca 100644 --- a/window/goWindow.h +++ b/window/goWindow.h @@ -57,3 +57,8 @@ char* aGetTitle(){ // printf("title::::%s\n",title ); return title; } + +int32 aGetPID(void){ + int pid=WGetPID(); + return pid; +} diff --git a/window/window.h b/window/window.h index 3e9da69..0c082b2 100644 --- a/window/window.h +++ b/window/window.h @@ -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 +} + From 85377986eb4d05b4c31b540c7a9c4d3b58a0e6fd Mon Sep 17 00:00:00 2001 From: vCaesar Date: Wed, 18 Jan 2017 20:41:39 +0800 Subject: [PATCH 2/7] Update doc --- doc.md | 13 ++++++++++++- doc_zh.md | 13 ++++++++++++- robotgo.go | 2 +- 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/doc.md b/doc.md index f7be2b6..52f19d2 100644 --- a/doc.md +++ b/doc.md @@ -64,6 +64,7 @@ #####[SetHandle](#SetHandle) #####[GetHandle](#GetHandle) #####[GetTitle](#GetTitle) +#####[GetPID](#GetPID) ###

.GetVersion()

get robotgo version @@ -525,5 +526,15 @@ func main() { ####Return: - Returns Window Title + Returns Window Title + +###

.GetPID()

+ + Get the process id + +####Arguments: + + +####Return: + Returns the process id diff --git a/doc_zh.md b/doc_zh.md index 9e39ef5..46c8f37 100644 --- a/doc_zh.md +++ b/doc_zh.md @@ -67,6 +67,7 @@ #####[SetHandle](#SetHandle) #####[GetHandle](#GetHandle) #####[GetTitle](#GetTitle) +#####[GetPID](#GetPID) ##

键盘

@@ -540,4 +541,14 @@ func main() { ####返回值: - 返回窗口标题 \ No newline at end of file + 返回窗口标题 + +###

.GetPID()

+ + 获取进程id + +####参数: + + +####返回值: + 返回进程id \ No newline at end of file diff --git a/robotgo.go b/robotgo.go index 96cdf7b..f8a8cd6 100644 --- a/robotgo.go +++ b/robotgo.go @@ -39,7 +39,7 @@ import ( ) const ( - version string = "v0.42.0.219,Mount Ngauruhoe!" + version string = "v0.42.0.221,Mount Ngauruhoe!" ) //GetVersion get version From de60d4d88bf4ea2f0b83c708665c4341ad2a2617 Mon Sep 17 00:00:00 2001 From: vCaesar Date: Wed, 18 Jan 2017 21:13:26 +0800 Subject: [PATCH 3/7] Update example --- example/main.go | 3 ++- robotgo.go | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/example/main.go b/example/main.go index 739e509..1e41ba0 100644 --- a/example/main.go +++ b/example/main.go @@ -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) diff --git a/robotgo.go b/robotgo.go index f8a8cd6..a6e00d1 100644 --- a/robotgo.go +++ b/robotgo.go @@ -39,7 +39,7 @@ import ( ) const ( - version string = "v0.42.0.221,Mount Ngauruhoe!" + version string = "v0.42.0.222,Mount Ngauruhoe!" ) //GetVersion get version From bf5f4c21e5ea326c542028b6695a6e42816688b8 Mon Sep 17 00:00:00 2001 From: vCaesar Date: Fri, 20 Jan 2017 00:35:11 +0800 Subject: [PATCH 4/7] Move doc and Update name --- doc.md => docs/doc.md | 0 doc_zh.md => docs/doc_zh.md | 0 event/goEvent.h | 42 ++++++++++++++++++------------------- event/hook/logger_c.h | 2 +- 4 files changed, 22 insertions(+), 22 deletions(-) rename doc.md => docs/doc.md (100%) rename doc_zh.md => docs/doc_zh.md (100%) diff --git a/doc.md b/docs/doc.md similarity index 100% rename from doc.md rename to docs/doc.md diff --git a/doc_zh.md b/docs/doc_zh.md similarity index 100% rename from doc_zh.md rename to docs/doc_zh.md diff --git a/event/goEvent.h b/event/goEvent.h index 3028911..556e3de 100644 --- a/event/goEvent.h +++ b/event/goEvent.h @@ -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; } diff --git a/event/hook/logger_c.h b/event/hook/logger_c.h index ccc16ed..8752245 100644 --- a/event/hook/logger_c.h +++ b/event/hook/logger_c.h @@ -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; } From e0b440d3a8db014e27e23cd6424056387ee7a8ed Mon Sep 17 00:00:00 2001 From: vCaesar Date: Fri, 20 Jan 2017 00:36:43 +0800 Subject: [PATCH 5/7] Update md --- README.md | 2 +- README_zh.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c1a0b2e..0f99a3f 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ This is a work in progress. -##[API Document](https://github.com/go-vgo/robotgo/blob/master/doc.md)    [中文文档](https://github.com/go-vgo/robotgo/blob/master/doc_zh.md) +##[API Document](https://github.com/go-vgo/robotgo/blob/master/docs/doc.md)    [中文文档](https://github.com/go-vgo/robotgo/blob/master/docs/doc_zh.md) Please click API Document;This is a work in progress. - [Installation](#installation) diff --git a/README_zh.md b/README_zh.md index 77f0db0..5cae1ad 100644 --- a/README_zh.md +++ b/README_zh.md @@ -14,7 +14,7 @@ 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. - [Installation](#installation) From ce5433a61ce46e04151ae0e0398d4de2e9329648 Mon Sep 17 00:00:00 2001 From: vCaesar Date: Fri, 20 Jan 2017 01:20:23 +0800 Subject: [PATCH 6/7] Update ascii --- robotgo.go | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/robotgo.go b/robotgo.go index a6e00d1..c433004 100644 --- a/robotgo.go +++ b/robotgo.go @@ -39,7 +39,7 @@ import ( ) const ( - version string = "v0.42.0.222,Mount Ngauruhoe!" + version string = "v0.42.0.225,Mount Ngauruhoe!" ) //GetVersion get version @@ -625,15 +625,12 @@ func Convert(args ...interface{}) { } /* - ------------- --- --- ------------ ---- ---- ------------ -************ *** *** ************ ***** **** ************ ----- --- --- ---- ------ ---- ------------ -************ *** *** ************ ************ **** ------------- --- --- ------------ ------------ ---- -**** ******** **** **** ****** **** ------------- ------ ------------ ---- ----- ---- -************ **** ************ **** **** **** + ___________ ____ _______ .__ __. .___________. +| ____\ \ / / | ____|| \ | | | | +| |__ \ \/ / | |__ | \| | `---| |----` +| __| \ / | __| | . ` | | | +| |____ \ / | |____ | |\ | | | +|_______| \__/ |_______||__| \__| |__| */ //Map a map From 50a74fa4a5f437085f839e3b455b3c64710e53ff Mon Sep 17 00:00:00 2001 From: vCaesar Date: Fri, 20 Jan 2017 22:18:57 +0800 Subject: [PATCH 7/7] Update md --- README.md | 25 +++++++++++++------------ README_zh.md | 24 ++++++++++++------------ 2 files changed, 25 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index 0f99a3f..e0b0004 100644 --- a/README.md +++ b/README.md @@ -21,24 +21,13 @@ This is a work in progress. ##[API Document](https://github.com/go-vgo/robotgo/blob/master/docs/doc.md)    [中文文档](https://github.com/go-vgo/robotgo/blob/master/docs/doc_zh.md) Please click API Document;This is a work in progress. +- [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: ####ALL: @@ -89,6 +78,18 @@ sudo apt-get install xcb libxcb-xkb-dev x11-xkb-utils libx11-xcb-dev libxkbcommo 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) ###Mouse diff --git a/README_zh.md b/README_zh.md index 5cae1ad..5731df0 100644 --- a/README_zh.md +++ b/README_zh.md @@ -17,24 +17,13 @@ RobotGo 支持 Mac, Windows, and Linux(X11). ##[中文文档](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) ###鼠标