Return normal terminal input when using tty, sys, terminos

Question:

I’m working on a little project which requiers input without "pausing" for each time.
Without completely understanding how it works, I used some code that I found online.

import tty, sys, termios

while True:
    filedescriptors = termios.tcgetattr(sys.stdin)
    tty.setcbreak(sys.stdin)
    dir_inp = 0
    while 1:
        dir_inp = sys.stdin.read(1)[0]
        if dir_inp != "q":

That is all the necessary code to allow for free input without pausing for confirmation or anything. At some point in the program I want the user to input a name, and the normal input() command no longer works…

Seeing as I’m unable to figure out how the code for this free input works, I’m also unable to figure out how to stop it…

(Usually I try my best to understand what I’m implementing in my code, but this is particularly tricky)

input() works just fine before the code shown above is run, but won’t work once it’s in action.

Answers:

I just changed to PyInp, much easier

Categories: questions Tags: , , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.