79625868

Date: 2025-05-16 20:02:02
Score: 1.5
Natty:
Report link

As per @Mr_Pink comment, I just needed to remove the channel receive. The following works:

package main

import (
    "fmt"
    "os"
    "time"

    hook "github.com/robotn/gohook"
)

func main() {
    fmt.Println("Press q to quit.")
    hook.Register(hook.KeyDown, []string{"q"}, func(e hook.Event) {
        os.Exit(3)
    })
    s := hook.Start()
    hook.Process(s)

    // TODO: While listening for key events with gohook above, I also want to continuously print to the console.
    // How do I get this loop to run, while the above event listener is also active?
    for {
        fmt.Print(".")
        time.Sleep(200 * time.Millisecond)
    }
}
Reasons:
  • Blacklisted phrase (1): How do I
  • Long answer (-0.5):
  • Has code block (-0.5):
  • User mentioned (1): @Mr_Pink
  • Self-answer (0.5):
Posted by: Dave Rapin