Why doesn't Python include non-blocking keyboard input function?
BartC
bc at freeuk.com
Wed Oct 26 11:00:12 EDT 2016
On 26/10/2016 13:33, Marko Rauhamaa wrote:
> BartC <bc at freeuk.com>:
>
>> On 26/10/2016 05:44, Marko Rauhamaa wrote:
>> (I've implemented 'keyboards' both on-screen, and on the surface of
>> digitising tablets (also with a hacked Casio calculator pcb when I
>> couldn't afford a real one). With all of those I was mainly interested
>> in key events, not the details.)
>
> Say you want to implement a simple, character-based shooting game where
> the two guns are operated by the [Shift] keys. Unfortunately, the Unix
> terminal API doesn't make that possible. You need to get the keyboard
> events from some other API. In practice, your only choice is X11/Wayland
> (on Linux).
That sort of thing is possible to build by directly calling OS-specific
functions in a similar manner to Steven D'Aprano's way of implementing
getch().
But it's something everyone would have to code themselves.
(I just tried it using my 'getchx' function where it ought to have
worked. Unfortunately MS' interface to key events doesn't seem to
distinguish between left and right shift keys. But it was doable with
left/right ctrl keys.
That's a blocking function it it means having to wait for input. But a
version that just tests for status shouldn't be hard.)
--
Bartc
More information about the Python-list
mailing list