mirror of
https://github.com/robotn/gohook.git
synced 2025-04-16 20:10:42 +08:00
Compare commits
No commits in common. "master" and "v0.41.0" have entirely different histories.
4
.github/workflows/go.yml
vendored
4
.github/workflows/go.yml
vendored
@ -10,10 +10,10 @@ jobs:
|
||||
runs-on: ${{ matrix.os }}
|
||||
|
||||
steps:
|
||||
- name: Set up Go 1.23.0
|
||||
- name: Set up Go 1.21.0
|
||||
uses: actions/setup-go@v1
|
||||
with:
|
||||
go-version: 1.23.0
|
||||
go-version: 1.21.0
|
||||
id: go
|
||||
|
||||
- name: Check out code into the Go module directory
|
||||
|
@ -45,11 +45,7 @@ func add() {
|
||||
|
||||
fmt.Println("--- Please press w---")
|
||||
hook.Register(hook.KeyDown, []string{"w"}, func(e hook.Event) {
|
||||
fmt.Println("keyDown: ", "w")
|
||||
})
|
||||
|
||||
hook.Register(hook.KeyUp, []string{"w"}, func(e hook.Event) {
|
||||
fmt.Println("keyUp: ", "w")
|
||||
fmt.Println("w")
|
||||
})
|
||||
|
||||
s := hook.Start()
|
||||
|
@ -34,7 +34,7 @@ environment:
|
||||
PATH: C:\msys64\mingw32\bin\;C:\Program Files (x86)\NSIS\;%PATH%
|
||||
# - COMPILER: MINGW_W64
|
||||
# ARCHITECTURE: x64
|
||||
GOVERSION: 1.23.0
|
||||
GOVERSION: 1.21.0
|
||||
# GOPATH: c:\gopath
|
||||
|
||||
# scripts that run after cloning repository
|
||||
|
@ -6,15 +6,6 @@ import (
|
||||
hook "github.com/robotn/gohook"
|
||||
)
|
||||
|
||||
func main() {
|
||||
registerEvent()
|
||||
|
||||
base()
|
||||
|
||||
add()
|
||||
addMouse()
|
||||
}
|
||||
|
||||
func registerEvent() {
|
||||
fmt.Println("--- Please press ctrl + shift + q to stop hook ---")
|
||||
hook.Register(hook.KeyDown, []string{"q", "ctrl", "shift"}, func(e hook.Event) {
|
||||
@ -24,11 +15,7 @@ func registerEvent() {
|
||||
|
||||
fmt.Println("--- Please press w ---")
|
||||
hook.Register(hook.KeyDown, []string{"w"}, func(e hook.Event) {
|
||||
fmt.Println("KeyDown: ", "w-")
|
||||
})
|
||||
|
||||
hook.Register(hook.KeyUp, []string{"w"}, func(e hook.Event) {
|
||||
fmt.Println("KeyUp: ", "w")
|
||||
fmt.Println("w-")
|
||||
})
|
||||
|
||||
s := hook.Start()
|
||||
@ -82,3 +69,12 @@ func base() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
registerEvent()
|
||||
|
||||
base()
|
||||
|
||||
add()
|
||||
addMouse()
|
||||
}
|
||||
|
2
go.mod
2
go.mod
@ -4,5 +4,5 @@ go 1.17
|
||||
|
||||
require (
|
||||
github.com/vcaesar/keycode v0.10.1
|
||||
github.com/vcaesar/tt v0.20.1
|
||||
github.com/vcaesar/tt v0.20.0
|
||||
)
|
||||
|
4
go.sum
4
go.sum
@ -1,4 +1,4 @@
|
||||
github.com/vcaesar/keycode v0.10.1 h1:0DesGmMAPWpYTCYddOFiCMKCDKgNnwiQa2QXindVUHw=
|
||||
github.com/vcaesar/keycode v0.10.1/go.mod h1:JNlY7xbKsh+LAGfY2j4M3znVrGEm5W1R8s/Uv6BJcfQ=
|
||||
github.com/vcaesar/tt v0.20.1 h1:D/jUeeVCNbq3ad8M7hhtB3J9x5RZ6I1n1eZ0BJp7M+4=
|
||||
github.com/vcaesar/tt v0.20.1/go.mod h1:cH2+AwGAJm19Wa6xvEa+0r+sXDJBT0QgNQey6mwqLeU=
|
||||
github.com/vcaesar/tt v0.20.0 h1:9t2Ycb9RNHcP0WgQgIaRKJBB+FrRdejuaL6uWIHuoBA=
|
||||
github.com/vcaesar/tt v0.20.0/go.mod h1:GHPxQYhn+7OgKakRusH7KJ0M5MhywoeLb8Fcffs/Gtg=
|
||||
|
19
hook.go
19
hook.go
@ -92,12 +92,10 @@ var (
|
||||
|
||||
lck sync.RWMutex
|
||||
|
||||
pressed = make(map[uint16]bool, 256)
|
||||
uppressed = make(map[uint16]bool, 256)
|
||||
used = []int{}
|
||||
pressed = make(map[uint16]bool, 256)
|
||||
used = []int{}
|
||||
|
||||
keys = map[int][]uint16{}
|
||||
upkeys = map[int][]uint16{}
|
||||
cbs = map[int]func(Event){}
|
||||
events = map[uint8][]int{}
|
||||
)
|
||||
@ -118,17 +116,12 @@ func Register(when uint8, cmds []string, cb func(Event)) {
|
||||
key := len(used)
|
||||
used = append(used, key)
|
||||
tmp := []uint16{}
|
||||
uptmp := []uint16{}
|
||||
|
||||
for _, v := range cmds {
|
||||
if when == KeyUp {
|
||||
uptmp = append(uptmp, Keycode[v])
|
||||
}
|
||||
tmp = append(tmp, Keycode[v])
|
||||
}
|
||||
|
||||
keys[key] = tmp
|
||||
upkeys[key] = uptmp
|
||||
cbs[key] = cb
|
||||
events[when] = append(events[when], key)
|
||||
// return
|
||||
@ -141,7 +134,6 @@ func Process(evChan <-chan Event) (out chan bool) {
|
||||
for ev := range evChan {
|
||||
if ev.Kind == KeyDown || ev.Kind == KeyHold {
|
||||
pressed[ev.Keycode] = true
|
||||
uppressed[ev.Keycode] = true
|
||||
} else if ev.Kind == KeyUp {
|
||||
pressed[ev.Keycode] = false
|
||||
}
|
||||
@ -153,12 +145,6 @@ func Process(evChan <-chan Event) (out chan bool) {
|
||||
|
||||
if allPressed(pressed, keys[v]...) {
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -267,7 +253,6 @@ func End() {
|
||||
close(ev)
|
||||
|
||||
pressed = make(map[uint16]bool, 256)
|
||||
uppressed = make(map[uint16]bool, 256)
|
||||
used = []int{}
|
||||
|
||||
keys = map[int][]uint16{}
|
||||
|
Loading…
x
Reference in New Issue
Block a user