Comments (7)
Hi, this is pretty interesting. I've never heard of an issue like this, and I've answered quite a few questions about Pygame over the years.
- Can your share your code for the project? You can either push your project to a repository on GitHub, or feel free to send me a zip file of your project. I'm username at gmail.
- What OS are you using? What version of Python do you have installed? How did you install it? What version of Pygame do you have, and how did you install it?
- What physical computer are you using? What keyboard are you using? How is the keyboard connected?
from pcc_3e.
I have pushed the code to GitHub.
My programming environment is as follows:
● OS: Windows 10
● PyCharm 2022.2.3 (Professional Edition)
● Python 3.10.10 installed via the official website
● pygame 2.5.0 installed via PyCharm
● Keyboard: Varmilo VA87M connected via a data cable
● Lenovo LEGION Y7000P
When I initially encountered this issue (being unable to close the window by pressing the 'q' key), I was not aware of the case sensitivity problem.
Then I searched on Google for the problem, and many people suggested a solution of adding the line pygame.quit()
after sys.exit()
. I tried it, but it didn't work.
Then I came across a blog post where the author seemed to have a similar issue, and the post mentioned that using the uppercase 'Q' successfully closed the window. I tried it, and it worked.
from pcc_3e.
Does this mean you have to have caps lock on to quit the game?
from pcc_3e.
Does this mean you have to have caps lock on to quit the game?
Yes, I need to have Caps Lock on to quit the game (and close the window, if these two are the same). If I press the lowercase 'q', the game window will not close, but it will simply stop responding to any keys. It's somewhat like quitting the game anyway.
from pcc_3e.
I downloaded the version of the game you have in your repository, and it quits when I press q, shift-q. Both of those combinations work with or without caps lock on.
Here's a minimal program that just shows information about each key that's pressed:
import sys
import pygame
class KeyDisplayer:
"""Show info about any key that's pressed."""
def __init__(self):
pygame.init()
self.screen = pygame.display.set_mode((400, 200))
def run_game(self):
while True:
# Watch for keyboard and mouse events.
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
elif event.type == pygame.KEYDOWN:
key_name = pygame.key.name(event.key)
print(event.key, key_name)
if __name__ == '__main__':
kd = KeyDisplayer()
kd.run_game()
# Start with caps lock off, and press the following keys:
# q, shift-q, caps lock, q
Here's my output:
$ python key_displayer.py
pygame 2.5.1 (SDL 2.28.2, Python 3.11.2)
Hello from the pygame community. https://www.pygame.org/contribute.html
113 q
1073742049 left shift
113 q
1073741881 caps lock
113 q
What do you get if you press q, shift-q, caps lock, q?
Also, do you get the same results if you unplug the external keyboard and use your laptop's built-in keyboard? (both with this minimal program and the original game program?)
from pcc_3e.
I think I've found the reason for the issue. My keyboard language is set to Chinese by default, and even when switched to English input mode, the situation I described occurs. When I change the keyboard language to English, both lowercase and uppercase 'q' can exit the game properly.
In the case where the keyboard language is set to Chinese, whether using an external keyboard or the built-in laptop keyboard, only 'q' with Caps Lock on can successfully exit the game, while 'q' and 'Shift+q' can not.
Here's my output where the keyboard language is set to Chinese :
pygame 2.5.0 (SDL 2.28.0, Python 3.10.10)
Hello from the pygame community. https://www.pygame.org/contribute.html
1073741881 caps lock
Anyway, I'm very sorry for taking up your time due to the keyboard language, and I really appreciate your patient assistance.
from pcc_3e.
No problem, that was really interesting!
I'm glad you got it sorted, and I'm happy to know a little more about how internationalization work impacts a project like Pygame. I'm sure I will see this issue in some form or another again at some point.
from pcc_3e.
Related Issues (9)
- Python crash course
- pathlib.Path read_text() HOT 1
- UnboundLocalError: local variable 'range' referenced before assignment HOT 3
- Matplotlib installation through pip HOT 2
- pcc_3e/chapter_11 /test_name_function.py differs from text printed in book HOT 3
- Hello world! from Command Prompt Error HOT 9
- About ex_20_4_extended HOT 4
- chapter_13/ending_the_game : Ship Limit Discrepancy in Alien Invasion Game
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pcc_3e.