Pygame: Is there any easy way to find the letter/number of ANY alphanumeric pressed?

前端 未结 2 682
长情又很酷
长情又很酷 2020-11-29 13:17

Game I\'m working on currently needs to let people time in their name for highscore board. I\'m slightly familiar with how to deal with key presses, but I\'ve only dealt wit

2条回答
  •  醉梦人生
    2020-11-29 14:19

    if you look K_a is just 97 thats the ascii code for 'a' , I will extrapolate to K_? is the ascii code for whatever the question mark represents

    if event.type == KEYUP: 
        print chr(event.key) #convert ascii code to a character
    

    maybe?

    as pointed out this will not work with ascii over 255 (no longer ascii really)

    you can use the method outlined below or just use unichr(event.key) instead of chr

提交回复
热议问题