robotn / gohook

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

How to use gohook to bind right and other buttons? #40

Open ZeronoFreya opened 1 year ago

ZeronoFreya commented 1 year ago
package main

import (
    "fmt"

    hook "github.com/robotn/gohook"
)

func main() {

    // out: alt-q
    hook.Register(hook.KeyDown, []string{"alt", "q"}, func(e hook.Event) {
        fmt.Println("alt-q")
    })

    // out: no output
    hook.Register(hook.KeyDown, []string{"up"}, func(e hook.Event) {
        fmt.Println("up")
    })

    // out: no output
    hook.Register(hook.KeyHold, []string{"left"}, func(e hook.Event) {
        fmt.Println("left")
    })

    // out: no output
    hook.Register(hook.KeyUp, []string{"down"}, func(e hook.Event) {
        fmt.Println("down")
    })

    s := hook.Start()
    <-hook.Process(s)
}

Description

I'm sure there is nothing wrong with the keyboard, the following code prints out the keys normally

hook.Register(hook.KeyUp, []string{}, func(e hook.Event) {
    fmt.Println(e)
})

...