mirror of
https://github.com/go-vgo/robotgo.git
synced 2025-06-10 02:23:54 +00:00
update hook pkg to newest
This commit is contained in:
parent
906e2a0461
commit
96820b2f41
go.modgo.sum
vendor
github.com/robotn/gohook
modules.txt
2
go.mod
2
go.mod
@ -7,7 +7,7 @@ require (
|
||||
github.com/go-ole/go-ole v1.2.2 // indirect
|
||||
github.com/lxn/win v0.0.0-20181015143721-a7f87360b10e
|
||||
github.com/otiai10/gosseract v2.2.0+incompatible
|
||||
github.com/robotn/gohook v0.0.0-20181215173318-e36d1aac6c1a
|
||||
github.com/robotn/gohook v0.0.0-20190221131031-8d5c93253274
|
||||
github.com/shirou/gopsutil v2.18.12+incompatible
|
||||
github.com/shirou/w32 v0.0.0-20160930032740-bb4de0191aa4 // indirect
|
||||
github.com/vcaesar/imgo v0.0.0-20181209162409-13af122cf2fa
|
||||
|
4
go.sum
4
go.sum
@ -14,8 +14,8 @@ github.com/lxn/win v0.0.0-20181015143721-a7f87360b10e h1:dz4TzIsrPe4XtUyhLkOLdCS
|
||||
github.com/lxn/win v0.0.0-20181015143721-a7f87360b10e/go.mod h1:jACzEp9RV7NhfPJQkiCNTteU4nkZZVlvkNpYtVOZPfE=
|
||||
github.com/otiai10/gosseract v2.2.0+incompatible h1:r2Icyba/doznLy0MgsDMWJADETgJNjlX78x/BBbhCUY=
|
||||
github.com/otiai10/gosseract v2.2.0+incompatible/go.mod h1:XrzWItCzCpFRZ35n3YtVTgq5bLAhFIkascoRo8G32QE=
|
||||
github.com/robotn/gohook v0.0.0-20181215173318-e36d1aac6c1a h1:ywJG+bNPAxgEjZA6lqfbzcBlAw2F91dbMGYtP9xmrHw=
|
||||
github.com/robotn/gohook v0.0.0-20181215173318-e36d1aac6c1a/go.mod h1:YD5RyCnUEY2xqtkkgeQVZ31UAfAnVPwUxpTE5cwSXg4=
|
||||
github.com/robotn/gohook v0.0.0-20190221131031-8d5c93253274 h1:kSg34ruV/HqMFgzSkmsUPaDwm8pCpVZXf9j8VY0gNY0=
|
||||
github.com/robotn/gohook v0.0.0-20190221131031-8d5c93253274/go.mod h1:YD5RyCnUEY2xqtkkgeQVZ31UAfAnVPwUxpTE5cwSXg4=
|
||||
github.com/shirou/gopsutil v2.18.12+incompatible h1:1eaJvGomDnH74/5cF4CTmTbLHAriGFsTZppLXDX93OM=
|
||||
github.com/shirou/gopsutil v2.18.12+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=
|
||||
github.com/shirou/w32 v0.0.0-20160930032740-bb4de0191aa4 h1:udFKJ0aHUL60LboW/A+DfgoHVedieIzIXE8uylPue0U=
|
||||
|
1
vendor/github.com/robotn/gohook/.gitignore
generated
vendored
1
vendor/github.com/robotn/gohook/.gitignore
generated
vendored
@ -22,3 +22,4 @@ _testmain.go
|
||||
*.exe
|
||||
*.test
|
||||
*.prof
|
||||
*.idea
|
13
vendor/github.com/robotn/gohook/README.md
generated
vendored
13
vendor/github.com/robotn/gohook/README.md
generated
vendored
@ -16,10 +16,13 @@ import (
|
||||
)
|
||||
|
||||
func main() {
|
||||
// hook.AsyncHook()
|
||||
veve := hook.AddEvent("v")
|
||||
if veve == 0 {
|
||||
fmt.Println("v...")
|
||||
EvChan := hook.Start()
|
||||
defer hook.End()
|
||||
|
||||
for ev := range EvChan {
|
||||
fmt.Println(ev)
|
||||
}
|
||||
}
|
||||
```
|
||||
```
|
||||
|
||||
Based on [libuiohook](https://github.com/kwhat/libuiohook).
|
2
vendor/github.com/robotn/gohook/appveyor.yml
generated
vendored
2
vendor/github.com/robotn/gohook/appveyor.yml
generated
vendored
@ -34,7 +34,7 @@ environment:
|
||||
PATH: C:\msys64\mingw32\bin\;C:\Program Files (x86)\NSIS\;%PATH%
|
||||
# - COMPILER: MINGW_W64
|
||||
# ARCHITECTURE: x64
|
||||
GOVERSION: 1.11.4
|
||||
GOVERSION: 1.11.5
|
||||
# GOPATH: c:\gopath
|
||||
|
||||
# scripts that run after cloning repository
|
||||
|
1439
vendor/github.com/robotn/gohook/chan/eb_chan.h
generated
vendored
Normal file
1439
vendor/github.com/robotn/gohook/chan/eb_chan.h
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
217
vendor/github.com/robotn/gohook/event/dispatch_proc.h
generated
vendored
Normal file
217
vendor/github.com/robotn/gohook/event/dispatch_proc.h
generated
vendored
Normal file
@ -0,0 +1,217 @@
|
||||
// Copyright 2016 The go-vgo Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// https://github.com/go-vgo/robotgo/blob/master/LICENSE
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
#ifndef dispatch_proc_h
|
||||
#define dispatch_proc_h
|
||||
|
||||
// #include "pub.h"
|
||||
// #include "../chan/eb_chan.h"
|
||||
|
||||
void dispatch_proc(iohook_event * const event) {
|
||||
if (!sending) { return; }
|
||||
|
||||
// leaking memory? hope not
|
||||
char* buffer = calloc(200, sizeof(char));
|
||||
|
||||
switch (event->type) {
|
||||
case EVENT_HOOK_ENABLED:
|
||||
case EVENT_HOOK_DISABLED:
|
||||
sprintf(buffer,
|
||||
"{\"id\":%i,\"time\":%" PRIu64 ",\"mask\":%hu,\"reserved\":%hu}",
|
||||
event->type, event->time, event->mask,event->reserved);
|
||||
break; // send it?
|
||||
case EVENT_KEY_PRESSED:
|
||||
case EVENT_KEY_RELEASED:
|
||||
case EVENT_KEY_TYPED:
|
||||
sprintf(buffer,
|
||||
"{\"id\":%i,\"time\":%" PRIu64 ",\"mask\":%hu,\"reserved\":%hu,\"keycode\":%hu,\"rawcode\":%hu,\"keychar\":%hu}",
|
||||
event->type, event->time, event->mask,event->reserved,
|
||||
event->data.keyboard.keycode,
|
||||
event->data.keyboard.rawcode,
|
||||
event->data.keyboard.keychar);
|
||||
break;
|
||||
case EVENT_MOUSE_PRESSED:
|
||||
case EVENT_MOUSE_RELEASED:
|
||||
case EVENT_MOUSE_CLICKED:
|
||||
case EVENT_MOUSE_MOVED:
|
||||
case EVENT_MOUSE_DRAGGED:
|
||||
sprintf(buffer,
|
||||
"{\"id\":%i,\"time\":%" PRIu64 ",\"mask\":%hu,\"reserved\":%hu,\"x\":%hd,\"y\":%hd,\"button\":%u,\"clicks\":%u}",
|
||||
event->type, event->time, event->mask,event->reserved,
|
||||
event->data.mouse.x,
|
||||
event->data.mouse.y,
|
||||
event->data.mouse.button,
|
||||
event->data.mouse.clicks);
|
||||
break;
|
||||
case EVENT_MOUSE_WHEEL:
|
||||
sprintf(buffer,
|
||||
"{\"id\":%i,\"time\":%" PRIu64 ",\"mask\":%hu,\"reserved\":%hu,\"clicks\":%hu,\"x\":%hd,\"y\":%hd,\"type\":%hu,\"ammount\":%hu,\"rotation\":%hd,\"direction\":%hu}",
|
||||
event->type, event->time, event->mask, event->reserved,
|
||||
event->data.wheel.clicks,
|
||||
event->data.wheel.x,
|
||||
event->data.wheel.y,
|
||||
event->data.wheel.type,
|
||||
event->data.wheel.amount,
|
||||
event->data.wheel.rotation,
|
||||
event->data.wheel.direction);
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr,"\nError on file: %s, unusual event->type: %i\n",__FILE__,event->type);
|
||||
return;
|
||||
}
|
||||
|
||||
// to-do remove this for
|
||||
int i;
|
||||
for (i = 0; i < 5; i++) {
|
||||
switch (eb_chan_try_send(events, buffer)) { // never block the hook callback
|
||||
case eb_chan_res_ok:
|
||||
i=5;
|
||||
break;
|
||||
default:
|
||||
if (i == 4) { // let's not leak memory
|
||||
free(buffer);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// fprintf(stdout, "----%s\n", buffer);
|
||||
}
|
||||
|
||||
void dispatch_proc_end(iohook_event * const event) {
|
||||
char buffer[256] = { 0 };
|
||||
size_t length = snprintf(buffer, sizeof(buffer),
|
||||
"id=%i,when=%" PRIu64 ",mask=0x%X",
|
||||
event->type, event->time, event->mask);
|
||||
|
||||
switch (event->type) {
|
||||
case EVENT_KEY_PRESSED:
|
||||
// If the escape key is pressed, naturally terminate the program.
|
||||
if (event->data.keyboard.keycode == VC_ESCAPE) {
|
||||
// int status = hook_stop();
|
||||
// switch (status) {
|
||||
// // System level errors.
|
||||
// case IOHOOK_ERROR_OUT_OF_MEMORY:
|
||||
// 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().
|
||||
// loggerProc(LOG_LEVEL_ERROR, "Failed to get XRecord context. (%#X)", status);
|
||||
// break;
|
||||
|
||||
// // Default error.
|
||||
// case IOHOOK_FAILURE:
|
||||
// default:
|
||||
// loggerProc(LOG_LEVEL_ERROR, "An unknown hook error occurred. (%#X)", status);
|
||||
// break;
|
||||
// }
|
||||
}
|
||||
case EVENT_KEY_RELEASED:
|
||||
snprintf(buffer + length, sizeof(buffer) - length,
|
||||
",keycode=%u,rawcode=0x%X",
|
||||
event->data.keyboard.keycode, event->data.keyboard.rawcode);
|
||||
int key_code = (uint16_t) event->data.keyboard.keycode;
|
||||
|
||||
if (event->data.keyboard.keycode == VC_ESCAPE
|
||||
&& atoi(cevent) == 11) {
|
||||
int stopEvent = stop_event();
|
||||
// printf("stop_event%d\n", stopEvent);
|
||||
cstatus = 0;
|
||||
}
|
||||
|
||||
// printf("atoi(str)---%d\n", atoi(cevent));
|
||||
if (key_code == atoi(cevent)) {
|
||||
int stopEvent = stop_event();
|
||||
// printf("%d\n", stopEvent);
|
||||
cstatus = 0;
|
||||
}
|
||||
break;
|
||||
|
||||
case EVENT_KEY_TYPED:
|
||||
snprintf(buffer + length, sizeof(buffer) - length,
|
||||
",keychar=%lc,rawcode=%u",
|
||||
(uint16_t) event->data.keyboard.keychar,
|
||||
event->data.keyboard.rawcode);
|
||||
|
||||
#ifdef WE_REALLY_WANT_A_POINTER
|
||||
char *buf = malloc (6);
|
||||
#else
|
||||
char buf[6];
|
||||
#endif
|
||||
|
||||
sprintf(buf, "%lc", (uint16_t) event->data.keyboard.keychar);
|
||||
|
||||
#ifdef WE_REALLY_WANT_A_POINTER
|
||||
free (buf);
|
||||
#endif
|
||||
|
||||
if (strcmp(buf, cevent) == 0) {
|
||||
int stopEvent = stop_event();
|
||||
// printf("%d\n", stopEvent);
|
||||
cstatus = 0;
|
||||
}
|
||||
// return (char*) event->data.keyboard.keychar;
|
||||
break;
|
||||
|
||||
case EVENT_MOUSE_PRESSED:
|
||||
case EVENT_MOUSE_RELEASED:
|
||||
case EVENT_MOUSE_CLICKED:
|
||||
case EVENT_MOUSE_MOVED:
|
||||
case EVENT_MOUSE_DRAGGED:
|
||||
snprintf(buffer + length, sizeof(buffer) - length,
|
||||
",x=%i,y=%i,button=%i,clicks=%i",
|
||||
event->data.mouse.x, event->data.mouse.y,
|
||||
event->data.mouse.button, event->data.mouse.clicks);
|
||||
|
||||
int abutton = event->data.mouse.button;
|
||||
int aclicks = event->data.mouse.clicks;
|
||||
int amouse = -1;
|
||||
|
||||
if (strcmp(cevent, "mleft") == 0) {
|
||||
amouse = 1;
|
||||
}
|
||||
if (strcmp(cevent, "mright") == 0) {
|
||||
amouse = 2;
|
||||
}
|
||||
if (strcmp(cevent, "wheelDown") == 0) {
|
||||
amouse = 4;
|
||||
}
|
||||
if (strcmp(cevent, "wheelUp") == 0) {
|
||||
amouse = 5;
|
||||
}
|
||||
if (strcmp(cevent, "wheelLeft") == 0) {
|
||||
amouse = 6;
|
||||
}
|
||||
if (strcmp(cevent, "wheelRight") == 0) {
|
||||
amouse = 7;
|
||||
}
|
||||
if (abutton == amouse && aclicks == 1) {
|
||||
int stopEvent = stop_event();
|
||||
cstatus = 0;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case EVENT_MOUSE_WHEEL:
|
||||
snprintf(buffer + length, sizeof(buffer) - length,
|
||||
",type=%i,amount=%i,rotation=%i",
|
||||
event->data.wheel.type, event->data.wheel.amount,
|
||||
event->data.wheel.rotation);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
// fprintf(stdout, "----%s\n", buffer);
|
||||
}
|
||||
|
||||
#endif
|
180
vendor/github.com/robotn/gohook/event/goEvent.h
generated
vendored
180
vendor/github.com/robotn/gohook/event/goEvent.h
generated
vendored
@ -8,151 +8,69 @@
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
#ifndef goevent_h
|
||||
#define goevent_h
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
#include "pub.h"
|
||||
// #include "../chan/eb_chan.h"
|
||||
#include "dispatch_proc.h"
|
||||
|
||||
void go_send(char*);
|
||||
void go_sleep(void);
|
||||
|
||||
void dispatch_proc(iohook_event * const event) {
|
||||
char buffer[256] = { 0 };
|
||||
size_t length = snprintf(buffer, sizeof(buffer),
|
||||
"id=%i,when=%" PRIu64 ",mask=0x%X",
|
||||
event->type, event->time, event->mask);
|
||||
void start_ev(){
|
||||
events = eb_chan_create(1024);
|
||||
eb_chan_retain(events);
|
||||
sending = true;
|
||||
// add_event("q");
|
||||
add_event_async();
|
||||
}
|
||||
|
||||
switch (event->type) {
|
||||
case EVENT_KEY_PRESSED:
|
||||
// If the escape key is pressed, naturally terminate the program.
|
||||
if (event->data.keyboard.keycode == VC_ESCAPE) {
|
||||
// int status = hook_stop();
|
||||
// switch (status) {
|
||||
// // System level errors.
|
||||
// case IOHOOK_ERROR_OUT_OF_MEMORY:
|
||||
// loggerProc(LOG_LEVEL_ERROR, "Failed to allocate memory. (%#X)", status);
|
||||
// break;
|
||||
void pollEv(){
|
||||
if (events == NULL) { return; }
|
||||
|
||||
for (;eb_chan_buf_len(events)!=0;) {
|
||||
char* tmp;
|
||||
if (eb_chan_try_recv(events, (const void**) &tmp)
|
||||
== eb_chan_res_ok) {
|
||||
// send a char
|
||||
go_send(tmp);
|
||||
free(tmp);
|
||||
} else {
|
||||
//
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// case IOHOOK_ERROR_X_RECORD_GET_CONTEXT:
|
||||
// // NOTE This is the only platform specific error that occurs on hook_stop().
|
||||
// loggerProc(LOG_LEVEL_ERROR, "Failed to get XRecord context. (%#X)", status);
|
||||
// break;
|
||||
|
||||
// // Default error.
|
||||
// case IOHOOK_FAILURE:
|
||||
// default:
|
||||
// loggerProc(LOG_LEVEL_ERROR, "An unknown hook error occurred. (%#X)", status);
|
||||
// break;
|
||||
// }
|
||||
}
|
||||
case EVENT_KEY_RELEASED:
|
||||
snprintf(buffer + length, sizeof(buffer) - length,
|
||||
",keycode=%u,rawcode=0x%X",
|
||||
event->data.keyboard.keycode, event->data.keyboard.rawcode);
|
||||
int key_code = (uint16_t) event->data.keyboard.keycode;
|
||||
|
||||
if (event->data.keyboard.keycode == VC_ESCAPE
|
||||
&& atoi(cevent) == 11) {
|
||||
int stopEvent = stop_event();
|
||||
// printf("stop_event%d\n", stopEvent);
|
||||
cstatus = 0;
|
||||
}
|
||||
|
||||
// printf("atoi(str)---%d\n", atoi(cevent));
|
||||
if (key_code == atoi(cevent)) {
|
||||
int stopEvent = stop_event();
|
||||
// printf("%d\n", stopEvent);
|
||||
cstatus = 0;
|
||||
}
|
||||
break;
|
||||
|
||||
case EVENT_KEY_TYPED:
|
||||
snprintf(buffer + length, sizeof(buffer) - length,
|
||||
",keychar=%lc,rawcode=%u",
|
||||
(uint16_t) event->data.keyboard.keychar,
|
||||
event->data.keyboard.rawcode);
|
||||
|
||||
#ifdef WE_REALLY_WANT_A_POINTER
|
||||
char *buf = malloc (6);
|
||||
#else
|
||||
char buf[6];
|
||||
#endif
|
||||
|
||||
sprintf(buf, "%lc", (uint16_t) event->data.keyboard.keychar);
|
||||
|
||||
#ifdef WE_REALLY_WANT_A_POINTER
|
||||
free (buf);
|
||||
#endif
|
||||
|
||||
if (strcmp(buf, cevent) == 0) {
|
||||
int stopEvent = stop_event();
|
||||
// printf("%d\n", stopEvent);
|
||||
cstatus = 0;
|
||||
}
|
||||
// return (char*) event->data.keyboard.keychar;
|
||||
break;
|
||||
|
||||
case EVENT_MOUSE_PRESSED:
|
||||
case EVENT_MOUSE_RELEASED:
|
||||
case EVENT_MOUSE_CLICKED:
|
||||
case EVENT_MOUSE_MOVED:
|
||||
case EVENT_MOUSE_DRAGGED:
|
||||
snprintf(buffer + length, sizeof(buffer) - length,
|
||||
",x=%i,y=%i,button=%i,clicks=%i",
|
||||
event->data.mouse.x, event->data.mouse.y,
|
||||
event->data.mouse.button, event->data.mouse.clicks);
|
||||
|
||||
int abutton = event->data.mouse.button;
|
||||
int aclicks = event->data.mouse.clicks;
|
||||
int amouse = -1;
|
||||
|
||||
if (strcmp(cevent, "mleft") == 0) {
|
||||
amouse = 1;
|
||||
}
|
||||
if (strcmp(cevent, "mright") == 0) {
|
||||
amouse = 2;
|
||||
}
|
||||
if (strcmp(cevent, "wheelDown") == 0) {
|
||||
amouse = 4;
|
||||
}
|
||||
if (strcmp(cevent, "wheelUp") == 0) {
|
||||
amouse = 5;
|
||||
}
|
||||
if (strcmp(cevent, "wheelLeft") == 0) {
|
||||
amouse = 6;
|
||||
}
|
||||
if (strcmp(cevent, "wheelRight") == 0) {
|
||||
amouse = 7;
|
||||
}
|
||||
if (abutton == amouse && aclicks == 1) {
|
||||
int stopEvent = stop_event();
|
||||
cstatus = 0;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case EVENT_MOUSE_WHEEL:
|
||||
snprintf(buffer + length, sizeof(buffer) - length,
|
||||
",type=%i,amount=%i,rotation=%i",
|
||||
event->data.wheel.type, event->data.wheel.amount,
|
||||
event->data.wheel.rotation);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
// fprintf(stdout, "----%s\n", buffer);
|
||||
void endPoll(){
|
||||
sending = false;
|
||||
pollEv(); // remove last things from channel
|
||||
eb_chan_release(events);
|
||||
}
|
||||
|
||||
int add_event(char *key_event) {
|
||||
// (uint16_t *)
|
||||
cevent = key_event;
|
||||
add_hook(&dispatch_proc_end);
|
||||
|
||||
return cstatus;
|
||||
}
|
||||
|
||||
void add_event_async(){
|
||||
add_hook(&dispatch_proc);
|
||||
}
|
||||
|
||||
int add_hook(dispatcher_t dispatch) {
|
||||
// Set the logger callback for library output.
|
||||
hook_set_logger(&loggerProc);
|
||||
|
||||
// Set the event callback for IOhook events.
|
||||
hook_set_dispatch_proc(&dispatch_proc);
|
||||
hook_set_dispatch_proc(dispatch);
|
||||
|
||||
// Start the hook and block.
|
||||
// NOTE If EVENT_HOOK_ENABLED was delivered, the status will always succeed.
|
||||
int status = hook_run();
|
||||
@ -224,9 +142,9 @@ int add_event(char *key_event) {
|
||||
break;
|
||||
}
|
||||
|
||||
// return status;
|
||||
return status;
|
||||
// printf("%d\n", status);
|
||||
return cstatus;
|
||||
// return cstatus;
|
||||
}
|
||||
|
||||
int stop_event(){
|
||||
@ -242,7 +160,7 @@ int stop_event(){
|
||||
loggerProc(LOG_LEVEL_ERROR, "Failed to get XRecord context. (%#X)", status);
|
||||
break;
|
||||
|
||||
// Default error.
|
||||
// Default error.
|
||||
case IOHOOK_FAILURE:
|
||||
default:
|
||||
// loggerProc(LOG_LEVEL_ERROR, "An unknown hook error occurred. (%#X)", status);
|
||||
@ -250,4 +168,6 @@ int stop_event(){
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
2
vendor/github.com/robotn/gohook/event/os.h
generated
vendored
2
vendor/github.com/robotn/gohook/event/os.h
generated
vendored
@ -23,7 +23,7 @@
|
||||
#endif /* USE_X11 */
|
||||
|
||||
#if defined(IS_WINDOWS)
|
||||
#define STRICT /* Require use of exact types. */
|
||||
// #define STRICT /* Require use of exact types. */
|
||||
#define WIN32_LEAN_AND_MEAN 1 /* Speed up compilation. */
|
||||
#include <windows.h>
|
||||
#elif !defined(IS_MACOSX) && !defined(USE_X11)
|
||||
|
17
vendor/github.com/robotn/gohook/event/pub.h
generated
vendored
17
vendor/github.com/robotn/gohook/event/pub.h
generated
vendored
@ -33,21 +33,28 @@
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "../hook/iohook.h"
|
||||
|
||||
#include "../hook/iohook.h"
|
||||
#include "../chan/eb_chan.h"
|
||||
|
||||
eb_chan events;
|
||||
bool sending = false;
|
||||
|
||||
int vccode[100];
|
||||
int codesz;
|
||||
int codesz;
|
||||
|
||||
char *cevent;
|
||||
int rrevent;
|
||||
// uint16_t *cevent;
|
||||
int cstatus = 1;
|
||||
int event_status;
|
||||
int rrevent;
|
||||
|
||||
|
||||
int stop_event();
|
||||
int add_hook(dispatcher_t dispatch);
|
||||
void add_event_async();
|
||||
int add_event(char *key_event);
|
||||
int stop_event();
|
||||
|
||||
void dispatch_proc_end(iohook_event * const event);
|
||||
// int allEvent(char *key_event);
|
||||
int allEvent(char *key_event, int vcode[], int size);
|
||||
|
||||
|
40
vendor/github.com/robotn/gohook/example/main.go
generated
vendored
Normal file
40
vendor/github.com/robotn/gohook/example/main.go
generated
vendored
Normal file
@ -0,0 +1,40 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/robotn/gohook"
|
||||
)
|
||||
|
||||
func add() {
|
||||
s := hook.Start()
|
||||
defer hook.End()
|
||||
|
||||
ct := false
|
||||
for {
|
||||
i := <-s
|
||||
|
||||
if i.Kind == hook.KeyHold && i.Rawcode == 59 {
|
||||
ct = true
|
||||
}
|
||||
|
||||
if ct && i.Rawcode == 12 {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func base() {
|
||||
EvChan := hook.Start()
|
||||
defer hook.End()
|
||||
|
||||
for ev := range EvChan {
|
||||
fmt.Println(ev)
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
base()
|
||||
|
||||
add()
|
||||
}
|
37
vendor/github.com/robotn/gohook/extern.go
generated
vendored
Normal file
37
vendor/github.com/robotn/gohook/extern.go
generated
vendored
Normal file
@ -0,0 +1,37 @@
|
||||
package hook
|
||||
|
||||
/*
|
||||
|
||||
// #include "event/hook_async.h"
|
||||
*/
|
||||
import "C"
|
||||
import (
|
||||
"log"
|
||||
"time"
|
||||
|
||||
"encoding/json"
|
||||
)
|
||||
|
||||
//export go_send
|
||||
func go_send(s *C.char) {
|
||||
str := []byte(C.GoString(s))
|
||||
out := Event{}
|
||||
|
||||
err := json.Unmarshal(str, &out)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
if out.Keychar != CharUndefined {
|
||||
raw2key[out.Rawcode] = string([]rune{out.Keychar})
|
||||
}
|
||||
|
||||
// todo bury this deep into the C lib so that the time is correct
|
||||
out.When = time.Now() // at least it's consistent
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
// todo: maybe make non-bloking
|
||||
ev <- out
|
||||
}
|
135
vendor/github.com/robotn/gohook/hook.go
generated
vendored
135
vendor/github.com/robotn/gohook/hook.go
generated
vendored
@ -20,15 +20,146 @@ package hook
|
||||
//#cgo windows LDFLAGS: -lgdi32 -luser32
|
||||
|
||||
#include "event/goEvent.h"
|
||||
// #include "event/hook_async.h"
|
||||
|
||||
*/
|
||||
import "C"
|
||||
|
||||
import (
|
||||
// "fmt"
|
||||
"fmt"
|
||||
"time"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
const (
|
||||
// HookEnabled honk enable status
|
||||
HookEnabled = 1 // iota
|
||||
HookDisabled = 2
|
||||
|
||||
KeyDown = 3
|
||||
KeyHold = 4
|
||||
KeyUp = 5
|
||||
|
||||
MouseUp = 6
|
||||
MouseHold = 7
|
||||
MouseDown = 8
|
||||
MouseMove = 9
|
||||
MouseDrag = 10
|
||||
MouseWheel = 11
|
||||
|
||||
FakeEvent = 12
|
||||
// Keychar could be v
|
||||
CharUndefined = 0xFFFF
|
||||
WheelUp = -1
|
||||
WheelDown = 1
|
||||
)
|
||||
|
||||
// Event Holds a system event
|
||||
// If it's a Keyboard event the relevant fields are:
|
||||
// Mask, Keycode, Rawcode, and Keychar,
|
||||
// Keychar is probably what you want.
|
||||
// If it's a Mouse event the relevant fields are:
|
||||
// Button, Clicks, X, Y, Amount, Rotation and Direction
|
||||
type Event struct {
|
||||
Kind uint8 `json:"id"`
|
||||
When time.Time
|
||||
Mask uint16 `json:"mask"`
|
||||
Reserved uint16 `json:"reserved"`
|
||||
|
||||
Keycode uint16 `json:"keycode"`
|
||||
Rawcode uint16 `json:"rawcode"`
|
||||
Keychar rune `json:"keychar"`
|
||||
|
||||
Button uint16 `json:"button"`
|
||||
Clicks uint16 `json:"clicks"`
|
||||
|
||||
X int16 `json:"x"`
|
||||
Y int16 `json:"y"`
|
||||
|
||||
Amount uint16 `json:"amount"`
|
||||
Rotation int16 `json:"rotation"`
|
||||
Direction uint8 `json:"direction"`
|
||||
}
|
||||
|
||||
var (
|
||||
ev = make(chan Event, 1024)
|
||||
asyncon = false
|
||||
)
|
||||
|
||||
// String return hook kind string
|
||||
func (e Event) String() string {
|
||||
switch e.Kind {
|
||||
case HookEnabled:
|
||||
return fmt.Sprintf("%v - Event: {Kind: HookEnabled}", e.When)
|
||||
case HookDisabled:
|
||||
return fmt.Sprintf("%v - Event: {Kind: HookDisabled}", e.When)
|
||||
case KeyUp:
|
||||
return fmt.Sprintf("%v - Event: {Kind: KeyUp, Rawcode: %v, Keychar: %v}", e.When, e.Rawcode, e.Keychar)
|
||||
case KeyHold:
|
||||
return fmt.Sprintf("%v - Event: {Kind: KeyHold, Rawcode: %v, Keychar: %v}", e.When, e.Rawcode, e.Keychar)
|
||||
case KeyDown:
|
||||
return fmt.Sprintf("%v - Event: {Kind: KeyDown, Rawcode: %v, Keychar: %v}", e.When, e.Rawcode, e.Keychar)
|
||||
case MouseUp:
|
||||
return fmt.Sprintf("%v - Event: {Kind: MouseUp, Button: %v, X: %v, Y: %v, Clicks: %v}", e.When, e.Button, e.X, e.Y, e.Clicks)
|
||||
case MouseHold:
|
||||
return fmt.Sprintf("%v - Event: {Kind: MouseHold, Button: %v, X: %v, Y: %v, Clicks: %v}", e.When, e.Button, e.X, e.Y, e.Clicks)
|
||||
case MouseDown:
|
||||
return fmt.Sprintf("%v - Event: {Kind: MouseDown, Button: %v, X: %v, Y: %v, Clicks: %v}", e.When, e.Button, e.X, e.Y, e.Clicks)
|
||||
case MouseMove:
|
||||
return fmt.Sprintf("%v - Event: {Kind: MouseMove, Button: %v, X: %v, Y: %v, Clicks: %v}", e.When, e.Button, e.X, e.Y, e.Clicks)
|
||||
case MouseDrag:
|
||||
return fmt.Sprintf("%v - Event: {Kind: MouseDrag, Button: %v, X: %v, Y: %v, Clicks: %v}", e.When, e.Button, e.X, e.Y, e.Clicks)
|
||||
case MouseWheel:
|
||||
return fmt.Sprintf("%v - Event: {Kind: MouseWheel, Amount: %v, Rotation: %v, Direction: %v}", e.When, e.Amount, e.Rotation, e.Direction)
|
||||
case FakeEvent:
|
||||
return fmt.Sprintf("%v - Event: {Kind: FakeEvent}", e.When)
|
||||
}
|
||||
|
||||
return "Unknown event, contact the mantainers"
|
||||
}
|
||||
|
||||
// RawcodetoKeychar rawcode to keychar
|
||||
func RawcodetoKeychar(r uint16) string {
|
||||
return raw2key[r]
|
||||
}
|
||||
|
||||
// KeychartoRawcode key char to rawcode
|
||||
func KeychartoRawcode(kc string) uint16 {
|
||||
return keytoraw[kc]
|
||||
}
|
||||
|
||||
// Start Adds global event hook to OS
|
||||
// returns event channel
|
||||
func Start() chan Event {
|
||||
asyncon = true
|
||||
go C.start_ev()
|
||||
|
||||
go func() {
|
||||
for {
|
||||
C.pollEv()
|
||||
time.Sleep(time.Millisecond * 50)
|
||||
|
||||
// todo: find smallest time that does not destroy the cpu utilization
|
||||
if !asyncon {
|
||||
return
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
return ev
|
||||
}
|
||||
|
||||
// End removes global event hook
|
||||
func End() {
|
||||
C.endPoll()
|
||||
C.stop_event()
|
||||
|
||||
for len(ev) != 0 {
|
||||
<-ev
|
||||
}
|
||||
|
||||
asyncon = false
|
||||
}
|
||||
|
||||
// AddEvent add event listener
|
||||
func AddEvent(key string) int {
|
||||
cs := C.CString(key)
|
||||
|
347
vendor/github.com/robotn/gohook/hook/darwin/hook_c.h
generated
vendored
347
vendor/github.com/robotn/gohook/hook/darwin/hook_c.h
generated
vendored
@ -1110,235 +1110,234 @@ CGEventRef hook_event_proc(CGEventTapProxy tap_proxy, CGEventType type, CGEventR
|
||||
IOHOOK_API int hook_run() {
|
||||
int status = IOHOOK_SUCCESS;
|
||||
|
||||
do {
|
||||
// Reset the restart flag...
|
||||
restart_tap = false;
|
||||
// Check for accessibility each time we start the loop.
|
||||
if (is_accessibility_enabled()) {
|
||||
logger(LOG_LEVEL_DEBUG, "%s [%u]: Accessibility API is enabled.\n",
|
||||
__FUNCTION__, __LINE__);
|
||||
|
||||
// Check for accessibility each time we start the loop.
|
||||
if (is_accessibility_enabled()) {
|
||||
logger(LOG_LEVEL_DEBUG, "%s [%u]: Accessibility API is enabled.\n",
|
||||
__FUNCTION__, __LINE__);
|
||||
do {
|
||||
// Reset the restart flag...
|
||||
restart_tap = false;
|
||||
|
||||
// Initialize starting modifiers.
|
||||
initialize_modifiers();
|
||||
// Initialize starting modifiers.
|
||||
initialize_modifiers();
|
||||
|
||||
// Try and allocate memory for hook_info.
|
||||
hook_info *hook = malloc(sizeof(hook_info));
|
||||
if (hook != NULL) {
|
||||
// Setup the event mask to listen for.
|
||||
#ifdef USE_DEBUG
|
||||
CGEventMask event_mask = kCGEventMaskForAllEvents;
|
||||
#else
|
||||
CGEventMask event_mask = CGEventMaskBit(kCGEventKeyDown) |
|
||||
CGEventMaskBit(kCGEventKeyUp) |
|
||||
CGEventMaskBit(kCGEventFlagsChanged) |
|
||||
// Try and allocate memory for hook_info.
|
||||
hook_info *hook = malloc(sizeof(hook_info));
|
||||
if (hook != NULL) {
|
||||
// Setup the event mask to listen for.
|
||||
#ifdef USE_DEBUG
|
||||
CGEventMask event_mask = kCGEventMaskForAllEvents;
|
||||
#else
|
||||
CGEventMask event_mask = CGEventMaskBit(kCGEventKeyDown) |
|
||||
CGEventMaskBit(kCGEventKeyUp) |
|
||||
CGEventMaskBit(kCGEventFlagsChanged) |
|
||||
|
||||
CGEventMaskBit(kCGEventLeftMouseDown) |
|
||||
CGEventMaskBit(kCGEventLeftMouseUp) |
|
||||
CGEventMaskBit(kCGEventLeftMouseDragged) |
|
||||
CGEventMaskBit(kCGEventLeftMouseDown) |
|
||||
CGEventMaskBit(kCGEventLeftMouseUp) |
|
||||
CGEventMaskBit(kCGEventLeftMouseDragged) |
|
||||
|
||||
CGEventMaskBit(kCGEventRightMouseDown) |
|
||||
CGEventMaskBit(kCGEventRightMouseUp) |
|
||||
CGEventMaskBit(kCGEventRightMouseDragged) |
|
||||
CGEventMaskBit(kCGEventRightMouseDown) |
|
||||
CGEventMaskBit(kCGEventRightMouseUp) |
|
||||
CGEventMaskBit(kCGEventRightMouseDragged) |
|
||||
|
||||
CGEventMaskBit(kCGEventOtherMouseDown) |
|
||||
CGEventMaskBit(kCGEventOtherMouseUp) |
|
||||
CGEventMaskBit(kCGEventOtherMouseDragged) |
|
||||
CGEventMaskBit(kCGEventOtherMouseDown) |
|
||||
CGEventMaskBit(kCGEventOtherMouseUp) |
|
||||
CGEventMaskBit(kCGEventOtherMouseDragged) |
|
||||
|
||||
CGEventMaskBit(kCGEventMouseMoved) |
|
||||
CGEventMaskBit(kCGEventScrollWheel) |
|
||||
CGEventMaskBit(kCGEventMouseMoved) |
|
||||
CGEventMaskBit(kCGEventScrollWheel) |
|
||||
|
||||
// NOTE This event is undocumented and used
|
||||
// for caps-lock release and multi-media keys.
|
||||
CGEventMaskBit(NX_SYSDEFINED);
|
||||
#endif
|
||||
// NOTE This event is undocumented and used
|
||||
// for caps-lock release and multi-media keys.
|
||||
CGEventMaskBit(NX_SYSDEFINED);
|
||||
#endif
|
||||
|
||||
// Create the event tap.
|
||||
hook->port = CGEventTapCreate(
|
||||
kCGSessionEventTap, // kCGHIDEventTap
|
||||
kCGHeadInsertEventTap, // kCGTailAppendEventTap
|
||||
kCGEventTapOptionDefault, // kCGEventTapOptionListenOnly See Bug #22
|
||||
event_mask,
|
||||
hook_event_proc,
|
||||
NULL);
|
||||
// Create the event tap.
|
||||
hook->port = CGEventTapCreate(
|
||||
kCGSessionEventTap, // kCGHIDEventTap
|
||||
kCGHeadInsertEventTap, // kCGTailAppendEventTap
|
||||
kCGEventTapOptionDefault, // kCGEventTapOptionListenOnly See Bug #22
|
||||
event_mask,
|
||||
hook_event_proc,
|
||||
NULL);
|
||||
|
||||
if (hook->port != NULL) {
|
||||
logger(LOG_LEVEL_DEBUG, "%s [%u]: CGEventTapCreate Successful.\n",
|
||||
__FUNCTION__, __LINE__);
|
||||
|
||||
// Create the runloop event source from the event tap.
|
||||
hook->source = CFMachPortCreateRunLoopSource(kCFAllocatorDefault, hook->port, 0);
|
||||
if (hook->source != NULL) {
|
||||
logger(LOG_LEVEL_DEBUG, "%s [%u]: CFMachPortCreateRunLoopSource successful.\n",
|
||||
if (hook->port != NULL) {
|
||||
logger(LOG_LEVEL_DEBUG, "%s [%u]: CGEventTapCreate Successful.\n",
|
||||
__FUNCTION__, __LINE__);
|
||||
|
||||
event_loop = CFRunLoopGetCurrent();
|
||||
if (event_loop != NULL) {
|
||||
logger(LOG_LEVEL_DEBUG, "%s [%u]: CFRunLoopGetCurrent successful.\n",
|
||||
// Create the runloop event source from the event tap.
|
||||
hook->source = CFMachPortCreateRunLoopSource(kCFAllocatorDefault, hook->port, 0);
|
||||
if (hook->source != NULL) {
|
||||
logger(LOG_LEVEL_DEBUG, "%s [%u]: CFMachPortCreateRunLoopSource successful.\n",
|
||||
__FUNCTION__, __LINE__);
|
||||
|
||||
// Create run loop observers.
|
||||
hook->observer = CFRunLoopObserverCreate(
|
||||
kCFAllocatorDefault,
|
||||
kCFRunLoopEntry | kCFRunLoopExit, //kCFRunLoopAllActivities,
|
||||
true,
|
||||
0,
|
||||
hook_status_proc,
|
||||
NULL);
|
||||
|
||||
if (hook->observer != NULL) {
|
||||
logger(LOG_LEVEL_DEBUG, "%s [%u]: CFRunLoopObserverCreate successful.\n",
|
||||
event_loop = CFRunLoopGetCurrent();
|
||||
if (event_loop != NULL) {
|
||||
logger(LOG_LEVEL_DEBUG, "%s [%u]: CFRunLoopGetCurrent successful.\n",
|
||||
__FUNCTION__, __LINE__);
|
||||
|
||||
tis_message = (TISMessage *) calloc(1, sizeof(TISMessage));
|
||||
if (tis_message != NULL) {
|
||||
if (! CFEqual(event_loop, CFRunLoopGetMain())) {
|
||||
#ifdef USE_WEAK_IMPORT
|
||||
if (dispatch_sync_f == NULL || dispatch_get_main_queue == NULL) {
|
||||
#else
|
||||
*(void **) (&dispatch_sync_f_f) = dlsym(RTLD_DEFAULT, "dispatch_sync_f");
|
||||
const char *dlError = dlerror();
|
||||
if (dlError != NULL) {
|
||||
logger(LOG_LEVEL_DEBUG, "%s [%u]: %s.\n",
|
||||
__FUNCTION__, __LINE__, dlError);
|
||||
}
|
||||
// Create run loop observers.
|
||||
hook->observer = CFRunLoopObserverCreate(
|
||||
kCFAllocatorDefault,
|
||||
kCFRunLoopEntry | kCFRunLoopExit, //kCFRunLoopAllActivities,
|
||||
true,
|
||||
0,
|
||||
hook_status_proc,
|
||||
NULL);
|
||||
|
||||
*(void **) (&dispatch_get_main_queue_f) = dlsym(RTLD_DEFAULT, "dispatch_get_main_queue");
|
||||
dlError = dlerror();
|
||||
if (dlError != NULL) {
|
||||
logger(LOG_LEVEL_DEBUG, "%s [%u]: %s.\n",
|
||||
__FUNCTION__, __LINE__, dlError);
|
||||
}
|
||||
if (hook->observer != NULL) {
|
||||
logger(LOG_LEVEL_DEBUG, "%s [%u]: CFRunLoopObserverCreate successful.\n",
|
||||
__FUNCTION__, __LINE__);
|
||||
|
||||
if (dispatch_sync_f_f == NULL || dispatch_get_main_queue_f == NULL) {
|
||||
#endif
|
||||
logger(LOG_LEVEL_DEBUG, "%s [%u]: Failed to locate dispatch_sync_f() or dispatch_get_main_queue()!\n",
|
||||
__FUNCTION__, __LINE__);
|
||||
|
||||
#if ! defined(USE_CARBON_LEGACY) && defined(USE_COREFOUNDATION)
|
||||
logger(LOG_LEVEL_DEBUG, "%s [%u]: Falling back to runloop signaling.\n",
|
||||
__FUNCTION__, __LINE__);
|
||||
|
||||
int runloop_status = start_message_port_runloop();
|
||||
if (runloop_status != IOHOOK_SUCCESS) {
|
||||
return runloop_status;
|
||||
tis_message = (TISMessage *) calloc(1, sizeof(TISMessage));
|
||||
if (tis_message != NULL) {
|
||||
if (! CFEqual(event_loop, CFRunLoopGetMain())) {
|
||||
#ifdef USE_WEAK_IMPORT
|
||||
if (dispatch_sync_f == NULL || dispatch_get_main_queue == NULL) {
|
||||
#else
|
||||
*(void **) (&dispatch_sync_f_f) = dlsym(RTLD_DEFAULT, "dispatch_sync_f");
|
||||
const char *dlError = dlerror();
|
||||
if (dlError != NULL) {
|
||||
logger(LOG_LEVEL_DEBUG, "%s [%u]: %s.\n",
|
||||
__FUNCTION__, __LINE__, dlError);
|
||||
}
|
||||
|
||||
*(void **) (&dispatch_get_main_queue_f) = dlsym(RTLD_DEFAULT, "dispatch_get_main_queue");
|
||||
dlError = dlerror();
|
||||
if (dlError != NULL) {
|
||||
logger(LOG_LEVEL_DEBUG, "%s [%u]: %s.\n",
|
||||
__FUNCTION__, __LINE__, dlError);
|
||||
}
|
||||
|
||||
if (dispatch_sync_f_f == NULL || dispatch_get_main_queue_f == NULL) {
|
||||
#endif
|
||||
logger(LOG_LEVEL_DEBUG, "%s [%u]: Failed to locate dispatch_sync_f() or dispatch_get_main_queue()!\n",
|
||||
__FUNCTION__, __LINE__);
|
||||
|
||||
#if ! defined(USE_CARBON_LEGACY) && defined(USE_COREFOUNDATION)
|
||||
logger(LOG_LEVEL_DEBUG, "%s [%u]: Falling back to runloop signaling.\n",
|
||||
__FUNCTION__, __LINE__);
|
||||
|
||||
int runloop_status = start_message_port_runloop();
|
||||
if (runloop_status != IOHOOK_SUCCESS) {
|
||||
return runloop_status;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Add the event source and observer to the runloop mode.
|
||||
CFRunLoopAddSource(event_loop, hook->source, kCFRunLoopDefaultMode);
|
||||
CFRunLoopAddObserver(event_loop, hook->observer, kCFRunLoopDefaultMode);
|
||||
// Add the event source and observer to the runloop mode.
|
||||
CFRunLoopAddSource(event_loop, hook->source, kCFRunLoopDefaultMode);
|
||||
CFRunLoopAddObserver(event_loop, hook->observer, kCFRunLoopDefaultMode);
|
||||
|
||||
#ifdef USE_OBJC
|
||||
// Create a garbage collector to handle Cocoa events correctly.
|
||||
Class NSAutoreleasePool_class = (Class) objc_getClass("NSAutoreleasePool");
|
||||
id pool = class_createInstance(NSAutoreleasePool_class, 0);
|
||||
auto_release_pool = objc_msgSend(pool, sel_registerName("init"));
|
||||
#endif
|
||||
|
||||
// Start the hook thread runloop.
|
||||
CFRunLoopRun();
|
||||
|
||||
|
||||
#ifdef USE_OBJC
|
||||
//objc_msgSend(auto_release_pool, sel_registerName("drain"));
|
||||
objc_msgSend(auto_release_pool, sel_registerName("release"));
|
||||
#endif
|
||||
|
||||
// Lock back up until we are done processing the exit.
|
||||
if (CFRunLoopContainsObserver(event_loop, hook->observer, kCFRunLoopDefaultMode)) {
|
||||
CFRunLoopRemoveObserver(event_loop, hook->observer, kCFRunLoopDefaultMode);
|
||||
}
|
||||
|
||||
if (CFRunLoopContainsSource(event_loop, hook->source, kCFRunLoopDefaultMode)) {
|
||||
CFRunLoopRemoveSource(event_loop, hook->source, kCFRunLoopDefaultMode);
|
||||
}
|
||||
|
||||
#if ! defined(USE_CARBON_LEGACY) && defined(USE_COREFOUNDATION)
|
||||
if (! CFEqual(event_loop, CFRunLoopGetMain())) {
|
||||
#ifdef USE_WEAK_IMPORT
|
||||
if (dispatch_sync_f == NULL || dispatch_get_main_queue == NULL) {
|
||||
#else
|
||||
if (dispatch_sync_f_f == NULL || dispatch_get_main_queue_f == NULL) {
|
||||
#ifdef USE_OBJC
|
||||
// Create a garbage collector to handle Cocoa events correctly.
|
||||
Class NSAutoreleasePool_class = (Class) objc_getClass("NSAutoreleasePool");
|
||||
id pool = class_createInstance(NSAutoreleasePool_class, 0);
|
||||
auto_release_pool = objc_msgSend(pool, sel_registerName("init"));
|
||||
#endif
|
||||
stop_message_port_runloop();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
// Free the TIS Message.
|
||||
free(tis_message);
|
||||
// Start the hook thread runloop.
|
||||
CFRunLoopRun();
|
||||
|
||||
|
||||
#ifdef USE_OBJC
|
||||
//objc_msgSend(auto_release_pool, sel_registerName("drain"));
|
||||
objc_msgSend(auto_release_pool, sel_registerName("release"));
|
||||
#endif
|
||||
|
||||
// Lock back up until we are done processing the exit.
|
||||
if (CFRunLoopContainsObserver(event_loop, hook->observer, kCFRunLoopDefaultMode)) {
|
||||
CFRunLoopRemoveObserver(event_loop, hook->observer, kCFRunLoopDefaultMode);
|
||||
}
|
||||
|
||||
if (CFRunLoopContainsSource(event_loop, hook->source, kCFRunLoopDefaultMode)) {
|
||||
CFRunLoopRemoveSource(event_loop, hook->source, kCFRunLoopDefaultMode);
|
||||
}
|
||||
|
||||
#if ! defined(USE_CARBON_LEGACY) && defined(USE_COREFOUNDATION)
|
||||
if (! CFEqual(event_loop, CFRunLoopGetMain())) {
|
||||
#ifdef USE_WEAK_IMPORT
|
||||
if (dispatch_sync_f == NULL || dispatch_get_main_queue == NULL) {
|
||||
#else
|
||||
if (dispatch_sync_f_f == NULL || dispatch_get_main_queue_f == NULL) {
|
||||
#endif
|
||||
stop_message_port_runloop();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
// Free the TIS Message.
|
||||
free(tis_message);
|
||||
}
|
||||
else {
|
||||
logger(LOG_LEVEL_ERROR, "%s [%u]: Failed to allocate memory for TIS message structure!\n",
|
||||
__FUNCTION__, __LINE__);
|
||||
|
||||
// Set the exit status.
|
||||
status = IOHOOK_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
// Invalidate and free hook observer.
|
||||
CFRunLoopObserverInvalidate(hook->observer);
|
||||
CFRelease(hook->observer);
|
||||
}
|
||||
else {
|
||||
logger(LOG_LEVEL_ERROR, "%s [%u]: Failed to allocate memory for TIS message structure!\n",
|
||||
// We cant do a whole lot of anything if we cant
|
||||
// create run loop observer.
|
||||
logger(LOG_LEVEL_ERROR, "%s [%u]: CFRunLoopObserverCreate failure!\n",
|
||||
__FUNCTION__, __LINE__);
|
||||
|
||||
// Set the exit status.
|
||||
status = IOHOOK_ERROR_OUT_OF_MEMORY;
|
||||
status = IOHOOK_ERROR_CREATE_OBSERVER;
|
||||
}
|
||||
|
||||
// Invalidate and free hook observer.
|
||||
CFRunLoopObserverInvalidate(hook->observer);
|
||||
CFRelease(hook->observer);
|
||||
}
|
||||
else {
|
||||
// We cant do a whole lot of anything if we cant
|
||||
// create run loop observer.
|
||||
logger(LOG_LEVEL_ERROR, "%s [%u]: CFRunLoopObserverCreate failure!\n",
|
||||
logger(LOG_LEVEL_ERROR, "%s [%u]: CFRunLoopGetCurrent failure!\n",
|
||||
__FUNCTION__, __LINE__);
|
||||
|
||||
// Set the exit status.
|
||||
status = IOHOOK_ERROR_CREATE_OBSERVER;
|
||||
status = IOHOOK_ERROR_GET_RUNLOOP;
|
||||
}
|
||||
|
||||
// Clean up the event source.
|
||||
CFRelease(hook->source);
|
||||
}
|
||||
else {
|
||||
logger(LOG_LEVEL_ERROR, "%s [%u]: CFRunLoopGetCurrent failure!\n",
|
||||
logger(LOG_LEVEL_ERROR, "%s [%u]: CFMachPortCreateRunLoopSource failure!\n",
|
||||
__FUNCTION__, __LINE__);
|
||||
|
||||
// Set the exit status.
|
||||
status = IOHOOK_ERROR_GET_RUNLOOP;
|
||||
status = IOHOOK_ERROR_CREATE_RUN_LOOP_SOURCE;
|
||||
}
|
||||
|
||||
// Clean up the event source.
|
||||
CFRelease(hook->source);
|
||||
// Stop the CFMachPort from receiving any more messages.
|
||||
CFMachPortInvalidate(hook->port);
|
||||
CFRelease(hook->port);
|
||||
}
|
||||
else {
|
||||
logger(LOG_LEVEL_ERROR, "%s [%u]: CFMachPortCreateRunLoopSource failure!\n",
|
||||
logger(LOG_LEVEL_ERROR, "%s [%u]: Failed to create event port!\n",
|
||||
__FUNCTION__, __LINE__);
|
||||
|
||||
// Set the exit status.
|
||||
status = IOHOOK_ERROR_CREATE_RUN_LOOP_SOURCE;
|
||||
status = IOHOOK_ERROR_CREATE_EVENT_PORT;
|
||||
}
|
||||
|
||||
// Stop the CFMachPort from receiving any more messages.
|
||||
CFMachPortInvalidate(hook->port);
|
||||
CFRelease(hook->port);
|
||||
// Free the hook structure.
|
||||
free(hook);
|
||||
}
|
||||
else {
|
||||
logger(LOG_LEVEL_ERROR, "%s [%u]: Failed to create event port!\n",
|
||||
__FUNCTION__, __LINE__);
|
||||
|
||||
// Set the exit status.
|
||||
status = IOHOOK_ERROR_CREATE_EVENT_PORT;
|
||||
status = IOHOOK_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
} while (restart_tap);
|
||||
} else {
|
||||
logger(LOG_LEVEL_ERROR, "%s [%u]: Accessibility API is disabled!\n",
|
||||
__FUNCTION__, __LINE__);
|
||||
|
||||
// Free the hook structure.
|
||||
free(hook);
|
||||
}
|
||||
else {
|
||||
status = IOHOOK_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
}
|
||||
else {
|
||||
logger(LOG_LEVEL_ERROR, "%s [%u]: Accessibility API is disabled!\n",
|
||||
__FUNCTION__, __LINE__);
|
||||
|
||||
// Set the exit status.
|
||||
status = IOHOOK_ERROR_AXAPI_DISABLED;
|
||||
}
|
||||
} while (restart_tap);
|
||||
// Set the exit status.
|
||||
status = IOHOOK_ERROR_AXAPI_DISABLED;
|
||||
}
|
||||
|
||||
logger(LOG_LEVEL_DEBUG, "%s [%u]: Something, something, something, complete.\n",
|
||||
__FUNCTION__, __LINE__);
|
||||
|
3
vendor/github.com/robotn/gohook/hook/iohook.h
generated
vendored
3
vendor/github.com/robotn/gohook/hook/iohook.h
generated
vendored
@ -79,7 +79,8 @@ typedef struct _screen_data {
|
||||
typedef struct _keyboard_event_data {
|
||||
uint16_t keycode;
|
||||
uint16_t rawcode;
|
||||
uint16_t keychar;
|
||||
// uint16_t keychar;
|
||||
uint32_t keychar;
|
||||
// char *keychar;
|
||||
} keyboard_event_data,
|
||||
key_pressed_event_data,
|
||||
|
4
vendor/github.com/robotn/gohook/hook/windows/input_c.h
generated
vendored
4
vendor/github.com/robotn/gohook/hook/windows/input_c.h
generated
vendored
@ -293,8 +293,8 @@ unsigned short keycode_to_scancode(DWORD vk_code, DWORD flags) {
|
||||
scancode = keycode_scancode_table[vk_code][0];
|
||||
|
||||
if (flags & LLKHF_EXTENDED) {
|
||||
logger(LOG_LEVEL_WARN, "%s [%u]: EXTD2, vk_code %li\n",
|
||||
__FUNCTION__, __LINE__, vk_code);
|
||||
// logger(LOG_LEVEL_WARN, "%s [%u]: EXTD2, vk_code %li\n",
|
||||
// __FUNCTION__, __LINE__, vk_code);
|
||||
|
||||
switch (vk_code) {
|
||||
case VK_PRIOR:
|
||||
|
352
vendor/github.com/robotn/gohook/tables.go
generated
vendored
Normal file
352
vendor/github.com/robotn/gohook/tables.go
generated
vendored
Normal file
@ -0,0 +1,352 @@
|
||||
package hook
|
||||
|
||||
var (
|
||||
raw2key = map[uint16]string{ // https://github.com/wesbos/keycodes
|
||||
0: "error",
|
||||
3: "break",
|
||||
8: "backspace",
|
||||
9: "tab",
|
||||
12: "clear",
|
||||
13: "enter",
|
||||
16: "shift",
|
||||
17: "ctrl",
|
||||
18: "alt",
|
||||
19: "pause/break",
|
||||
20: "caps lock",
|
||||
21: "hangul",
|
||||
25: "hanja",
|
||||
27: "escape",
|
||||
28: "conversion",
|
||||
29: "non-conversion",
|
||||
32: "spacebar",
|
||||
33: "page up",
|
||||
34: "page down",
|
||||
35: "end",
|
||||
36: "home",
|
||||
37: "left arrow",
|
||||
38: "up arrow",
|
||||
39: "right arrow",
|
||||
40: "down arrow",
|
||||
41: "select",
|
||||
42: "print",
|
||||
43: "execute",
|
||||
44: "Print Screen",
|
||||
45: "insert",
|
||||
46: "delete",
|
||||
47: "help",
|
||||
48: "0",
|
||||
49: "1",
|
||||
50: "2",
|
||||
51: "3",
|
||||
52: "4",
|
||||
53: "5",
|
||||
54: "6",
|
||||
55: "7",
|
||||
56: "8",
|
||||
57: "9",
|
||||
58: ":",
|
||||
59: ";",
|
||||
60: "<",
|
||||
61: "=",
|
||||
63: "ß",
|
||||
64: "@",
|
||||
65: "a",
|
||||
66: "b",
|
||||
67: "c",
|
||||
68: "d",
|
||||
69: "e",
|
||||
70: "f",
|
||||
71: "g",
|
||||
72: "h",
|
||||
73: "i",
|
||||
74: "j",
|
||||
75: "k",
|
||||
76: "l",
|
||||
77: "m",
|
||||
78: "n",
|
||||
79: "o",
|
||||
80: "p",
|
||||
81: "q",
|
||||
82: "r",
|
||||
83: "s",
|
||||
84: "t",
|
||||
85: "u",
|
||||
86: "v",
|
||||
87: "w",
|
||||
88: "x",
|
||||
89: "y",
|
||||
90: "z",
|
||||
91: "l-super",
|
||||
92: "r-super",
|
||||
93: "apps",
|
||||
95: "sleep",
|
||||
96: "numpad 0",
|
||||
97: "numpad 1",
|
||||
98: "numpad 2",
|
||||
99: "numpad 3",
|
||||
100: "numpad 4",
|
||||
101: "numpad 5",
|
||||
102: "numpad 6",
|
||||
103: "numpad 7",
|
||||
104: "numpad 8",
|
||||
105: "numpad 9",
|
||||
106: "multiply",
|
||||
107: "add",
|
||||
108: "numpad period",
|
||||
109: "subtract",
|
||||
110: "decimal point",
|
||||
111: "divide",
|
||||
112: "f1",
|
||||
113: "f2",
|
||||
114: "f3",
|
||||
115: "f4",
|
||||
116: "f5",
|
||||
117: "f6",
|
||||
118: "f7",
|
||||
119: "f8",
|
||||
120: "f9",
|
||||
121: "f10",
|
||||
122: "f11",
|
||||
123: "f12",
|
||||
124: "f13",
|
||||
125: "f14",
|
||||
126: "f15",
|
||||
127: "f16",
|
||||
128: "f17",
|
||||
129: "f18",
|
||||
130: "f19",
|
||||
131: "f20",
|
||||
132: "f21",
|
||||
133: "f22",
|
||||
134: "f23",
|
||||
135: "f24",
|
||||
144: "num lock",
|
||||
145: "scroll lock",
|
||||
160: "^",
|
||||
161: "!",
|
||||
162: "؛",
|
||||
163: "#",
|
||||
164: "$",
|
||||
165: "ù",
|
||||
166: "page backward",
|
||||
167: "page forward",
|
||||
168: "refresh",
|
||||
169: "closing paren (AZERTY)",
|
||||
170: "*",
|
||||
171: "~ + * key",
|
||||
172: "home key",
|
||||
173: "minus (firefox), mute/unmute",
|
||||
174: "decrease volume level",
|
||||
175: "increase volume level",
|
||||
176: "next",
|
||||
177: "previous",
|
||||
178: "stop",
|
||||
179: "play/pause",
|
||||
180: "e-mail",
|
||||
181: "mute/unmute (firefox)",
|
||||
182: "decrease volume level (firefox)",
|
||||
183: "increase volume level (firefox)",
|
||||
186: "semi-colon / ñ",
|
||||
187: "equal sign",
|
||||
188: "comma",
|
||||
189: "dash",
|
||||
190: "period",
|
||||
191: "forward slash / ç",
|
||||
192: "grave accent / ñ / æ / ö",
|
||||
193: "?, / or °",
|
||||
194: "numpad period (chrome)",
|
||||
219: "open bracket",
|
||||
220: "back slash",
|
||||
221: "close bracket / å",
|
||||
222: "single quote / ø / ä",
|
||||
223: "`",
|
||||
224: "left or right ⌘ key (firefox)",
|
||||
225: "altgr",
|
||||
226: "< /git >, left back slash",
|
||||
230: "GNOME Compose Key",
|
||||
231: "ç",
|
||||
233: "XF86Forward",
|
||||
234: "XF86Back",
|
||||
235: "non-conversion",
|
||||
240: "alphanumeric",
|
||||
242: "hiragana/katakana",
|
||||
243: "half-width/full-width",
|
||||
244: "kanji",
|
||||
251: "unlock trackpad (Chrome/Edge)",
|
||||
255: "toggle touchpad",
|
||||
}
|
||||
|
||||
keytoraw = map[string]uint16{
|
||||
"error": 0,
|
||||
"break": 3,
|
||||
"backspace": 8,
|
||||
"tab": 9,
|
||||
"clear": 12,
|
||||
"enter": 13,
|
||||
"shift": 16,
|
||||
"ctrl": 17,
|
||||
"alt": 18,
|
||||
"pause/break": 19,
|
||||
"caps lock": 20,
|
||||
"hangul": 21,
|
||||
"hanja": 25,
|
||||
"escape": 27,
|
||||
"conversion": 28,
|
||||
"non-conversion": 29,
|
||||
"spacebar": 32,
|
||||
"page up": 33,
|
||||
"page down": 34,
|
||||
"end": 35,
|
||||
"home": 36,
|
||||
"left arrow": 37,
|
||||
"up arrow": 38,
|
||||
"right arrow": 39,
|
||||
"down arrow": 40,
|
||||
"select": 41,
|
||||
"print": 42,
|
||||
"execute": 43,
|
||||
"Print Screen": 44,
|
||||
"insert": 45,
|
||||
"delete": 46,
|
||||
"help": 47,
|
||||
"0": 48,
|
||||
"1": 49,
|
||||
"2": 50,
|
||||
"3": 51,
|
||||
"4": 52,
|
||||
"5": 53,
|
||||
"6": 54,
|
||||
"7": 55,
|
||||
"8": 56,
|
||||
"9": 57,
|
||||
":": 58,
|
||||
";": 59,
|
||||
"<": 60,
|
||||
"=": 61,
|
||||
"ß": 63,
|
||||
"@": 64,
|
||||
"a": 65,
|
||||
"b": 66,
|
||||
"c": 67,
|
||||
"d": 68,
|
||||
"e": 69,
|
||||
"f": 70,
|
||||
"g": 71,
|
||||
"h": 72,
|
||||
"i": 73,
|
||||
"j": 74,
|
||||
"k": 75,
|
||||
"l": 76,
|
||||
"m": 77,
|
||||
"n": 78,
|
||||
"o": 79,
|
||||
"p": 80,
|
||||
"q": 81,
|
||||
"r": 82,
|
||||
"s": 83,
|
||||
"t": 84,
|
||||
"u": 85,
|
||||
"v": 86,
|
||||
"w": 87,
|
||||
"x": 88,
|
||||
"y": 89,
|
||||
"z": 90,
|
||||
"l-super": 91,
|
||||
"r-super": 92,
|
||||
"apps": 93,
|
||||
"sleep": 95,
|
||||
"numpad 0": 96,
|
||||
"numpad 1": 97,
|
||||
"numpad 2": 98,
|
||||
"numpad 3": 99,
|
||||
"numpad 4": 100,
|
||||
"numpad 5": 101,
|
||||
"numpad 6": 102,
|
||||
"numpad 7": 103,
|
||||
"numpad 8": 104,
|
||||
"numpad 9": 105,
|
||||
"multiply": 106,
|
||||
"add": 107,
|
||||
"numpad period": 108,
|
||||
"subtract": 109,
|
||||
"decimal point": 110,
|
||||
"divide": 111,
|
||||
"f1": 112,
|
||||
"f2": 113,
|
||||
"f3": 114,
|
||||
"f4": 115,
|
||||
"f5": 116,
|
||||
"f6": 117,
|
||||
"f7": 118,
|
||||
"f8": 119,
|
||||
"f9": 120,
|
||||
"f10": 121,
|
||||
"f11": 122,
|
||||
"f12": 123,
|
||||
"f13": 124,
|
||||
"f14": 125,
|
||||
"f15": 126,
|
||||
"f16": 127,
|
||||
"f17": 128,
|
||||
"f18": 129,
|
||||
"f19": 130,
|
||||
"f20": 131,
|
||||
"f21": 132,
|
||||
"f22": 133,
|
||||
"f23": 134,
|
||||
"f24": 135,
|
||||
"num lock": 144,
|
||||
"scroll lock": 145,
|
||||
"^": 160,
|
||||
"!": 161,
|
||||
"؛": 162,
|
||||
"#": 163,
|
||||
"$": 164,
|
||||
"ù": 165,
|
||||
"page backward": 166,
|
||||
"page forward": 167,
|
||||
"refresh": 168,
|
||||
"closing paren (AZERTY)": 169,
|
||||
"*": 170,
|
||||
"~ + * key": 171,
|
||||
"home key": 172,
|
||||
"minus (firefox), mute/unmute": 173,
|
||||
"decrease volume level": 174,
|
||||
"increase volume level": 175,
|
||||
"next": 176,
|
||||
"previous": 177,
|
||||
"stop": 178,
|
||||
"play/pause": 179,
|
||||
"e-mail": 180,
|
||||
"mute/unmute (firefox)": 181,
|
||||
"decrease volume level (firefox)": 182,
|
||||
"increase volume level (firefox)": 183,
|
||||
"semi-colon / ñ": 186,
|
||||
"equal sign": 187,
|
||||
"comma": 188,
|
||||
"dash": 189,
|
||||
"period": 190,
|
||||
"forward slash / ç": 191,
|
||||
"grave accent / ñ / æ / ö": 192,
|
||||
"?, / or °": 193,
|
||||
"numpad period (chrome)": 194,
|
||||
"open bracket": 219,
|
||||
"back slash": 220,
|
||||
"close bracket / å": 221,
|
||||
"single quote / ø / ä": 222,
|
||||
"`": 223,
|
||||
"left or right ⌘ key (firefox)": 224,
|
||||
"altgr": 225,
|
||||
"< /git >, left back slash": 226,
|
||||
"GNOME Compose Key": 230,
|
||||
"ç": 231,
|
||||
"XF86Forward": 233,
|
||||
"XF86Back": 234,
|
||||
"alphanumeric": 240,
|
||||
"hiragana/katakana": 242,
|
||||
"half-width/full-width": 243,
|
||||
"kanji": 244,
|
||||
"unlock trackpad (Chrome/Edge)": 251,
|
||||
"toggle touchpad": 255,
|
||||
}
|
||||
)
|
4
vendor/modules.txt
vendored
4
vendor/modules.txt
vendored
@ -17,7 +17,7 @@ github.com/go-ole/go-ole/oleutil
|
||||
github.com/lxn/win
|
||||
# github.com/otiai10/gosseract v2.2.0+incompatible
|
||||
github.com/otiai10/gosseract
|
||||
# github.com/robotn/gohook v0.0.0-20181215173318-e36d1aac6c1a
|
||||
# github.com/robotn/gohook v0.0.0-20190220150725-b5ca357c14ff
|
||||
github.com/robotn/gohook
|
||||
# github.com/shirou/gopsutil v2.18.12+incompatible
|
||||
github.com/shirou/gopsutil/process
|
||||
@ -30,7 +30,7 @@ github.com/shirou/gopsutil/net
|
||||
github.com/shirou/w32
|
||||
# github.com/vcaesar/imgo v0.0.0-20181209162409-13af122cf2fa
|
||||
github.com/vcaesar/imgo
|
||||
# golang.org/x/image v0.0.0-20181116024801-cd38e8056d9b
|
||||
# golang.org/x/image v0.0.0-20181116024801-cd38e8056d9b => github.com/golang/image v0.0.0-20181116024801-cd38e8056d9b
|
||||
golang.org/x/image/bmp
|
||||
# golang.org/x/sys v0.0.0-20190109145017-48ac38b7c8cb => github.com/golang/sys v0.0.0-20190109145017-48ac38b7c8cb
|
||||
golang.org/x/sys/unix
|
||||
|
Loading…
Reference in New Issue
Block a user