Single-module non-blocking Keypress Detection in Python

310 views Asked by At

TL;DR, I'm trying to make a python-only single-module platform-nonspecific non-blocking keypress detector that works in IDLE.

Good luck.

So say I'm running a loop, in IDLE, for an arbitrary amount of time. I want a way to get user input without blocking the loop, on any system I want.

Example:

import keyboard #(is one module in same directory)(Mac, Windows, Linux, who knows?)

teststring = ''

while True:
    if keyboard.isDown('a'):
        teststring += 'a'
    if keyboard.isDown('enter'):
        if 'a' in testring:
            break

    ... (neural network or whatever continues)

To put it a different way, I'm trying to make a universal event listener that works in IDLE. If one already exists, do let me know, but I have done some research and none work in one easy-to-use module.

Note: You don't have to write this, I just want to know what pre-installed Python modules you would use to do this and a general idea of how to go about it.

0

There are 0 answers