pygame icon indicating copy to clipboard operation
pygame copied to clipboard

get_just_pressed() and get_just_released() functions

Open ScriptLineStudios opened this issue 3 years ago • 1 comments

Response to changes requested in #3190 (unfortunately had to open another PR because I now longer have the repo I made those changes in). As requested in #3175 there should be more global access to key information which can be accessed without going via the event loop. Here is an example of the api usage:

if pygame.key.get_just_pressed()[pygame.K_b]:
    print("B Pressed")
if pygame.key.get_just_pressed()[pygame.K_a]: 
    print("A Pressed")

if pygame.key.get_just_released()[pygame.K_b]:
    print("B Released")
if pygame.key.get_just_released()[pygame.K_a]: 
    print("A Released")

ScriptLineStudios avatar Jun 16 '22 13:06 ScriptLineStudios

This is a very impressive pull request for a first time contributor!

Left a couple notes from a quick skim.

It would be good for you to do a setup.py format and add type stubs to get a couple more of the test runners passing. Type stubs are here: https://github.com/pygame/pygame/tree/main/buildconfig/stubs/pygame

It also needs unit tests, those would go in here: https://github.com/pygame/pygame/blob/main/test/key_test.py

Starbuck5 avatar Jun 17 '22 08:06 Starbuck5

lol, I accidentally closed this

ScriptLineStudios avatar Nov 11 '22 12:11 ScriptLineStudios