You can use pygame.key.get_pressed to do that.
example:
while running:
keys = pygame.key.get_pressed() #checking pressed keys
if keys[pygame.K_UP]:
y1 -= 1
if keys[pygame.K_DOWN]:
y1 += 1
Related Contents:
- How to detect collisions between two rectangular objects or images in pygame
- Why is nothing drawn in PyGame at all?
- ImportError: No module named ‘pygame’
- Add scrolling to a platformer in pygame
- How do I stop more than 1 bullet firing at once?
- Sometimes the ball doesn’t bounce off the paddle in pong game
- Why is my pygame application loop not working properly? [duplicate]
- How to detect when a rectangular object, image or sprite is clicked
- How do I blit a PNG with some transparency onto a surface in Pygame?
- How to make smooth movement in pygame
- How can i shoot a bullet with space bar?
- How does this algorithm make the character jump in pygame?
- Not letting the character move out of the window [duplicate]
- Making the background move sideways in pygame
- Does PyGame do 3d?
- Pygame is running slow
- jumping too fast?
- How can you rotate the sprite and shoot the bullets towards the mouse position?
- Framerate affect the speed of the game
- pycharm doesn’t recognize pygame package
- How to make a surface with a transparent background in pygame
- is it possible to run pygame or pyglet in a browser?
- Solving “DLL load failed: %1 is not a valid Win32 application.” for Pygame
- Is it possible to change sprite colours in Pygame?
- How can I made a collision mask?
- Pygame how to let balls collide
- rect collision with list of rects
- How to run multiple while loops at a time in Pygame
- Pygame mask collision
- How to draw images and sprites in pygame?
- Pygame button single click [duplicate]
- How to set the pivot point (center of rotation) for pygame.transform.rotate()?
- Scale Everything On Pygame Display Surface
- Pygame, sounds don’t play
- Drag multiple sprites with different “update ()” methods from the same Sprite class in Pygame
- Typewriter Effect Pygame
- Pygame with Multiple Windows
- Pygame Window not Responding after few seconds
- trying creating dropdown menu pygame, but got stuck
- How to display an image after a time interval?
- SVG rendering in a PyGame application. Prior to Pygame 2.0, Pygame did not support SVG. Then how did you load it?
- How to Change the Name of a Pygame window?
- pygame audio playback speed
- pygame.error “couldn’t open image.png” only in command prompt
- How do I focus light or how do I only draw certain circular parts of the window in pygame?
- Is it possible to implement gradual movement of an object to given coordinates in Pygame?
- How to start threads at the same time in Python [duplicate]
- Pygame: Collision by Sides of Sprite
- How to move a sprite according to an angle in Pygame
- Play WAV file in Python