mirror of
https://github.com/robotn/gohook.git
synced 2024-11-24 13:26:54 +08:00
add hook go support
This commit is contained in:
parent
5d0c662549
commit
b0df75125b
34
hook.go
34
hook.go
@ -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()
|
||||||
|
}
|
@ -5,16 +5,16 @@
|
|||||||
#include <ApplicationServices/ApplicationServices.h>
|
#include <ApplicationServices/ApplicationServices.h>
|
||||||
#include <Carbon/Carbon.h> // For HIToolbox kVK_ keycodes and TIS funcitons.
|
#include <Carbon/Carbon.h> // For HIToolbox kVK_ keycodes and TIS funcitons.
|
||||||
#ifdef USE_IOKIT
|
#ifdef USE_IOKIT
|
||||||
#include <IOKit/hidsystem/ev_keymap.h>
|
#include <IOKit/hidsystem/ev_keymap.h>
|
||||||
#endif
|
#endif
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
|
||||||
#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
|
||||||
|
|
||||||
|
@ -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...")
|
||||||
|
Loading…
Reference in New Issue
Block a user