diff --git a/hook.go b/hook.go index a15e7ac..5e5031b 100644 --- a/hook.go +++ b/hook.go @@ -114,6 +114,19 @@ func allPressed(pressed map[uint16]bool, keys ...uint16) bool { return true } +func keyRegistered(evKeyCode uint16, keys ...uint16) bool { + // Handle empty keys list case (consider all keys registered) + if len(keys) == 0 { + return true + } + for _, k := range keys { + if k == evKeyCode { + return true + } + } + return false +} + // Register register gohook event func Register(when uint8, cmds []string, cb func(Event)) { key := len(used) @@ -151,6 +164,9 @@ func Process(evChan <-chan Event) (out chan bool) { if !asyncon { break } + if !keyRegistered(ev.Keycode, keys[v]...) { + continue + } if allPressed(pressed, keys[v]...) { cbs[v](ev)