Pygame 检测任何按键而不只是 'S' 键

Pygame detecting any keydown instead of just 'S' key

当运行以下代码行时,用户应该按'W'按钮开始冥想,然后按'S'按钮停止冥想,但是我是发现如果按下任何按钮,用户开始或停止冥想取决于 DL[19] = 4 或 0。这是一个问题,因为我需要键 'A' 和 'D' 来导航房间。关于如何解决这个问题有什么建议吗?

        if DL[19] == 0: # no activity
            displaydata1 = font.render(" 'W' Key: meditate", True, (255,255,255))
            screen.blit(displaydata1, (coordinates[0], coordinates[1] + 14))
            if event.type == pygame.KEYDOWN:
                if pygame.K_w:
                    DL[19] = 4 # set activity to meditating

        elif DL[19] == 4: # meditating
            displaydata1 = font.render(" 'S' Key: stop meditating", True, (255,255,255))
            screen.blit(displaydata1, (coordinates[0], coordinates[1] + 14))
            if event.type == pygame.KEYDOWN:
                if pygame.K_s:
                    DL[19] = 0 # set to no activity
if DL[19] == 0: # no activity
            displaydata1 = font.render(" 'W' Key: meditate", True, (255,255,255))
            screen.blit(displaydata1, (coordinates[0], coordinates[1] + 14))
            if event.type == pygame.KEYDOWN:
                if event.type == pygame.K_w:
                    DL[19] = 4 # set activity to meditating

        elif DL[19] == 4: # meditating
            displaydata1 = font.render(" 'S' Key: stop meditating", True, (255,255,255))
            screen.blit(displaydata1, (coordinates[0], coordinates[1] + 14))
            if event.type == pygame.KEYDOWN:
                if event.type == pygame.K_s:
                    DL[19] = 0 # set to no activity


你说event.type == pygame.K_w看看“w”是否被点击