In Python 3, use input():

input("Press Enter to continue...")

In Python 2, use raw_input():

raw_input("Press Enter to continue...")

This only waits for the user to press enter though.


On Windows/DOS, one might want to use msvcrt. The msvcrt module gives you access to a number of functions in the Microsoft Visual C/C++ Runtime Library (MSVCRT):

import msvcrt as m
def wait():
    m.getch()

This should wait for a key press.


Notes:

In Python 3, raw_input() does not exist.
In Python 2, input(prompt) is equivalent to eval(raw_input(prompt)).

Answer from riza on Stack Overflow
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ make-python-wait-for-a-pressed-key
Make Python Wait For a Pressed Key - GeeksforGeeks
July 23, 2025 - The input function presenting the standard Python distribution could serve the purpose. But the function is only limited to the Enter key, i.e., It requires the Enter key to be pressed for it to return. The following example demonstrates the working: Now the code, upon execution, halts the execution of the program and waits for the Enter keypress...
Discussions

How so I wait for a keystroke?
Contrary to what has been answered so far it is actually super simple to do what you describe. If I have not misunderstood you, you basically want to create some sort of hotkey functionality. Basically execute some code whenever button x is pressed on the keyboard. You can utilize the module keyboard or alternatively pynput for that. Keep in mind that you may need to run the script with admin privileges. Below is a quick example that triggers a function when the spacebar is hit. import keyboard def hotkey_callback(): print("Space was pressed!") keyboard.add_hotkey('space', hotkey_callback) # Stops the program when you hit esc keyboard.wait('esc') More on reddit.com
๐ŸŒ r/learnpython
16
2
September 14, 2023
Jupyter Python Script waiting keyboard input without Enter strike
Dear Friends, My script wants to get the input from the keyboard without the need of hitting the ENTER key. The input() function works for getting the input, but it requires hitting the enter key. I have also tried several libraries for being used in .py scripts, but none of them works in ... More on discourse.jupyter.org
๐ŸŒ discourse.jupyter.org
0
0
June 3, 2022
python - raw_input without pressing enter - Stack Overflow
I'm using raw_input in Python to interact with user in shell. c = raw_input('Press s or n to continue:') if c.upper() == 'S': print 'YES' It works as intended, but the user has to press enter ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
Have program wait for keypress to start (while not in focus in command prompt)?
Time.sleep() might be useful here. If you pend on input, and place it within a while loop, along with time.sleep(), then you can check if any input is provided or sleep the foreground process for a second. More on reddit.com
๐ŸŒ r/learnpython
12
1
November 20, 2021
๐ŸŒ
Pierian Training
pieriantraining.com โ€บ home โ€บ how to wait for a keypress in python
How to Wait for a Keypress in Python - Pierian Training
April 28, 2023 - If you want to wait for a keypress in Python, you can use the `msvcrt` module. This module provides access to a number of functions in the Microsoft Visual C runtime library, including the ability to read a single character from the console. ... In this example, we import the `msvcrt` module and then use its `getch()` function to wait for a keypress. The `getch()` function reads a single character from the console without echoing it to the screen.
๐ŸŒ
Jupyter Community Forum
discourse.jupyter.org โ€บ jupyterlab
Jupyter Python Script waiting keyboard input without Enter strike - JupyterLab - Jupyter Community Forum
June 3, 2022 - Dear Friends, My script wants to get the input from the keyboard without the need of hitting the ENTER key. The input() function works for getting the input, but it requires hitting the enter key. I have also tried seveโ€ฆ
๐ŸŒ
Quora
quora.com โ€บ How-do-you-make-a-command-to-wait-for-the-user-to-press-ENTER-in-Python
How to make a command to wait for the user to press 'ENTER' in Python - Quora
Something went wrong. Wait a moment and try again.Try again ... Development and Programmi... Python (programming langu... ... Use input() (Python 3) or raw_input() (Python 2) to pause until the user presses Enter.
Find elsewhere
๐ŸŒ
Raspberry Pi Forums
forums.raspberrypi.com โ€บ board index โ€บ programming โ€บ python
Reading key presses in Python (without pausing execution) - Raspberry Pi Forums
November 17, 2021 - Hi all, I'm both a Pi and Python ... in Python on the Pi. I'd like to do something like read the state of a key every 1/10th of a second, and do something, otherwise continue executing as normal. ... while True: key = read_state(SPECIFIC KEY) #Return True is key is pressed if key: do something time.sleep(0.1) The important thing is that I don't want my script to stop and wait for user input ...
๐ŸŒ
Linux Hint
linuxhint.com โ€บ python_pause_user_input
Python Pause For User Input โ€“ Linux Hint
A bye message is printed after pressing any key. sleep() method can be used to pause the user input for a certain period of time. In the following script, a simple addition task is given for the user. sleep() method is used here to wait for the user for 5 seconds before typing the answer.
๐ŸŒ
Reddit
reddit.com โ€บ r/learnpython โ€บ have program wait for keypress to start (while not in focus in command prompt)?
r/learnpython on Reddit: Have program wait for keypress to start (while not in focus in command prompt)?
November 20, 2021 -

Hi!

I have a python script that I don't want to start until a key is pressed (ideally a specified key, but if not, any key). I cannot use the Keyboard module because the program will not support multithreading, and the keyboard.wait function requires multithreading to work unfortunately.

None of the solutions I googled have worked so far.

I've tried:

    import os
    os.system("pause")

Also this:

import msvcrt as m
def wait():
    m.getch()

And of course this:

input()

I think part of the issue is I'm running the program in Pycharm, so maybe it doesn't register these? Although I do plan on compiling into an exe so maybe it won't be an issue when the app is distributed, I'd like for some kind of wait key that works in Pycharm so that I can run it during debugging etc. without having to worry about compiling it first.

Can anyone help? I'm at wits end trying to solve what I think should be an easy problem to solve!

๐ŸŒ
Sololearn
sololearn.com โ€บ en โ€บ Discuss โ€บ 2235815 โ€บ how-do-i-read-keyboard-input-without-waiting-for-the-user-to-press-enter
How do I read keyboard input without waiting for the user to press Enter? | Sololearn: Learn to code for FREE!
Actually it is possible, but you'll have to be creative on it. The first option would be to simulate keypress using a library like pyautotui, and set a timer that will press enter key on timeout.
๐ŸŒ
Codemia
codemia.io โ€บ knowledge-hub โ€บ path โ€บ how_do_i_wait_for_a_pressed_key
How do I wait for a pressed key?
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises
๐ŸŒ
W3docs
w3docs.com โ€บ python
How do I wait for a pressed key? - Python
import msvcrt def wait_for_key(): while True: if msvcrt.kbhit(): return msvcrt.getch() print("Press any key to continue...") key = wait_for_key() print("You pressed: ", key)
๐ŸŒ
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

๐ŸŒ
Sopython
sopython.com โ€บ canon โ€บ 63 โ€บ how-do-i-read-keyboard-input-without-waiting-for-the-user-to-press-enter
How do I read keyboard input without waiting for the user to press Enter? - sopython
How do I read keyboard input without waiting for the user to press Enter ยท Made by the cabbage addicts from the Python room on Stack Overflow
๐ŸŒ
Raspberry Pi Forums
forums.raspberrypi.com โ€บ board index โ€บ programming โ€บ python
Detecting Key Press No Window or Wait - Raspberry Pi Forums
Hi. I want to detect a key press, without a window. I also do not want for it to wait until a key is pressed. I need this to be cross platform, and I need to be able to run it without being root. I want this to be able to detect any key.
๐ŸŒ
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...
๐ŸŒ
Sololearn
sololearn.com โ€บ en โ€บ Discuss โ€บ 2462337 โ€บ is-it-possible-to-take-input-without-clicking-on-enter-key-in-python
Is it possible to take input without clicking on ENTER key in python? | Sololearn: Learn to code for FREE!
August 25, 2020 - Jan Markus you don't actually need OOP for this, it can be done using simple functions. ... Kode Krasher I am not sure, some things don't work well on SL. I tried the script on my computer an it worked fine though, I'll share the script. ... This is the one: https://stackoverflow.com/questions/1335507/keyboard-input-with-timeout It's python2, just add parenthesis to print()