0

I'm currently creating a text-based RPG in Python.

When the game is first launched, it prints a small introduction message letter by letter. The thing is that, while it's printing, the user can still type on the keyboard and insert random letters in the text.

How can I block the keyboard input while the introduction is being printed ?

Here's the letter-by-letter printing function:

def slow_print(txt, duration=1):
    delay = float(duration)/len(txt)

    #Block input    

    for c in txt:
        write(c)
        time.sleep(delay)
    print

    #Unblock input

And the write function:

def write(s):
    sys.stdout.write(s)
    sys.stdout.flush()

Note: I'm on Linux

Lord Baryhobal
  • 132
  • 1
  • 7

1 Answers1

1

I think you're asking about turning off the "echoing" of keyboard to the console. not sure how cross-platform support for control of this, but the standard termios module lets you do this in Posix systems.

there's even an example in the docs doing this

Sam Mason
  • 15,216
  • 1
  • 41
  • 60
  • note that when you need more complicated output you should look at using [`curses`](https://docs.python.org/3/howto/curses.html), which makes this even easier – Sam Mason Nov 09 '19 at 22:39