Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down