最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

python - How to properly detect pressed buttons in pygamepygame-ce? - Stack Overflow

programmeradmin4浏览0评论

I noticed that when you launch script with pygame, every button's keycode 'sticks' to keyboard layout language. That makes it impossible to detect key pressing if script didn't start in latin, as keycode no more matches something code expects.

I tried code below and it will print 113 if I start with latin layout and press 'q', even if I change layout to cyrillic and press 'й'. But if I start with cyrillic layout and press 'й' it will print 1081, even if I change layout to latin and press 'q'.

for event in pygame.event.get():
    if event.type == pygame.KEYDOWN:
        print(event.key)

All that means that if I start with cyrillic layout script will print 1081, if I start with latin layout it will print 113, and if I start with other layout it will print other number.

event object also has scancode and unicode, I think that may be useful.

Is there a way to bypass this?

pygame.key.get_pressed() also doesn't work as it compares same keycodes, so q's keycode 113 != й's keycode 1081

发布评论

评论列表(0)

  1. 暂无评论