robotn / gohook

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

During a test where multiple keys are pressed and held down simultaneously, only the last key pressed continually triggers the hold event.Even under the above conditions, only up to 6 keys can be pressed simultaneously. #49

Closed LuSrackhall closed 3 months ago

LuSrackhall commented 3 months ago

During a test where multiple keys are pressed and held down simultaneously, only the last key pressed continually triggers the hold event. Intuitively, if I am holding down multiple keys, each should be able to continually trigger its corresponding hold event.

Even under the above conditions, only up to 6 keys can be pressed simultaneously. (When I am holding down 6 keys and start pressing a 7th key or more, no further keyboard events can be detected.)

I am not sure if these two issues are due to my personal device setup:

package main

import (
    hook "github.com/robotn/gohook"
)

func main() {
    keyEventListen()
}

func keyEventListen() {
    evChan := hook.Start()
    defer hook.End()

    keycode_keycodeChan_map := make(map[uint16]chan hook.Event)

    for ev := range evChan {
        if ev.Kind == 4 || ev.Kind == 5 {
            if _, exists := keycode_keycodeChan_map[ev.Keycode]; exists {
                keycode_keycodeChan_map[ev.Keycode] <- ev
            } else {
                keycode_keycodeChan_map[ev.Keycode] = make(chan hook.Event)
                go handleKeyEvent(keycode_keycodeChan_map[ev.Keycode])
                keycode_keycodeChan_map[ev.Keycode] <- ev

            }
        }
    }
}

func handleKeyEvent(evChan chan hook.Event) {

    var key_down_soundIsRun bool = false

    for ev := range evChan {
        if ev.Kind == 4 {
            println("hold")
            println(ev.Keycode) 
            if !key_down_soundIsRun {
                println("仅播放 key_down 声音")
                key_down_soundIsRun = true
            }
        }

        if ev.Kind == 5 {
            println("up")
            println(ev.Keycode)
            println("仅播放 key_up 声音")
            key_down_soundIsRun = false
        }
    }
}

Description

...

LuSrackhall commented 3 months ago

Hardware Limitations