我们从Python开源项目中,提取了以下8个代码示例,用于说明如何使用pygame.K_LSHIFT。
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 __init__(self): super(JackitConfigControls, self).__init__() self.up = pygame.K_w self.down = pygame.K_s self.left = pygame.K_a self.right = pygame.K_d self.jump = pygame.K_SPACE self.interact = pygame.K_e self.push = pygame.K_LSHIFT self.reset_code = pygame.K_q self.toggle_sound = pygame.K_m self.kill_self = pygame.K_k self.reset_game = pygame.K_n
def from_json(self, raw): ''' Load the object from JSON loaded from config file ''' # First pass make sure all are valid for key in raw: if isinstance(raw[key], str): if not hasattr(pygame, raw[key]): raise ConfigError( "Invalid control for {}. Must be a valid pygame key constant".format(key) ) else: raw[key] = getattr(pygame, raw[key]) elif isinstance(raw[key], int): pass else: raise ConfigError( "Controls must be a valid pygame key constant as a string or integer" ) # Check for duplicates values = list(raw.values()) values_set = set(values) if len(values) != len(values_set): raise ConfigError("Cannot have duplicate controls") self.up = raw.get('up', getattr(pygame, 'K_w')) self.down = raw.get('down', getattr(pygame, 'K_s')) self.left = raw.get('left', getattr(pygame, 'K_a')) self.right = raw.get('right', getattr(pygame, 'K_d')) self.jump = raw.get('jump', getattr(pygame, 'K_SPACE')) self.interact = raw.get('interact', getattr(pygame, 'K_e')) self.push = raw.get("push", getattr(pygame, "K_LSHIFT")) self.reset_code = raw.get("reset_code", getattr(pygame, "K_q")) self.toggle_sound = raw.get("toggle_sound", getattr(pygame, "K_m")) self.kill_self = raw.get("kill_self", getattr(pygame, "K_k")) self.reset_game = raw.get("reset_game", getattr(pygame, "K_n"))
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 handleInput(self, sprite, event): if event.type == pygame.KEYDOWN: if event.key == pygame.K_RIGHT or event.key == pygame.K_d: sprite.updateSpeedRight() sprite.rightPressed = True elif event.key == pygame.K_LEFT or event.key == pygame.K_a: sprite.updateSpeedLeft() sprite.leftPressed = True elif event.key == pygame.K_DOWN or event.key == pygame.K_s: sprite.updateSpeedDown() sprite.downPressed = True elif event.key == pygame.K_UP or event.key == pygame.K_w: sprite.updateSpeedUp() sprite.upPressed = True elif event.key == pygame.K_LSHIFT: sprite.leftShiftPressed = True if event.type == pygame.KEYUP: if event.key == pygame.K_RIGHT or event.key == pygame.K_d: sprite.rightPressed = False elif event.key == pygame.K_LEFT or event.key == pygame.K_a: sprite.leftPressed = False elif event.key == pygame.K_UP or event.key == pygame.K_w: sprite.upPressed = False elif event.key == pygame.K_DOWN or event.key == pygame.K_s: sprite.downPressed = False elif event.key == pygame.K_LSHIFT: sprite.leftShiftPressed = False elif event.key == pygame.K_SPACE: sprite.spacePressed = False if event.type == pygame.MOUSEBUTTONDOWN: if event.button == MOUSE_LEFT: sprite.leftMousePressed = True elif event.button == MOUSE_RIGHT: sprite.rightMousePressed = True elif event.type == pygame.MOUSEBUTTONUP: if event.button == MOUSE_LEFT: sprite.leftMousePressed = False elif event.button == MOUSE_RIGHT: sprite.rightMousePressed = False
def userInput(camera, display): deltaT = display.deltaT #keyboard down presses pressed = pygame.key.get_pressed() for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() quit() if event.type == pygame.KEYDOWN: if event.key ==pygame.K_ESCAPE: pygame.quit() quit() if event.type == pygame.MOUSEMOTION: x, y = event.rel event.pos = (display.w/2,display.h/2) #look around if( abs(x)>1 ): camera.turnRight( -x*deltaT) if( abs(y)>1 ): camera.turnUp( -y*deltaT) #capture mouse pygame.mouse.set_pos(display.w/2., display.w/2) pygame.event.get(pygame.MOUSEMOTION) #steal the new mouse event and do nothing with it to reset it #print() #print(camera.posWorld.getString()) #print(camera.view()) #back forth if pressed[pygame.K_w]: camera.forward(deltaT) if pressed[pygame.K_s]: camera.forward(-deltaT) #up, down if pressed[pygame.K_SPACE]: camera.upward(-deltaT) if pressed[pygame.K_LSHIFT]: camera.upward(deltaT) #left right if pressed[pygame.K_a]: camera.sideward(deltaT) if pressed[pygame.K_d]: camera.sideward(-deltaT) #change openGL polygon mode if pressed[pygame.K_1]: glPolygonMode(GL_FRONT_AND_BACK, GL_POINT) if pressed[pygame.K_2]: glPolygonMode(GL_FRONT_AND_BACK, GL_LINE) if pressed[pygame.K_3]: glPolygonMode(GL_FRONT_AND_BACK, GL_FILL) #start the main
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