How to read a single character from the user?

后端 未结 23 2661
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-21 04:28

Is there a way of reading one single character from the user input? For instance, they press one key at the terminal and it is returned (sort of like getch()).

23条回答
  •  北恋
    北恋 (楼主)
    2020-11-21 05:12

    Try this with pygame:

    import pygame
    pygame.init()             // eliminate error, pygame.error: video system not initialized
    keys = pygame.key.get_pressed()
    
    if keys[pygame.K_SPACE]:
        d = "space key"
    
    print "You pressed the", d, "."
    

提交回复
热议问题