robotn / gohook

GoHook, Go global keyboard and mouse listener hook
MIT License
314 stars 44 forks source link

Multiple events occur in single input #47

Open thewh1teagle opened 5 months ago

thewh1teagle commented 5 months ago

I use gohook in the project github.com/shortcut and publish it to macOS / Linux / Windows.

In macOS if I push some key and hold it will send multiple keyDown events altought I clicked only once and holding. in Windows if I push some key without holding it send multiple keyDown events, if I hold then also same as macOS - multiple events are sent for simple hit on keys.

main.go#L181


func registerShortcuts(shortcuts []Shortcut) {
    for _, shortcut := range shortcuts {
        fmt.Printf("Register shortcut %v\n", shortcut)
        hook.Register(hook.KeyDown, shortcut.Keys, func(e hook.Event) {
            fmt.Printf("Shortcut <%s> activated\n", shortcut.Name)
            command := strings.Split(shortcut.Command, " ")
            cmd := exec.Command(command[0], command[1:]...)

            if err := cmd.Start(); err != nil {
                fmt.Printf("Error executing command for shortcut <%s>: %v\n", shortcut.Name, err)
            }
        })
    }
}