On Fri, Apr 15, 2022 at 6:35 AM Daniel Jankins <djank...@gmail.com> wrote:

> I have a newbie question.  I want to loop until a char is available
> (keypress).
> Could someone point me to an example.
>

I can't point you to an example because that wouldn't be idiomatic Go; thus
such examples are (I hope) hard to find. In Go you shouldn't busy wait
using a function like "kbhit
<https://www.geeksforgeeks.org/kbhit-c-language/>" . You should create a
channel for communicating the keys that are seen, create a goroutine that
reads from os.Stdin and injects keys into that channel, then use an event
loop in a different goroutine that uses "select
<https://go.dev/ref/spec#Select_statements>" to read key events from that
channel.

-- 
Kurtis Rader
Caretaker of the exceptional canines Junior and Hank

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CABx2%3DD8-Cf3gP-qw7rdA9%3Dfgx9LVJ3fvyuU5SN7jt19MgZj4Sw%40mail.gmail.com.

Reply via email to