title: How to catch keypress without enter in Golang loop
body: <p>I've got a loop in which some things happen according to the state it runs in (manual/automatic/learning). I now want to be able to let the program switch between these states by pressing the accompanying letters on the keyboard ("m" for manual, "a" for automatic and "l" for learning).</p>
  
  <p>So to do this I need to be able to catch a keypress during the loop and change the variable status accordingly. I now have the following, which can catch a keypress followed by an enter:</p>
  
  <pre><code>ch := make(chan string)
  go func(ch chan string) {
      reader := bufio.NewReader(os.Stdin)
      for {
          s, _ := reader.ReadString('\n')
          ch &lt;- s
      }
  }(ch)
  
  for {
      select {
          case stdin, _ := &lt;-ch:
              fmt.Println("Keys pressed:", stdin)
          default:
              fmt.Println("Working..")
      }
      time.Sleep(time.Second)
  }
  </code></pre>
  
  <p>But the fact that I need to hit the enter button is not acceptable.</p>
  
  <p>Does anybody know a non-blocking way to catch a keypress of a normal letter (not a SIGINT) without the need to hit enter afterwards?</p>