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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:13:35+00:00 2026-06-17T09:13:35+00:00

I am making a pygame program where I have a string and whatever the

  • 0

I am making a pygame program where I have a string and whatever the user types it displays it in the pygame window. Here is the code:

    if (event.type==pygame.KEYDOWN):
                    if (event.key==pygame.K_BACKSPACE):
                            if (len(sin)>0):
                                    sin=""
                    elif (event.key==pygame.K_RETURN):
                            if (len(sin)==11):
                                    #sin.replace("-","")
                                    running=2
                                    screen.fill(white)
                            else:
                                    body=True

                    else:
                            sin=sin+chr(event.key)
    text=font.render(sin,True,(black),white) 

One problem is that it does not recognize special characters like (“:”,”;”,shift characters etc.) Is there a better way to code something like this?

  • 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-17T09:13:36+00:00Added an answer on June 17, 2026 at 9:13 am

    Use event.unicode to get what you are looking for.

    … The pygame.KEYDOWN event has an additional attributes unicode, and
    scancode. unicode represents a single character string that is the
    fully translated character entered. …


    To answer your comment you just check event.unicode instead of event.key:

    ...
    if (event.type==pygame.KEYDOWN):
        if (event.unicode==pygame.K_COLON): #to match a colon
            pass
        elif (event.unicode== (pygame.K_Z | pygame.KMOD_SHIFT)): #to explicitly match a capital Z instead of just a z
           pass
    ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm making a program with the Pygame that changes the overall colours of inserted
I'm making a Snake type game using Pygame. Everything's pretty much working, but below
Making a simple program which will generate a multiple choice form. I have an
I'm making a drawing program with python and pygame. I am trying to incorporate
I am making a drawing program in python with pygame right now. The interface
Making a server in java, First off, Here's the code. AnsiConsole.out.println(This is a Test.);
I'm currently making a game with Python using the PyGame module. I have two
I am making a simple multiplayer economic game in pygame. It consists of turns
Making a word document of our network set-up. We have about 7 servers and
Making a simple application, so when the user logs out of Windows, it of

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.