From f049036b8c4f0ff4f3aa81f179d33b8ea8d69329 Mon Sep 17 00:00:00 2001 From: vcaesar Date: Sat, 8 Feb 2025 15:44:55 -0800 Subject: [PATCH] Update: update examples and README.md --- README.md | 6 +++++- examples/main.go | 24 ++++++++++++++---------- hook.go | 2 -- 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 350b281..36c9cf8 100644 --- a/README.md +++ b/README.md @@ -45,7 +45,11 @@ func add() { fmt.Println("--- Please press w---") hook.Register(hook.KeyDown, []string{"w"}, func(e hook.Event) { - fmt.Println("w") + fmt.Println("keyDown: ", "w") + }) + + hook.Register(hook.KeyUp, []string{"w"}, func(e hook.Event) { + fmt.Println("keyUp: ", "w") }) s := hook.Start() diff --git a/examples/main.go b/examples/main.go index 2a1ab8b..3245e9f 100644 --- a/examples/main.go +++ b/examples/main.go @@ -6,6 +6,15 @@ 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) { @@ -15,7 +24,11 @@ func registerEvent() { fmt.Println("--- Please press w ---") hook.Register(hook.KeyDown, []string{"w"}, func(e hook.Event) { - fmt.Println("w-") + fmt.Println("KeyDown: ", "w-") + }) + + hook.Register(hook.KeyUp, []string{"w"}, func(e hook.Event) { + fmt.Println("KeyUp: ", "w") }) s := hook.Start() @@ -69,12 +82,3 @@ func base() { } } } - -func main() { - registerEvent() - - base() - - add() - addMouse() -} diff --git a/hook.go b/hook.go index fc625ec..f30e1f2 100644 --- a/hook.go +++ b/hook.go @@ -118,7 +118,6 @@ func Register(when uint8, cmds []string, cb func(Event)) { key := len(used) used = append(used, key) tmp := []uint16{} - uptmp := []uint16{} for _, v := range cmds { @@ -160,7 +159,6 @@ func Process(evChan <-chan Event) (out chan bool) { uppressed = make(map[uint16]bool, 256) cbs[v](ev) } - } } }