Skip to content

Idea for multiple keys pressed #22

Description

@borisreyesgrange

Hi, I'm using your pygamge_function with my High School Computer Science students in Chile, and I want to share with you this idea... I take your keyPressed function and add a simple modification to add multiple keys detecting (for jumping with direction for example, or move in diagonal):

KeyCheck must be a list with the keys to check

def keysPressed(keyCheck):
global keydict
pygame.event.clear()
keys = pygame.key.get_pressed()
pressedKeys = 0
if sum(keys) > 0:
for key in keyCheck:
if key == "" or keys[keydict[key.lower()]]:
pressedKeys += 1
if pressedKeys == len(keyCheck):
return True
return False

When we use this, in the game loop, we must check the multiple keys pressed actions first, before of the single keystroke in the "if" that controls the movement.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions