Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 132419
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T06:15:35+00:00 2026-05-11T06:15:35+00:00

I am developing a simple game in PyGame … A rocket ship flying around

  • 0

I am developing a simple game in PyGame… A rocket ship flying around and shooting stuff.


Question: Why does pygame stop emitting keyboard events when too may keys are pressed at once?

About the Key Handling: The program has a number of variables like KEYSTATE_FIRE, KEYSTATE_TURNLEFT, etc…

  1. When a KEYDOWN event is handled, it sets the corresponding KEYSTATE_* variable to True.
  2. When a KEYUP event is handled, it sets the same variable to False.

The problem: If UP-ARROW and LEFT-ARROW are being pressed at the same time, pygame DOES NOT emit a KEYDOWN event when SPACE is pressed. This behavior varies depending on the keys. When pressing letters, it seems that I can hold about 5 of them before pygame stops emitting KEYDOWN events for additional keys.

Verification: In my main loop, I simply printed each event received to verify the above behavior.

The code: For reference, here is the (crude) way of handling key events at this point:

while GAME_RUNNING:     FRAME_NUMBER += 1     CLOCK.tick(FRAME_PER_SECOND)      #----------------------------------------------------------------------     # Check for events     for event in pygame.event.get():         print event          if event.type == pygame.QUIT:             raise SystemExit()          elif event.type == pygame.KEYDOWN and event.dict['key'] == pygame.K_UP:             KEYSTATE_FORWARD = True         elif event.type == pygame.KEYUP and event.dict['key'] == pygame.K_UP:             KEYSTATE_FORWARD = False          elif event.type == pygame.KEYDOWN and event.dict['key'] == pygame.K_DOWN:             KEYSTATE_BACKWARD = True         elif event.type == pygame.KEYUP and event.dict['key'] == pygame.K_DOWN:             KEYSTATE_BACKWARD = False          elif event.type == pygame.KEYDOWN and event.dict['key'] == pygame.K_LEFT:             KEYSTATE_TURNLEFT = True         elif event.type == pygame.KEYUP and event.dict['key'] == pygame.K_LEFT:             KEYSTATE_TURNLEFT = False          elif event.type == pygame.KEYDOWN and event.dict['key'] == pygame.K_RIGHT:             KEYSTATE_TURNRIGHT = True         elif event.type == pygame.KEYUP and event.dict['key'] == pygame.K_RIGHT:             KEYSTATE_TURNRIGHT = False          elif event.type == pygame.KEYDOWN and event.dict['key'] == pygame.K_SPACE:             KEYSTATE_FIRE = True         elif event.type == pygame.KEYUP and event.dict['key'] == pygame.K_SPACE:             KEYSTATE_FIRE = False      # remainder of game loop here... 

For pressing this sequence:

  • a (down)
  • s (down)
  • d (down)
  • f (down)
  • g (down)
  • h (down)
  • j (down)
  • k (down)
  • a (up)
  • s (up)
  • d (up)
  • f (up)
  • g (up)
  • h (up)
  • j (up)
  • k (up)

Here is the output:

  • <Event(2-KeyDown {'scancode': 30, 'key': 97, 'unicode': u'a', 'mod': 0})>
  • <Event(2-KeyDown {'scancode': 31, 'key': 115, 'unicode': u's', 'mod': 0})>
  • <Event(2-KeyDown {'scancode': 32, 'key': 100, 'unicode': u'd', 'mod': 0})>
  • <Event(2-KeyDown {'scancode': 33, 'key': 102, 'unicode': u'f', 'mod': 0})>
  • <Event(3-KeyUp {'scancode': 30, 'key': 97, 'mod': 0})>
  • <Event(3-KeyUp {'scancode': 31, 'key': 115, 'mod': 0})>
  • <Event(3-KeyUp {'scancode': 32, 'key': 100, 'mod': 0})>
  • <Event(3-KeyUp {'scancode': 33, 'key': 102, 'mod': 0})>
  • <Event(2-KeyDown {'scancode': 36, 'key': 106, 'unicode': u'j', 'mod': 0})>
  • <Event(2-KeyDown {'scancode': 37, 'key': 107, 'unicode': u'k', 'mod': 0})>
  • <Event(3-KeyUp {'scancode': 36, 'key': 106, 'mod': 0})>
  • <Event(3-KeyUp {'scancode': 37, 'key': 107, 'mod': 0})>

Is this a common issue? Is there a workaround? If not, what is the best way to handle multiple-key control issues when using pygame?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T06:15:35+00:00Added an answer on May 11, 2026 at 6:15 am

    This sounds like a input problem, not a code problem – are you sure the problem isn’t the keyboard itself? Most keyboards have limitations on the number of keys that can be pressed at the same time. Often times you can’t press more than a few keys that are close together at a time.

    To test it out, just start pressing and holding letters on the keyboard and see when new letters stop appearing.

    My suggestion is to try mapping SPACE to a different key somewhere else and see what happens.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 72k
  • Answers 72k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer Found it. You guys were in essence correct on the… May 11, 2026 at 1:41 pm
  • added an answer I'm not sure about pasting multiple lines to command mode,… May 11, 2026 at 1:41 pm
  • added an answer You could set the OnClientClick property's value server-side like this:… May 11, 2026 at 1:41 pm

Related Questions

No related questions found

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.