Pygame only detects mouse events, does not detect KEYDOWN events

后端 未结 3 1967
清酒与你
清酒与你 2021-01-20 15:16

I have written the following simple program which should print out all events detected by pygame.event.get().

import pygame, sys
from pygame.loc         


        
相关标签:
3条回答
  • 2021-01-20 15:54

    For anyone still struggling with this, the issue is documented here on git and is fixed. https://github.com/pygame/pygame/issues/203

    Just uninstall pygame from your venv, then install below version.

    pip install -U https://github.com/pygame/pygame/archive/master.zip
    

    Just tried this and can finally use key events in pygame.

    0 讨论(0)
  • 2021-01-20 15:58

    If you're working in a virtualenv, don't use the virtualenv command.

    Use python3 -m venv.

    Then install pygame (e.g. pip3 install hg+http://bitbucket.org/pygame/pygame).

    See this thread for more details on this issue.

    0 讨论(0)
  • 2021-01-20 16:01

    Firstly i doubt you are but pygame only registers inputs when your focused on the pygame screen so there's that. I don't have a direct answer to your question so sorry but i do have my solution or work around to it. Because i dislike the normal event system i use pygame.key.get_pressed() (https://www.pygame.org/docs/ref/key.html) just because i think it looks better and more readable. This is probably just a bad habit of mine though sooo.....

    0 讨论(0)
提交回复
热议问题