鱼C论坛

 找回密码
 立即注册
查看: 3392|回复: 2

Pygame事件的输入问题

[复制链接]
发表于 2022-11-10 18:37:49 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
小甲鱼老师在讲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
  1. import pygame
  2. import sys

  3. pygame.init()

  4. size = width, height = 600, 400
  5. screen = pygame.display.set_mode(size)
  6. pygame.display.set_caption('FishC Demo')
  7. bg = (0, 0, 0)

  8. position = 0

  9. font = pygame.font.Font(None, 20)
  10. line_height = font.get_linesize()
  11. screen.fill(bg)

  12. while True:
  13.     for event in pygame.event.get():
  14.         if event.type == pygame.QUIT:
  15.             sys.exit()

  16.         screen.blit(font.render(str(event), True, (0, 255, 0)), (0, position))
  17.         position += line_height

  18.         if position > height:
  19.             position = 0
  20.             screen.fill(bg)

  21.         pygame.display.flip()
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2022-11-10 19:19:18 | 显示全部楼层
所以,,你的问题是什么??

你一直按着字母键s,它当然一直是 TextInput 的事件啦。。
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2022-11-10 21:46:28 | 显示全部楼层
阿奇_o 发表于 2022-11-10 19:19
所以,,你的问题是什么??

你一直按着字母键s,它当然一直是 TextInput 的事件啦。。

小甲鱼老师演示的是一直按着字母键h,但他却没有TextInput的事件
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-4-25 18:24

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表