robotn / gohook

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

Usinh hook.register doesn't register keyup #31

Open PaulDotSH opened 2 years ago

PaulDotSH commented 2 years ago

Using the code examples, having the following code

    hook.Register(hook.KeyDown, []string{"w"}, func(e hook.Event) {
        fmt.Println("w-")
                run=false
    })

    hook.Register(hook.KeyHold, []string{"space"}, func(e hook.Event) { ww
        run=true
    })

    hook.Register(hook.KeyUp, []string{"space"}, func(e hook.Event) {
        run=false
    })

If you press spacebar once, run is set to true, however on release it is still set to true, and only on pressing w it is set to false

LuSrackhall commented 3 months ago

"There is still a problem, KeyUp cannot be triggered, and it may be triggered incorrectly.

    hook.Register(hook.KeyUp, []string{"w"}, func(e hook.Event) {

        // fmt.Println("hook(KeyUp): ", e)

        ee, _ := json.Marshal(e)
        fmt.Println("hook(KeyUp): ", string(ee))

        fmt.Println("w")
    })

When this code is run, pressing the ‘w’ key does not produce any response. But when q, w, e are pressed quickly in succession, it enters the KeyUp callback for w. However, at this time, the keycode for e is 16 (and this number represents the event corresponding to q)."