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
  • 7,766
  • 8
  • 46
  • 61
user1067305
  • 2,949
  • 6
  • 23
  • 28

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
  • 2,949
  • 6
  • 23
  • 28