Python pygame 模块,K_KP5 实例源码

我们从Python开源项目中,提取了以下1个代码示例,用于说明如何使用pygame.K_KP5

项目:jackit    作者:vix597    | 项目源码 | 文件源码
def character_key(self, key):
        '''
        Handles the rest of the keys
        '''

        if key == pygame.K_LSHIFT or key == pygame.K_RSHIFT:
            return # Skip the event for the shift key itself

        try:
            # Handle the number pad
            if key == pygame.K_KP0:
                key = pygame.K_0
            elif key == pygame.K_KP1:
                key = pygame.K_1
            elif key == pygame.K_KP2:
                key = pygame.K_2
            elif key == pygame.K_KP3:
                key = pygame.K_3
            elif key == pygame.K_KP4:
                key = pygame.K_4
            elif key == pygame.K_KP5:
                key = pygame.K_5
            elif key == pygame.K_KP6:
                key = pygame.K_6
            elif key == pygame.K_KP7:
                key = pygame.K_7
            elif key == pygame.K_KP8:
                key = pygame.K_8
            elif key == pygame.K_KP9:
                key = pygame.K_9
            elif pygame.key.get_mods() & pygame.KMOD_SHIFT:
                if key >= 97 and key <= 122:
                    key = ord(chr(key).upper())
                else:
                    if KEY_TO_SHIFT_MAP.get(chr(key), None) is not None:
                        key = ord(KEY_TO_SHIFT_MAP[chr(key)])

            self.text = ''.join((
                self.text[:self.cursor_position],
                chr(key),
                self.text[self.cursor_position:]
            ))
            self.cursor_position += 1
        except ValueError:
            self.game_engine.hud.display_hint("Attempt to enter an invalid character!", 2)
            return