python 2.7.12 on Linux behaving differently than on Windows

Gregory Ewing greg.ewing at canterbury.ac.nz
Thu Dec 8 08:40:28 EST 2016


BartC wrote:
> Run the code below and start pressing keys. On both of my Linuxes, I get 
> escape sequences shown when I Insert, Delete, Home, End, Page Up, Page 
> Down, Up, Down, Left, Right and most of the function keys; not just 
> single ASCII codes.

That's probably because your terminal window is emulating
some model of glass teletype and sending the same sequence
of characters that a real terminal of that kind would
send in response to those keys. You'll likely get different
sequences depending on what terminal is being emulated.

> How do they work; what magic do they use to get that key information, 
> and why can't it be done outside of a GUI?

It doesn't have to be done in a GUI, but you'd have to
deal with whatever raw keyboard input device the GUIs are
built on. I'm not familiar with the details on Linux.
Look into /dev/input if you're curious.

-- 
Greg


More information about the Python-list mailing list