Pygame事件的输入问题
小甲鱼老师在讲Pygame事件中说并且示例:按下之后松开A、B、C、D等按键会且仅会出现KeyDown和KeyUp("如果我们按下字母h不动,他就会只有keydown"——小甲鱼老师)
但在我这边出现了这样一种情况
(不知道为什么我电脑不能传图片,所以下面是照着图片输入的内容。源码是小甲鱼老师在课上讲的“黑客帝国”的示例)
<Event(768-KeyDown{'unlcode':'s','key':115,'mod':4096,'scancode':22,'window':None})>
<Event(771-TextInput{'text':'s','window':'None'})>
<Event(771-TextInput{'text':'s','window':'None'})>
<Event(771-TextInput{'text':'s','window':'None'})>
<Event(771-TextInput{'text':'s','window':'None'})>
<Event(771-TextInput{'text':'s','window':'None'})>
<Event(771-TextInput{'text':'s','window':'None'})>
<Event(771-TextInput{'text':'s','window':'None'})>
<Event(769-KeyUp{'unlcode':'s','key':115,'mod':4096,'scancode':22,'window':None})>
电脑会一直出现textinput
import pygame
import sys
pygame.init()
size = width, height = 600, 400
screen = pygame.display.set_mode(size)
pygame.display.set_caption('FishC Demo')
bg = (0, 0, 0)
position = 0
font = pygame.font.Font(None, 20)
line_height = font.get_linesize()
screen.fill(bg)
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
screen.blit(font.render(str(event), True, (0, 255, 0)), (0, position))
position += line_height
if position > height:
position = 0
screen.fill(bg)
pygame.display.flip()
所以,,你的问题是什么??
你一直按着字母键s,它当然一直是 TextInput 的事件啦。。 阿奇_o 发表于 2022-11-10 19:19
所以,,你的问题是什么??
你一直按着字母键s,它当然一直是 TextInput 的事件啦。。
小甲鱼老师演示的是一直按着字母键h,但他却没有TextInput的事件
页:
[1]