I'm trying to write a function in python that restricts when a user can add inputs to the terminal for replit testing and for windows use. Ex. during delays, i don't want the user to be able to type anything, but they still can and it messes with my program. I can't seem to be doing it right.

def new_input(str):
device = "replit"
if device == "windows":
import msvcrt
char = msvcrt.getch()
if char not in ["\n", "\r", ""]:
msvcrt.putch('\r\n')
elif device == "replit":
import sys, os, termios
fd = sys.stdin.fileno()
oldterm = termios.tcgetattr(fd)
newattr = termios.tcgetattr(fd)
newattr[3] = newattr[3] & ~termios.ICANON & ~termios.ECHO
termios.tcsetattr(fd, termios.TCSANOW, newattr)
os.read(fd, 1024)
termios.tcsetattr(fd, termios.TCSAFLUSH, oldterm)
input(str).lower()