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

asked Nov 9, 2019 at 22:04

1 Answer 1

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

answered Nov 9, 2019 at 22:30
Sign up to request clarification or add additional context in comments.

1 Comment

note that when you need more complicated output you should look at using curses, which makes this even easier

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.