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

  • SEARCH
  • Home
  • 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 7721923
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T04:03:24+00:00 2026-06-01T04:03:24+00:00

I need to be able to move the mouse around while I am handling

  • 0

I need to be able to move the mouse around while I am handling keydown events.

How do I do this?

Here is the basic code I am using right now:

import pygame, sys
from pygame.locals import *

pygame.init()

while True:
    for event in pygame.event.get():
        if event.type == QUIT:
            pygame.quit()
            sys.exit()
        if event.type == USEREVENT + 1:
            rotate = True;
        if event.type == KEYDOWN:
            if event.key == K_LEFT or event.key == K_a:
                moveX = -1*moveSpeed
            elif event.key == K_RIGHT or event.key == K_d:
                moveX = moveSpeed
            if event.key == K_DOWN or event.key == K_s:
                moveY = moveSpeed
            elif event.key == K_UP or event.key == K_w:
                moveY = -1*moveSpeed

I can’t move the mouse while the following script is running and I am pressing a key down..

  • 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. Editorial Team
    Editorial Team
    2026-06-01T04:03:25+00:00Added an answer on June 1, 2026 at 4:03 am

    The main problem with your loop is that you have no delay between “frames” – that is that you simply cycle over the event loop at maximum CPU speed – this makes a key press generate lots (lots meaning probably around millions magnitude) of key-down events that are read.

    So:

    1. insert a pygame.time.delay(x) inside your whiel loop, with x
      somewhere between 15 and 100 – this will give you so many
      miliseconds of pause between interations
    2. insert a pygame.event.pump() call inside the loop – this will keep he event
      buffer flowing hapilly and prevent subtle bad behavior across
      different systems
    3. this is not related with your issue – but,
      there is absotely no need of such a thing as “-1*moveSpeed” to
      obtain the negative value of a variable – just use “-moveSpeed”
      instead.

    Also, this should stop the freezing, but pygame can only capture mouse or key events inside its own display window – which you are not initializing – you will have to call pygame.display.set_mode to actually see something.

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

Sidebar

Related Questions

I need change the text color , when mouse move on the images, Here
I need to be able to move a div with my mouse and store
I need to be able to create basic MS Project items (tasks, projects, resources,
I would like to imitate this exact feature on this page. (Move mouse toward
i have a list of images i need to be able to move them
i need a pointer i the right direction. I have been looking around and
Users of the website need to able to store images in their area ,
Need to be able to pull Magento products into an external template. Need to
I need to be able to get at the full URL of the page
I need to be able to get a list of the groups a user

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.