mirror of
https://github.com/robotn/gohook.git
synced 2024-11-22 19:46:49 +08:00
Merge c8d0020b0c
into b93f6ca661
This commit is contained in:
commit
733ccf447e
4
go.mod
4
go.mod
@ -1,6 +1,6 @@
|
|||||||
module github.com/robotn/gohook
|
module gohook
|
||||||
|
|
||||||
go 1.17
|
go 1.22
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/vcaesar/keycode v0.10.1
|
github.com/vcaesar/keycode v0.10.1
|
||||||
|
17
hook.go
17
hook.go
@ -93,9 +93,11 @@ var (
|
|||||||
lck sync.RWMutex
|
lck sync.RWMutex
|
||||||
|
|
||||||
pressed = make(map[uint16]bool, 256)
|
pressed = make(map[uint16]bool, 256)
|
||||||
|
uppressed = make(map[uint16]bool, 256)
|
||||||
used = []int{}
|
used = []int{}
|
||||||
|
|
||||||
keys = map[int][]uint16{}
|
keys = map[int][]uint16{}
|
||||||
|
upkeys = map[int][]uint16{}
|
||||||
cbs = map[int]func(Event){}
|
cbs = map[int]func(Event){}
|
||||||
events = map[uint8][]int{}
|
events = map[uint8][]int{}
|
||||||
)
|
)
|
||||||
@ -117,11 +119,17 @@ func Register(when uint8, cmds []string, cb func(Event)) {
|
|||||||
used = append(used, key)
|
used = append(used, key)
|
||||||
tmp := []uint16{}
|
tmp := []uint16{}
|
||||||
|
|
||||||
|
uptmp := []uint16{}
|
||||||
|
|
||||||
for _, v := range cmds {
|
for _, v := range cmds {
|
||||||
|
if when == KeyUp {
|
||||||
|
uptmp = append(uptmp, Keycode[v])
|
||||||
|
}
|
||||||
tmp = append(tmp, Keycode[v])
|
tmp = append(tmp, Keycode[v])
|
||||||
}
|
}
|
||||||
|
|
||||||
keys[key] = tmp
|
keys[key] = tmp
|
||||||
|
upkeys[key] = uptmp
|
||||||
cbs[key] = cb
|
cbs[key] = cb
|
||||||
events[when] = append(events[when], key)
|
events[when] = append(events[when], key)
|
||||||
// return
|
// return
|
||||||
@ -134,6 +142,7 @@ func Process(evChan <-chan Event) (out chan bool) {
|
|||||||
for ev := range evChan {
|
for ev := range evChan {
|
||||||
if ev.Kind == KeyDown || ev.Kind == KeyHold {
|
if ev.Kind == KeyDown || ev.Kind == KeyHold {
|
||||||
pressed[ev.Keycode] = true
|
pressed[ev.Keycode] = true
|
||||||
|
uppressed[ev.Keycode] = true
|
||||||
} else if ev.Kind == KeyUp {
|
} else if ev.Kind == KeyUp {
|
||||||
pressed[ev.Keycode] = false
|
pressed[ev.Keycode] = false
|
||||||
}
|
}
|
||||||
@ -145,6 +154,13 @@ func Process(evChan <-chan Event) (out chan bool) {
|
|||||||
|
|
||||||
if allPressed(pressed, keys[v]...) {
|
if allPressed(pressed, keys[v]...) {
|
||||||
cbs[v](ev)
|
cbs[v](ev)
|
||||||
|
} else if ev.Kind == KeyUp {
|
||||||
|
//uppressed[ev.Keycode] = true
|
||||||
|
if allPressed(uppressed, upkeys[v]...) {
|
||||||
|
uppressed = make(map[uint16]bool, 256)
|
||||||
|
cbs[v](ev)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -253,6 +269,7 @@ func End() {
|
|||||||
close(ev)
|
close(ev)
|
||||||
|
|
||||||
pressed = make(map[uint16]bool, 256)
|
pressed = make(map[uint16]bool, 256)
|
||||||
|
uppressed = make(map[uint16]bool, 256)
|
||||||
used = []int{}
|
used = []int{}
|
||||||
|
|
||||||
keys = map[int][]uint16{}
|
keys = map[int][]uint16{}
|
||||||
|
Loading…
Reference in New Issue
Block a user