【问题标题】:How to print/detect the scancode of a pressed key in pygame?如何在pygame中打印/检测按键的扫描码?
【发布时间】:2016-08-07 00:28:35
【问题描述】:

如何在pygame中打印/检测按键的扫描码?

如果我这样做:

for event in pygame.event.get():
    print event

打印出来:

<Event(2-KeyDown {'scancode': 1, 'key': 115, 'unicode': u's', 'mod': 0})>
<Event(3-KeyUp {'scancode': 1, 'key': 115, 'mod': 0})>

但是我怎样才能让它打印出扫描码部分呢?例如当我按d 时打印出1

我试过这个:

for event in pygame.event.get():
    print event["scancode"]

这会引发错误消息,因为它不是真正的字典数据结构。

【问题讨论】:

标签: python dictionary pygame


【解决方案1】:

你试过event.scancode吗? documentation 表示按键事件具有以下属性:

  • key是整数ID
  • unicode 是单个字符的 UNICODE 字符串
  • scancode 是平台特定的密钥代码

我猜mod 是 OR-d 位的位掩码。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-10-27
    • 2020-12-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多