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 7691591
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T20:39:38+00:00 2026-05-31T20:39:38+00:00

Is there anyway to use pygame to get input from the console, rather than

  • 0

Is there anyway to use pygame to get input from the console, rather than having to display a separate window to get input? I’m using pygame to track how long the keys on the keyboard are pressed.

The following code doesn’t work (this is just a minimal example, it doesn’t actually keep track of time elapsed):

pygame.init()

while 1:
    for event in pygame.event.get():
        if event.type == pygame.KEYDOWN:
            print event.key, 'pressed'

It doesn’t look like any pygame event is being raised. If I add

screen = pygame.display.set_mode((640, 480))

After

pygame.init()

then the event is raised, but I have that ghastly window I don’t want to deal with.

To explain why I don’t want the window, I envision this application being a command-line utility, so I can’t have that. Is there any functional reason preventing pygame from running on the command-line?

Thanks!

EDIT: I speculated that the problem was pygame.init(), and that I only needed to initialize the key and event modules. According to http://www.pygame.org/docs/tut/ImportInit.html I should have been able to call

pygame.key.init()
pygame.event.init()

but it didn’t work.

  • 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-05-31T20:39:39+00:00Added an answer on May 31, 2026 at 8:39 pm

    Pygame is designed for making (graphical) games, so it only captures key presses when there is a window displayed. As Ignacio said in his answer, reading from the command line and from another window are very different things.

    If you want to create a command line application, try curses:

    http://docs.python.org/library/curses.html

    Unfortunately, it only works on Linux and Mac OS X.

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

Sidebar

Related Questions

Is there anyway I can use this to display an image without having to
Is there anyway to use a bounded wildcard require a class implement more than
Is there anyway to use atrm command to remove queue job from PHP web
Is there anyway to use the built-in DNN Menu module to display a menu
Is there anyway to use the great address book UI with custom data? From
Is there anyway to use the Open Office SDK 2.0 to save a PowerPoint
Is there anyway to use LINQ to obtain the maximum of each columns for
Is there anyway I can use to destroy my deployed application at specific date?.
I was wondering if there was anyway to use functions like ReadFileEx that require
Is there anyway to make it possible to use .net 3.0 namespaces in a

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.