我们从Python开源项目中,提取了以下5个代码示例,用于说明如何使用pygame.KMOD_SHIFT。
def update(self, pressed_keys): if pressed_keys[K_w]: if pygame.key.get_mods() & pygame.KMOD_SHIFT: self.pixel.move((0, self.r_converter(10))) else: self.pixel.move((0, self.r_converter(200))) if pressed_keys[K_s]: if pygame.key.get_mods() & pygame.KMOD_SHIFT: self.pixel.move((0, self.r_converter(-10))) else: self.pixel.move((0, self.r_converter(-200))) if pressed_keys[K_a]: if pygame.key.get_mods() & pygame.KMOD_SHIFT: self.pixel.move((self.r_converter(-10), 0)) else: self.pixel.move((self.r_converter(-200), 0)) if pressed_keys[K_d]: if pygame.key.get_mods() & pygame.KMOD_SHIFT: self.pixel.move((self.r_converter(10), 0)) else: self.pixel.move((self.r_converter(200), 0)) self.axis = self.a_converter(self.pixel.axis)
def update(self, pressed_keys): small_step = 10 large_step = 200 if pressed_keys[K_w]: if pygame.key.get_mods() & pygame.KMOD_SHIFT: self.grating.move((0, self.r_converter(small_step))) else: self.grating.move((0, self.r_converter(large_step))) if pressed_keys[K_s]: if pygame.key.get_mods() & pygame.KMOD_SHIFT: self.grating.move((0, self.r_converter(-small_step))) else: self.grating.move((0, self.r_converter(-large_step))) if pressed_keys[K_a]: if pygame.key.get_mods() & pygame.KMOD_SHIFT: self.grating.move((self.r_converter(-small_step), 0)) else: self.grating.move((self.r_converter(-large_step), 0)) if pressed_keys[K_d]: if pygame.key.get_mods() & pygame.KMOD_SHIFT: self.grating.move((self.r_converter(small_step), 0)) else: self.grating.move((self.r_converter(large_step), 0)) self.axis = self.a_converter(self.grating.axis)
def is_caps(): return pygame.key.get_mods() & pygame.KMOD_SHIFT or pygame.key.get_mods() & pygame.KMOD_CAPS
def get_event(self, event): if event.type == pg.QUIT: self.done = True elif event.type == self.CHANGESTATE: self.change_state() elif event.type == self.UPDATECALENDAR: self.update_calendar() elif event.type == self.UPDATEQUOTE: self.update_quote() elif event.type == self.UPDATEWEATHER: self.update_weather() elif event.type == self.NIGHTRADIO: if self.RESTING and self.RADIO_RUNNING: process_input('s41\n') pg.time.set_timer(self.NIGHTRADIO,0) print('Station Changed to Relaxation Radio, disabling timer') elif event.type == pg.KEYDOWN: if event.key == pg.K_ESCAPE: if self.RADIO_RUNNING: process_input('q') print('You pressed ESC... Quitting') self.done = True return if not self.RADIO_RUNNING: if event.key == pg.K_m and pg.key.get_mods() & pg.KMOD_CTRL: print('Attempting to start the music') self.RADIO_RUNNING = True start_pianobar(sys.platform) else: if event.key in self.keymap_dict: if event.key == pg.K_q: self.RADIO_RUNNING = False process_input('q') elif event.key == pg.K_r: print('choosing a random radio station') sl = readfile(self.cwd+'/scripts/stationlist') random_station = 's'+str(random.randint(0,(len(sl)-1)))+'\n' process_input(random_station) else: process_input(self.keymap_dict[event.key]) elif event.key == pg.K_9 and pg.key.get_mods() & pg.KMOD_SHIFT: process_input('(') elif event.key == pg.K_0 and pg.key.get_mods() & pg.KMOD_SHIFT: process_input(')')
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