【问题标题】:Get special characters from the key events从关键事件中获取特殊字符
【发布时间】:2014-02-01 08:43:10
【问题描述】:

当 PyGame 键事件被触发时,与键关联的字母使用chr(event.key) 收集。当在挪威语键盘上按下带有特殊字符的键时,这不起作用,例如 æøå

if event.type == pygame.KEYDOWN:
    characterNumber = event.key
    character = chr(characterNumber)
    print(character)

如何检索这些字符?

【问题讨论】:

    标签: python keyboard pygame special-characters


    【解决方案1】:

    不要这样做:

    characterNumber = event.key
    character = chr(characterNumber)
    

    试试这个:

    character = event.unicode
    

    根据文档,KEYDOWN 事件应具有 unicode 属性,该属性表示基于当前键盘布局而按下的键的 unicode 值。

    http://www.pygame.org/docs/ref/event.html

    【讨论】:

      猜你喜欢
      • 2016-10-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多