pygame.key.get_pressed()返回包含键当前状态的列表。按住某个键时,该键的状态为
True,否则为
False。使用
pygame.key.get_pressed()评估是否一个键被连续按下。
while True: pressed_key= pygame.key.get_pressed() if pressed_key[pygame.K_UP]: # the pre in this condition is executed as long UP is hold down # [...]
当键的状态更改时,键盘事件(请参阅pygame.event模块)仅发生一次。
KEYDOWN每次按下一个键,事件就会发生一次。
KEYUP每次释放钥匙时发生一次。
while True: for event in pygame.event.get(): if event.type == pygame.KEYDOWN: if event.key == pygame.K_ESCAPE: # The following pre is executed once, every time when ESC is pressed. # [...] if event.type == pygame.KEYUP: if event.key == pygame.K_ESCAPE: # The following pre is executed once, every time when ESC is released. # [...]
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)