0

It can be done with termios under Unix, but not under Windows.

I do it easily in perl with TERM::Readkey, or in Windows Batch files.

If an answer has been given here, I have been unable to find it.

I find it hard to believe that python omits such a basic operation available in essentially all other languages.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
user1067305
  • 3,233
  • 7
  • 24
  • 29

1 Answers1

0

The answer above returns a byte, not a character, so it needs to be decoded.

Here is a solution that returns a single character without having to hit Enter. It works in python 3.4, on Windows

def getChar():
    import msvcrt 
    return msvcrt.getch().decode('utf-8')
user1067305
  • 3,233
  • 7
  • 24
  • 29