How to wait for 20 secs for user to press any key?
Question: How can I wait for user to press any key for 20 secs? I.e. I show the message
and it counts 20 secs, the code continues execution either if 20 secs are
passed OR if user pressed any key. How can I do it with python?


Answer: If you're on Windows:

    
    
    def wait_for_user(secs):
        import msvcrt
        import time
        start = time.time()
        while True:
            if msvcrt.kbhit():
                msvcrt.getch()
                break
            if time.time() - start > secs:
                break
    

