title: How do I erase a residual character at prompt after exiting python program
body: <p><a href="https://i.stack.imgur.com/DoDf6.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/DoDf6.png" alt="enter image description here"></a>I am writing Python menu programs, and are capturing key strikes (no ) and that's working OK.  The problem is when I exit the program using sys.exit() the last keystrike ends up on the command line.</p>
  
  <p>I'm using the 'keyboard' module which required pip install, but I'm open to suggestion on other ways to capture the key strike.  I've tried using msvcrt.getch(), sys.stdout.flush(), sys.stdin.flush() before exiting, to no avail.  In the code below, the character echoed to the command line is not necessarily upper case, depending on the caps lock.</p>
  
  <p>Thanks in advance.  This has to be a common problem, but I've spent a lot of time searching and so far nothing that works.</p>
  
  <pre><code>import keyboard
  import sys
  
  key = keyboard.read_key() 
  key = key.upper()
  print('Key pressed: '+key)
  
  sys.exit()   # leaves residual character on the command line
  </code></pre>