title: Terminal ignore input while python loop is running
body: <p>So I am creating a program that executes commands based on live user input. To do this I am using pynput (essentially a keylogger) which reads in each keystroke while the program  is active. The problem I am running into is that each keystroke is still being read into the terminal, so once the program ends, the terminal is bombarded with a random string of characters and/or keystrokes. Is there anyway I can get the terminal to ignore these inputs while the program is running?</p>
  <p>Code snippet below.</p>
  <pre><code>def on_press(key):
      global current_command
      try:
          # check to see if command is standard letter key, if it is, convert it to a command
          current_command = commands.Command(key.char)
      except AttributeError:
          # if not a letter command, check if it's a valid keyboard command; if it is, convert to command
          # TODO: finalize valid keys
          valid_keys = {
              &quot;Key.space&quot;: &quot;space&quot;,
              &quot;Key.shift&quot;: &quot;shift&quot;,
              &quot;Key.tab&quot;: &quot;tab&quot;,
              &quot;Key.enter&quot;: &quot;enter&quot;,
              &quot;Key.caps_lock&quot;: &quot;caps&quot;,
              &quot;Key.esc&quot;: &quot;escape&quot;
          }
          valid_command = valid_keys.get(str(key))
          if valid_command is not None:
              current_command = commands.Command(valid_command)
          else:
              # not a recognized command, creating command that will be logged, but ignored
              current_command = commands.Command(str(key))
      # stops listener
      return False
  
  
  def run_rover():
  
      while True:
          # during loop, inputs must be ignored by terminal
          command: commands.Command = input.collect_input()
          print(command)
          output = execute.execute(command)
          if output is not None:
              print(&quot;-&gt;&quot; + output + &quot;&lt;-&quot;)
              if output == &quot;powering off&quot;:
                  exit(0)
  </code></pre>