键盘输入实时获取
package main
import (
"fmt"
"os"
"github.com/eiannone/keyboard"
)
func main() {
for {
char, _, err := keyboard.GetSingleKey()
if err != nil {
panic(err)
}
fmt.Printf("You pressed: %q\r\n", char)
if string(char) == "q" {
os.Exit(1)
}
}
}