title: How can I read one character from stdin without having to hit enter?
body: <p>I want to run an executable that blocks on stdin and when a key is pressed that same character is printed immediately without <kbd>Enter</kbd> having to be pressed.</p>
  
  <p>How can I read one character from stdin without having to hit <kbd>Enter</kbd>? I started with this example:</p>
  
  <pre><code>fn main() {
      println!("Type something!");
  
      let mut line = String::new();
      let input = std::io::stdin().read_line(&amp;mut line).expect("Failed to read line");
  
      println!("{}", input);
  }
  </code></pre>
  
  <p>I looked through the API and tried replacing <code>read_line()</code> with <code>bytes()</code>, but everything I try requires me to hit <kbd>Enter</kbd> before read occurs.</p>
  
  <p>This question was asked for C/C++, but there seems to be no standard way to do it: <a href="https://stackoverflow.com/questions/421860/capture-characters-from-standard-input-without-waiting-for-enter-to-be-pressed">Capture characters from standard input without waiting for enter to be pressed</a></p>
  
  <p>It might not be doable in Rust considering it's not simple in C/C++.</p>