diff --git a/README.md b/README.md
index 11526cd..f4177af 100644
--- a/README.md
+++ b/README.md
@@ -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
```
diff --git a/README_zh.md b/README_zh.md
index 77f0db0..5731df0 100644
--- a/README_zh.md
+++ b/README_zh.md
@@ -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)
###鼠标
diff --git a/doc.md b/docs/doc.md
similarity index 98%
rename from doc.md
rename to docs/doc.md
index f7be2b6..52f19d2 100644
--- a/doc.md
+++ b/docs/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/docs/doc_zh.md
similarity index 98%
rename from doc_zh.md
rename to docs/doc_zh.md
index 9e39ef5..46c8f37 100644
--- a/doc_zh.md
+++ b/docs/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/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;
}
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 9367c89..c433004 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.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)
+}
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
+}
+