add hook go support

This commit is contained in:
vcaesar 2018-09-16 19:29:13 -04:00
parent 5d0c662549
commit b0df75125b
3 changed files with 49 additions and 15 deletions

34
hook.go
View File

@ -0,0 +1,34 @@
package hook
/*
#cgo darwin CFLAGS: -x objective-c -Wno-deprecated-declarations
#cgo darwin LDFLAGS: -framework Cocoa
#cgo linux CFLAGS:-I/usr/src
#cgo linux LDFLAGS: -lX11-xcb -lxcb -lxcb-xkb -lxkbcommon -lxkbcommon-x11 -lm
#cgo windows LDFLAGS: -lgdi32 -luser32
#include "event/goEvent.h"
// #include "event/hook_async.h"
*/
import "C"
import(
// "fmt"
"unsafe"
)
// AddEvent add event listener
func AddEvent(key string) int {
cs := C.CString(key)
eve := C.add_event(cs)
geve := int(eve)
defer C.free(unsafe.Pointer(cs))
return geve
}
// StopEvent stop event listener
func StopEvent() {
C.stop_event()
}

View File

@ -12,9 +12,9 @@
#ifndef USE_IOKIT #ifndef USE_IOKIT
// Some of the system key codes that are needed from IOKit. // Some of the system key codes that are needed from IOKit.
// #define NX_KEYTYPE_SOUND_UP 0x00 #define NX_KEYTYPE_SOUND_UP 0x00
// #define NX_KEYTYPE_SOUND_DOWN 0x01 #define NX_KEYTYPE_SOUND_DOWN 0x01
// #define NX_KEYTYPE_MUTE 0x07 #define NX_KEYTYPE_MUTE 0x07
/* Display controls... /* Display controls...
#define NX_KEYTYPE_BRIGHTNESS_UP 0x02 #define NX_KEYTYPE_BRIGHTNESS_UP 0x02
@ -26,18 +26,18 @@
#define NX_KEYTYPE_ILLUMINATION_TOGGLE 0x17 #define NX_KEYTYPE_ILLUMINATION_TOGGLE 0x17
*/ */
// #define NX_KEYTYPE_CAPS_LOCK 0x04 #define NX_KEYTYPE_CAPS_LOCK 0x04
//#define NX_KEYTYPE_HELP 0x05 //#define NX_KEYTYPE_HELP 0x05
// #define NX_POWER_KEY 0x06 #define NX_POWER_KEY 0x06
// #define NX_KEYTYPE_EJECT 0x0E #define NX_KEYTYPE_EJECT 0x0E
// #define NX_KEYTYPE_PLAY 0x10 #define NX_KEYTYPE_PLAY 0x10
// #define NX_KEYTYPE_NEXT 0x12 #define NX_KEYTYPE_NEXT 0x12
// #define NX_KEYTYPE_PREVIOUS 0x13 #define NX_KEYTYPE_PREVIOUS 0x13
/* There is no official fast-forward or rewind scan code support.*/ /* There is no official fast-forward or rewind scan code support.*/
// #define NX_KEYTYPE_FAST 0x14 #define NX_KEYTYPE_FAST 0x14
// #define NX_KEYTYPE_REWIND 0x15 #define NX_KEYTYPE_REWIND 0x15
#endif #endif

View File

@ -3,11 +3,11 @@ package main
import ( import (
"fmt" "fmt"
"go-vgo/robotn/gohook" "github.com/robotn/gohook"
) )
func main() { func main() {
hook.AsyncHook() // hook.AsyncHook()
veve := hook.AddEvent("v") veve := hook.AddEvent("v")
if veve == 0 { if veve == 0 {
fmt.Println("v...") fmt.Println("v...")