robotn / gohook

GoHook, Go global keyboard and mouse listener hook
MIT License
324 stars 43 forks source link

KeyUp cannot be triggered #48

Open LuSrackhall opened 5 months ago

LuSrackhall commented 5 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)."

mfkgef commented 5 months ago

Temporary solution:

hook.Register(hook.KeyUp, []string{""}, func(e hook.Event) {
  if hook.RawcodetoKeychar(e.Rawcode) == "w" {
      fmt.Println("w")
  }
})