如何在pygame,event.key中使用字母/数字组合?

时间:2015-01-18 17:29:14

标签: pygame

我知道在pygame中,对于命令:

if event.key==K_r:  

当你按下键盘上的字母r时,你会收到回复。但我想增加点唱机的字母/数字组合的复杂性。所以我试过了:

if event.key==K_r3:

我按了r然后我按了3.但是我收到一个错误:名字'K_r3'没有定义。我希望我不必为每个可能的字母/数字组合写出定义。有什么建议吗?

1 个答案:

答案 0 :(得分:1)

`不要担心Rico,有一个答案。请尝试以下方法:

if event.type == KEYDOWN:

#this says that a key was pressed down

keys = pygame.key.get_pressed()

#this is a list of all the keys that were pressed down. now, if you want to do do multiple keys, the answer is as follows:

if keys[K_3] and keys[K_r]:

(function)

我希望这可以帮助你实现pygame伟大。

相关问题