我们从Python开源项目中,提取了以下4个代码示例,用于说明如何使用pygame.K_RSHIFT。
def keyDown(self, event): if self.selected: if event.key == pygame.K_ESCAPE: self.selected = False elif event.key == pygame.K_BACKSPACE and len(self.current_string) > 0: #self.current_string = self.current_string[:-1] self.current_string.pop(self.curpos - 1) self.curpos -= 1 elif event.key == pygame.K_DELETE and len(self.current_string) > 0: #self.current_string = self.current_string[:-1] self.current_string.pop(self.curpos) elif event.key == pygame.K_RETURN: if self.completeHandler != None: self.completeHandler(self, string.join(self.current_string, "")) self.completed = True elif event.key >= 32 and event.key <= 127: k = event.key kp = pygame.key.get_pressed() if (kp[pygame.K_LSHIFT] or kp[pygame.K_RSHIFT]) and k > 96 and k < 123: k -= 32 elif (kp[pygame.K_LSHIFT] or kp[pygame.K_RSHIFT]) and k > 32: k = ord(self.schars[chr(k)]) self.current_string.insert(self.curpos, chr(k)) self.curpos += 1 elif event.key == pygame.K_LEFT and self.curpos > 0: self.curpos -= 1 elif event.key == pygame.K_RIGHT and self.curpos < len(self.current_string): self.curpos += 1
def readChar(): if event.key == pygame.K_BACKSPACE: return 'backspace' elif event.key == pygame.K_PAGEUP: return 'pageup' elif event.key == pygame.K_PAGEDOWN: return 'pagedown' elif event.key == pygame.K_TAB: return 'tab' elif event.key == pygame.K_RETURN: return 'enter' elif event.key == pygame.K_ESCAPE: return 'esc' elif event.key in (pygame.K_RSHIFT, pygame.K_LSHIFT): return 'shift' elif event.key in (pygame.K_RCTRL, pygame.K_LCTRL): return 'control' elif event.key == pygame.K_RIGHT: return 'kright' elif event.key == pygame.K_LEFT: return 'kleft' elif event.key == pygame.K_UP: return 'kup' elif event.key == pygame.K_DOWN: return 'kdown' elif event.key == pygame.K_CAPSLOCK: return None elif event.key == 282: return 'paste' elif event.key == 283: return 'begincur' elif event.key == 284: return 'endcur' elif event.key == 285: return 'delall' else: return event.unicode
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
def process_event(self, event): # perf: local for faster access io = self.io if event.type == pygame.MOUSEMOTION: io.mouse_pos = event.pos if event.type == pygame.MOUSEBUTTONDOWN: if event.button == 1: io.mouse_down[0] = 1 if event.button == 2: io.mouse_down[1] = 1 if event.button == 3: io.mouse_down[2] = 1 if event.type == pygame.MOUSEBUTTONUP: if event.button == 1: io.mouse_down[0] = 0 if event.button == 2: io.mouse_down[1] = 0 if event.button == 3: io.mouse_down[2] = 0 if event.button == 4: io.mouse_wheel = .5 if event.button == 5: io.mouse_wheel = -.5 if event.type == pygame.KEYDOWN: for char in event.unicode: code = ord(char) if 0 < code < 0x10000: io.add_input_character(code) io.keys_down[event.key] = True if event.type == pygame.KEYUP: io.keys_down[event.key] = False if event.type in (pygame.KEYDOWN, pygame.KEYUP): io.key_ctrl = ( io.keys_down[pygame.K_LCTRL] or io.keys_down[pygame.K_RCTRL] ) io.key_alt = ( io.keys_down[pygame.K_LALT] or io.keys_down[pygame.K_RALT] ) io.key_shift = ( io.keys_down[pygame.K_LSHIFT] or io.keys_down[pygame.K_RSHIFT] ) io.key_super = ( io.keys_down[pygame.K_LSUPER] or io.keys_down[pygame.K_LSUPER] ) if event.type == pygame.VIDEORESIZE: io.display_size = event.size