Use pygame.KEYDOWN
and pygame.KEYUP
to detect if a key is physically pressed down or released. You can activate keyboard repeat by using pygame.key.set_repeat
to generate multiple pygame.KEYDOWN
events when a key is held down, but that’s rarely a good idea.
Instead, you can use pygame.key.get_pressed()
to check if a key is currently held down:
while True: ... pressed = pygame.key.get_pressed() if pressed[pygame.K_w]: print("w is pressed") if pressed[pygame.K_s]: print("s is pressed")
Related Posts:
- Process finished with exit code -1073741515 (0xC0000135)
- ImportError: No module named ‘pygame’
- ImportError: No module named ‘pygame’
- pygame.error: video system not initialized
- pygame.error: video system not initialized
- How to draw a circle in PyGame?
- pygame.error: video system not initialized
- TypeError: object of type ‘int’ has no len() – Python/Pygame
- Pygame Drawing a Rectangle
- How do I detect collision in pygame?
- How to display text in pygame?
- How to get keyboard input in pygame?
- Countdown timer in Pygame
- pygame clock.tick() vs framerate in game main loop
- Start with pyglet or pygame?
- Pygame mouse clicking detection
- How can I create a text input box with Pygame?
- How do I maximize the display screen in PyGame?
- How to install PyGame on Python 3.4?
- How to clear up screen in pygame?
- Installation of pygame with Anaconda
- How do I rotate an image around its center using Pygame?
- How to handle a Button click event
- How to add a background image into pygame?
- SyntaxError: unexpected EOF while parsing
- Why am I seeing “TypeError: string indices must be integers”?
- TypeError: only integer scalar arrays can be converted to a scalar index with 1D numpy indices array
- How to emulate a do-while loop?
- How to prettyprint a JSON file?
- How to install pip with Python 3?
- pip not recognised as an internal or external command
- Converting list to numpy array
- How do I parse a string to a float or int?
- Check if something is (not) in a list in Python
- How to parse data in JSON format?
- TypeError: unhashable type: ‘dict’
- ‘Conda’ is not recognized as internal or external command
- Python list of dictionaries search
- Extract file name from path, no matter what the os/path format
- Importing requests module does not work
- Converting string into datetime
- How do I read CSV data into a record array in NumPy?
- How to normalize a NumPy array to a unit vector?
- Local variable referenced before assignment?
- Clickable link inside message discord.py
- Is arr.__len__() the preferred way to get the length of an array in Python?
- Running Python from Atom
- TypeError: can’t use a string pattern on a bytes-like object in re.findall()
- inserting characters at the start and end of a string
- Python: SyntaxError: keyword can’t be an expression
- “ImportError: no module named ‘requests'” after installing with pip
- Running Selenium with Headless Chrome Webdriver
- boto3 client NoRegionError: You must specify a region error only sometimes
- Converting Dictionary to List?
- pip3: command not found
- How to use sys.exit() in Python
- How do I get an empty array of any size in python?
- How to deep copy a list?
- How to remove \n from a list element?
- How to add an empty column to a dataframe?
- Virtualenv Command Not Found
- TypeError: ‘float’ object has no attribute ‘__getitem__’,python
- How to apply a function to two columns of Pandas dataframe
- Get Confusion Matrix From a Keras Multiclass Model
- AttributeError: ‘list’ object has no attribute ‘lower’ gensim
- Insert a row to pandas dataframe
- Anaconda Installed but Cannot Launch Navigator
- How to save a Seaborn plot into a file
- How to get the unit vector from a numpy array
- Subtract two columns in dataframe
- Sending string via socket (python)
- pandas DataFrame: replace nan values with average of columns
- How do I print the key-value pairs of a dictionary in python
- How to make a set of lists
- What’s the difference between a Python module and a Python package?
- Truncate to three decimals in Python
- How does ajax work with python?
- RSA encryption and decryption in Python
- pip3 error – ‘_NamespacePath’ object has no attribute ‘sort’
- What does {0} mean in this Python string?
- Tab Error in Python
- Is there a Python equivalent of the C# null-coalescing operator?
- Python 3.6 import requests
- Tensorflow 2.0 – AttributeError: module ‘tensorflow’ has no attribute ‘Session’
- What is key=lambda
- Extract a part of the filepath (a directory) in Python
- Python 3.5.1 urllib has no attribute request
- Rotating a two-dimensional array in Python
- TypeError: sequence item 0: expected string, int found
- What is the meaning of “int(a[::-1])” in Python?
- Pandas unstack problems: ValueError: Index contains duplicate entries, cannot reshape
- How do I read image data from a URL in Python?
- Python: Convert timedelta to int in a dataframe
- Can’t concat bytes to str
- cmake error ‘the source does not appear to contain CMakeLists.txt’
- Invalid syntax when using “print”?
- Error loading MySQLdb module: No module named ‘MySQLdb’
- Unable to install boto3
- Python MySQLdb not importing
- Write a program that asks the user to enter five test scores. Correspond it to a letter grade