mirror of
https://github.com/robotn/gohook.git
synced 2025-04-27 22:49:42 +08:00
oops
This commit is contained in:
parent
47d4c1b2b8
commit
a60a8234bc
113
hook.go
113
hook.go
@ -28,6 +28,9 @@ import (
|
||||
"fmt"
|
||||
"time"
|
||||
"unsafe"
|
||||
|
||||
"github.com/go-vgo/robotgo"
|
||||
hook "github.com/robotn/gohook"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -80,6 +83,106 @@ var (
|
||||
events = map[uint8][]int{}
|
||||
)
|
||||
|
||||
//from robotgo
|
||||
type uMap map[string]uint16
|
||||
|
||||
// MouseMap robotgo hook mouse's code map
|
||||
var MouseMap = uMap{
|
||||
"left": 1,
|
||||
"right": 2,
|
||||
"center": 3,
|
||||
"wheelDown": 4,
|
||||
"wheelUp": 5,
|
||||
"wheelLeft": 6,
|
||||
"wheelRight": 7,
|
||||
}
|
||||
|
||||
// Keycode robotgo hook key's code map
|
||||
var Keycode = uMap{
|
||||
"`": 41,
|
||||
"1": 2,
|
||||
"2": 3,
|
||||
"3": 4,
|
||||
"4": 5,
|
||||
"5": 6,
|
||||
"6": 7,
|
||||
"7": 8,
|
||||
"8": 9,
|
||||
"9": 10,
|
||||
"0": 11,
|
||||
"-": 12,
|
||||
"+": 13,
|
||||
//
|
||||
"q": 16,
|
||||
"w": 17,
|
||||
"e": 18,
|
||||
"r": 19,
|
||||
"t": 20,
|
||||
"y": 21,
|
||||
"u": 22,
|
||||
"i": 23,
|
||||
"o": 24,
|
||||
"p": 25,
|
||||
"[": 26,
|
||||
"]": 27,
|
||||
"\\": 43,
|
||||
//
|
||||
"a": 30,
|
||||
"s": 31,
|
||||
"d": 32,
|
||||
"f": 33,
|
||||
"g": 34,
|
||||
"h": 35,
|
||||
"j": 36,
|
||||
"k": 37,
|
||||
"l": 38,
|
||||
";": 39,
|
||||
"'": 40,
|
||||
//
|
||||
"z": 44,
|
||||
"x": 45,
|
||||
"c": 46,
|
||||
"v": 47,
|
||||
"b": 48,
|
||||
"n": 49,
|
||||
"m": 50,
|
||||
",": 51,
|
||||
".": 52,
|
||||
"/": 53,
|
||||
//
|
||||
"f1": 59,
|
||||
"f2": 60,
|
||||
"f3": 61,
|
||||
"f4": 62,
|
||||
"f5": 63,
|
||||
"f6": 64,
|
||||
"f7": 65,
|
||||
"f8": 66,
|
||||
"f9": 67,
|
||||
"f10": 68,
|
||||
"f11": 69,
|
||||
"f12": 70,
|
||||
// more
|
||||
"esc": 1,
|
||||
"delete": 14,
|
||||
"tab": 15,
|
||||
"ctrl": 29,
|
||||
"control": 29,
|
||||
"alt": 56,
|
||||
"space": 57,
|
||||
"shift": 42,
|
||||
"rshift": 54,
|
||||
"enter": 28,
|
||||
"cmd": 3675,
|
||||
"command": 3675,
|
||||
"rcmd": 3676,
|
||||
"ralt": 3640,
|
||||
"up": 57416,
|
||||
"down": 57424,
|
||||
"left": 57419,
|
||||
"right": 57421,
|
||||
}
|
||||
|
||||
func allPressed(pressed map[uint16]bool, keys ...uint16) bool {
|
||||
|
||||
for _, i := range keys {
|
||||
@ -91,12 +194,12 @@ func allPressed(pressed map[uint16]bool, keys ...uint16) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func Register(when uint8, cmds []string, cb func(hook.Event)) {
|
||||
func Register(when uint8, cmds []string, cb func(Event)) {
|
||||
key := len(used)
|
||||
used = append(used, key)
|
||||
tmp := []uint16{}
|
||||
for _, v := range cmds {
|
||||
tmp = append(tmp, robotgo.Keycode[v])
|
||||
tmp = append(tmp, Keycode[v])
|
||||
}
|
||||
keys[key] = tmp
|
||||
fmt.Println(tmp)
|
||||
@ -105,13 +208,13 @@ func Register(when uint8, cmds []string, cb func(hook.Event)) {
|
||||
return
|
||||
}
|
||||
|
||||
func Process(EvChan <-chan hook.Event) (out chan bool) {
|
||||
func Process(EvChan <-chan Event) (out chan bool) {
|
||||
out = make(chan bool)
|
||||
go func() {
|
||||
for ev := range EvChan {
|
||||
if ev.Kind == hook.KeyDown || ev.Kind == hook.KeyHold {
|
||||
if ev.Kind == KeyDown || ev.Kind == KeyHold {
|
||||
pressed[ev.Keycode] = true
|
||||
} else if ev.Kind == hook.KeyUp {
|
||||
} else if ev.Kind == KeyUp {
|
||||
pressed[ev.Keycode] = false
|
||||
}
|
||||
for _, v := range events[ev.Kind] {
|
||||
|
Loading…
x
Reference in New Issue
Block a user