There are at least two ways to approach this.

The first is to check whether your "standard input" stream has some data, without blocking to actually wait till there is some. The answers referenced in comments tell you how to approach this. However, while this is attractive in terms of simplicity (compared to the alternatives), there is no way to transparently do this portably between Windows and Linux.

The second way is to use a thread to block and wait for the user input:

import threading 
import time

no_input = True

def add_up_time():
    print "adding up time..."
    timeTaken=float(0)
    while no_input:
        time.sleep(0.01)
        timeTaken=timeTaken+0.01
    print(timeTaken)


# designed to be called as a thread
def signal_user_input():
    global no_input
    i = raw_input("hit enter to stop things")   # I have python 2.7, not 3.x
    no_input = False
    # thread exits here


# we're just going to wait for user input while adding up time once...
threading.Thread(target = signal_user_input).start()

add_up_time()

print("done.... we could set no_input back to True and loop back to the previous comment...")

As you can see, there's a bit of a dilemma about how to communicate from the thread to the main loop that the input has been received. Global variable to signal it... yucko eh?

Answer from GreenAsJade on Stack Overflow
🌐
Reddit
reddit.com › r/learnpython › * h e l p* python not waiting for user to input
r/learnpython on Reddit: * H E L P* python not waiting for user to input
July 6, 2024 -

i have an assignment due tomorrow please help

base_gene = input("""what is the base gene list:
""")
name4Genelist1 = input("\nplease enter a name for the gene list: \n\n")
base_gene_list = list(base_gene.split(","))

compare_gene = input("""what is the gene list you want to compare? :
""")
name4Genelist2 = input("please enter a name for the gene list: ")
compare_gene_list = list(compare_gene.split(","))


# print(base_gene_list)
# print(compare_gene_list)
print(compare_gene_list)
print(base_gene_list)
result = []
for element in compare_gene_list:
    if element not in base_gene_list:
        result.append(element)

result2 = []
for element in base_gene_list:
    if element not in compare_gene_list:
        result2.append(element)

OutPut = ','.join(result)
OutPut2 = ','.join(result2)
print("here is the stuff the was in "+ name4Genelist1 +" gene list and wasnt in " + name4Genelist2 + """:
"""+OutPut)
print("")
print("and here is the stuff the was in "+ name4Genelist2 +" gene list and wasn't in " + name4Genelist1 + """:
"""+OutPut2)
🌐
Reddit
reddit.com › r/learnpython › how to get input from users without pausing the code?
r/learnpython on Reddit: how to get input from users without pausing the code?
November 10, 2021 -

when you use the "input" function it prompts the user and waits for them to press enter;

Is there an easy way to listen for the user's keypresses in the background and then call a function when they press enter but I don't want to record them while they are not on the python terminal?

before I use the python pynput keyboard listener but that records keypresses even when you are not on the python window terminal.

🌐
Python.org
discuss.python.org › python help
Inputimeout doesn't wait for user input and immediately sends timeout message - Python Help - Discussions on Python.org
February 6, 2024 - def sneakyMinigame(): global alert objective = None for i in range(15): objective = random.choice(string.ascii_letters) try: time_over = inputimeout(prompt = "Type "+objective+": ", timeout=2) except Exception: time_over="You trip and fall" print(time_over) alert = alert + 1 break if response == objective: continue else: print("You made a noise!
🌐
Quora
quora.com › How-can-I-give-input-without-pressing-enter-key-in-Python
How to give input without pressing enter key in Python - Quora
Answer (1 of 2): Whenever we take input to any program we needed to press enter , whether we are talking about any of the languages but they provide us any such type of command that helps us to take input without pressing enter key. for eg: in c we can use getch() , and in Python also we can us...
Find elsewhere
🌐
CodeRivers
coderivers.org › blog › get-input-without-enter-python
Getting Input Without Enter in Python - CodeRivers
March 18, 2025 - The msvcrt module in Python provides functions that interact with the Microsoft Visual C Runtime Library. The getch() function within this module can be used to read a single character from the console without waiting for the Enter key to be pressed. This is possible because it directly accesses ...
🌐
Replit
replit.com › talk › ask › Python-How-do-I-input-without-pressing-enter › 33815
[Python] How do I input without pressing enter
This way, you can share your code without giving other users access to your personal data or linked accounts. ... Web pages written in HTML, CSS, and JavaScript can be deployed on Replit. HTML/CSS/JS repls are given a unique URL that can be shared with your friends, family, peers, and clients. ... Replit will install most available Python ...
🌐
Reddit
reddit.com › r/learnpython › how to detect keypress in python? without wait the user to press any key
r/learnpython on Reddit: How to detect keypress in Python? Without wait the user to press any key
May 23, 2020 -

I need to detect if any key is pressed but i cannot wait until the user press anything

Like he only gonna press any key if he wants to stop the program,so the program need to continue while he dont press nothing

Ps:sorry my bad english

from datetime import datetime
import os
from msvcrt import getch
from time import sleep

def get_down(time):
    print('press ENTER to cancel \n')
    while True:
        key = ord(getch())    #the program stop wanting the user to press a key
        if key == 13:
            print('You cancel the operation')
            break

        if time == hours:
            print("The system is gonna turn off")
            sleep(5)
            os.system("shutdown /s /t 1")


hours = datetime.now().strftime('%H:%M')
print('Now is: {}'.format(hours))
get_down(str(input('When you want to shutdown? (hh:mm):')))
🌐
GitHub
gist.github.com › r0dn0r › d75b22a45f064b24e42585c4cc3a30a0
Python: wait for input(), else continue after x seconds · GitHub
All this does is wait for a line to be entered, then return that line. If no line is entered, it won't try to read the input.
🌐
Reddit
reddit.com › r/learnpython › python input function without pressing enter?
r/learnpython on Reddit: Python input function without pressing enter?
December 19, 2020 -

Howdy,

Do you know if there is a way to accept user's input without pressing enter?

I am trying to exit a while loop by pressing the key "q" but with the input() function I have to press enter.

I would like to use standard Python modules (if possible) and not install anything else with pip.

Thank you!

Edit: I'm using Python3.8 on Unix

🌐
Cemetech
cemetech.net › forum › viewtopic.php
TI 84 CE Python circuit python input without waiting for key - Cemetech | Forum | Calculator Programming [Topic]
November 16, 2021 - As far I know, TI's Python intentionally lacks non-blocking input precisely because it could be used to make games.
🌐
DigitalOcean
digitalocean.com › community › tutorials › python-wait-time-wait-for-input
Python wait time, wait for user input | DigitalOcean
August 3, 2022 - Below short screen capture shows the complete program execution. Surprising, there is no easy way to wait for user input with a timeout or default value when empty user input is provided. I hope these useful features come in future Python releases.
🌐
Narkive
comp.lang.python.narkive.com › VSXfhUn3 › how-can-i-handle-the-char-immediately-after-its-input-without-waiting-an-endline
How can I handle the char immediately after its input, without waiting an endline?
This call will block if a keypress is not already available, but will not wait for Enter to be pressed. If the pressed key was a special function key, this will return '\000' or '\xe0'; the next call will return the keycode. The Control-C keypress cannot be read with this function.