anyone have any idea how I should do Console.ReadKey() method in Golang? I want it to just return a key as soon as it is pressed, without waiting for Enter.
Asked
Active
Viewed 152 times
0
-
Possibly duplicate question, have you tried this: https://stackoverflow.com/questions/14094190/function-similar-to-getchar – ibrahim-dogan Feb 02 '22 at 17:03
-
1Please read the help section, specifically on how to write a good question: include a clear description of the problem, code to reproduce, and _show us what you've tried_. – Elias Van Ootegem Feb 02 '22 at 17:05
-
This still waits for enter – Clue Feb 02 '22 at 17:19
-
This question, if to be answered as stated, requires an answer the size of 3-4 printed pages. Do you need it cross-platform or are you targetting some specific OS? Answering partially, Go's standard library has no direct support for what you're after. – kostix Feb 02 '22 at 17:33
-
@ibrahim-dogan, close but not 100%: you can have `getchar(3)` in Go by merely calling `Read()` on `os.Stdin` passing it a one-byte slice, but on POSIX systems it won't behave quite like `Console.ReadKey()`. – kostix Feb 02 '22 at 17:35
-
Take a look to golang tcell library. It provides text terminal operations. Example reading a key: https://github.com/gdamore/tcell/blob/master/_demos/hello_world.go#L78 – serge-v Feb 12 '22 at 12:19