[Tutor] Single char input

Alan Gauld alan.gauld at yahoo.co.uk
Wed Oct 23 17:47:35 EDT 2019



On 23 October 2019, at 22:25, Ed Connell <edwinconnell at gmail.com> wrote:

>Hi,
>How can I accept, evaluate, and act on a single keypress in python?

This is surprisingly difficult because it is operating system dependant. They're is no standard way to do it. As a result most programmers just read the line after the user hits return.

But if you really want to read the keypress you can use the msvcrt library in Windows or the curses like Gary on unlike systems.

I include examples of both in my event driven programming topic in my tutorial.

www.alan-g.me.uk/l2p2

Another approach might be to use ctypes to access the C standard library in your system.

Alan g.



More information about the Tutor mailing list