我们从Python开源项目中,提取了以下14个代码示例,用于说明如何使用pygame.K_x()。
def run(self): while self.visible & this.drawing: # wait for event event = pygame.event.wait() if event.type == pygame.KEYDOWN: if event.key == pygame.K_DOWN: self.select_previous() elif event.key == pygame.K_LEFT: self.select_previous() elif event.key == pygame.K_RETURN: self.activate() elif event.key == pygame.K_z: self.activate() elif event.key == pygame.K_x: self.previous_menu() elif event.key == pygame.K_RIGHT: self.select_next() # runs self, as well as show.
def _map_keys(self): key_map = self.io.key_map key_map[imgui.KEY_TAB] = pygame.K_TAB key_map[imgui.KEY_LEFT_ARROW] = pygame.K_LEFT key_map[imgui.KEY_RIGHT_ARROW] = pygame.K_RIGHT key_map[imgui.KEY_UP_ARROW] = pygame.K_UP key_map[imgui.KEY_DOWN_ARROW] = pygame.K_DOWN key_map[imgui.KEY_PAGE_UP] = pygame.K_PAGEUP key_map[imgui.KEY_PAGE_DOWN] = pygame.K_PAGEDOWN key_map[imgui.KEY_HOME] = pygame.K_HOME key_map[imgui.KEY_END] = pygame.K_END key_map[imgui.KEY_DELETE] = pygame.K_DELETE key_map[imgui.KEY_BACKSPACE] = pygame.K_BACKSPACE key_map[imgui.KEY_ENTER] = pygame.K_RETURN key_map[imgui.KEY_ESCAPE] = pygame.K_ESCAPE key_map[imgui.KEY_A] = pygame.K_a key_map[imgui.KEY_C] = pygame.K_c key_map[imgui.KEY_V] = pygame.K_v key_map[imgui.KEY_X] = pygame.K_x key_map[imgui.KEY_Y] = pygame.K_y key_map[imgui.KEY_Z] = pygame.K_z
def _Keyboard_Event(self, key, down=True): """ Internal keyboard event, don't override this. Checks for the initial keydown of the basic testbed keys. Passes the unused ones onto the test via the Keyboard() function. """ if down: if key == pygame.K_z: # Zoom in self.viewZoom = min(2 * self.viewZoom, 500.0) elif key == pygame.K_x: # Zoom out self.viewZoom = max(0.9 * self.viewZoom, 0.02)
def update(self, screen, event_queue, dt,clock,joystick, netmodel, vizmodel): # Logos/titles screen.blit(self.logo,(screen.get_width() / 4 - 265,screen.get_height() * 3 / 4-500)) screen.blit(self.intel,(screen.get_width() / 4 - 300,screen.get_height()-130)) screen.blit(self.activestate,(screen.get_width() - 980,screen.get_height() - 130)) nextState = self displaytext('Play', 32, screen.get_width() / 4 - 20, screen.get_height() * 3 / 4 - 80, WHITE, screen) displaytext('Train', 32, screen.get_width() / 4 - 20, screen.get_height() * 3 / 4 - 40, WHITE, screen) displaytext('Exit', 32, screen.get_width() / 4 - 20, screen.get_height() * 3 / 4, WHITE, screen) displaytext(u'\u00bb', 32, screen.get_width() / 4 - 60, screen.get_height() * 3 / 4 - 40*self.menu_selection, WHITE, screen) # Each game state processes its own input queue in its own way to avoid messy input logic for event in event_queue: if event.type == pygame.KEYDOWN or event.type == pygame.JOYBUTTONDOWN: if (event.type == pygame.KEYDOWN and (event.key == pygame.K_DOWN)) or (event.type == pygame.JOYBUTTONDOWN and (event.button == 1)) or (event.type == pygame.JOYAXISMOTION and (event.axis == 1 or event.value >= DEADZONE)): self.menu_selection -= 1 if self.menu_selection == -1: self.menu_selection = 2 if (event.type == pygame.KEYDOWN and (event.key == pygame.K_UP)) or (event.type == pygame.JOYBUTTONDOWN and (event.button == 0)) or (event.type == pygame.JOYAXISMOTION and (event.axis == 1 or event.value <= -DEADZONE)): self.menu_selection += 1 if self.menu_selection == 3: self.menu_selection = 0 if (event.type == pygame.KEYDOWN and event.key == pygame.K_RETURN) or (event.type == pygame.JOYBUTTONDOWN and event.button == 11): if self.menu_selection == 2: nextState = Play(False) elif self.menu_selection == 1: nextState = Play(True) else: nextState = None if (event.type == pygame.KEYDOWN and event.key == pygame.K_x): self.ExportModel() if (event.type == pygame.KEYDOWN and event.key == pygame.K_d): self.DumpData() if (event.type == pygame.KEYDOWN and event.key == pygame.K_w): self.DumpWeights() return nextState
def init_rotary_encoders(self): """ Rotary encoders (RE) initializer. This is executed only if RE enabled in config.txt. Two REs are configured this way: 1. Volume Control: GPIO16 - Volume Up, GPIO26 - Volume Down, GPIO13 - Mute 2. Tuning: GPIO12 - Move Right, GPIO6 - Move Left, GPIO5 - Select RE events will be wrapped into keyboard events with the following assignment: Volume Up - '+' key on numeric keypad, Volume Down - '-' key on keypad, Mute - 'x' key """ if not self.config[USAGE][USE_ROTARY_ENCODERS]: return from event.rotary import RotaryEncoder RotaryEncoder(16, 26, 13, pygame.K_KP_PLUS, pygame.K_KP_MINUS, pygame.K_x) RotaryEncoder(12, 6, 5, pygame.K_RIGHT, pygame.K_LEFT, pygame.K_RETURN)
def process_input(self): for event in pygame.event.get(): if event.type == pygame.QUIT: sys.exit() if event.type == pygame.KEYDOWN: if self.state.paused: if event.key == pygame.K_r: self.state.paused = False if self.state.game_over: if event.key == pygame.K_r: self.state = State(self.ROWS, self.COLS) if event.key == pygame.K_ESCAPE: sys.exit() if self.state.running: if event.key == pygame.K_DOWN: self.state.move_piece(board.DIRECTION_DOWN) if event.key == pygame.K_LEFT: self.state.move_piece(board.DIRECTION_LEFT) if event.key == pygame.K_RIGHT: self.state.move_piece(board.DIRECTION_RIGHT) if event.key == pygame.K_x: self.state.rotate_piece() if event.key == pygame.K_z: self.state.rotate_piece(True) if event.key == pygame.K_SPACE: self.state.drop_piece() if event.key == pygame.K_p: self.state.paused = True
def update(self, gamemap): ''' updated die Playerbewegungen beim (knopfdruck events) Parameter: Spielobjekt, gamemap return Value: - ''' keys = pygame.key.get_pressed() newRect = self.rect if keys[pygame.K_w]: newRect = self.rect.move(0, -self.speed) if gamemap.isRectValid(newRect): self.rect = newRect if keys[pygame.K_s]: newRect = self.rect.move(0, self.speed) if gamemap.isRectValid(newRect): self.rect = newRect if keys[pygame.K_a]: newRect = self.rect.move(-self.speed, 0) if gamemap.isRectValid(newRect): self.rect = newRect if keys[pygame.K_d]: newRect = self.rect.move(self.speed, 0) if gamemap.isRectValid(newRect): self.rect = newRect if keys[pygame.K_x]: print self.rect.center, self.room #def shot(self, xPos, yPos, eventPos):
def keyEvent(self, event): if event.type == pygame.KEYDOWN: if event.key == pygame.K_DOWN: self.down = 0 if event.key == pygame.K_UP: self.up = 0 if event.key == pygame.K_LEFT: self.left = 0 if event.key == pygame.K_RIGHT: self.right = 0 if event.key == pygame.K_a: self.start = 0 if event.key == pygame.K_s: self.select = 0 if event.key == pygame.K_x: self.b = 0 if event.key == pygame.K_z: self.a = 0 if event.type == pygame.KEYUP: if event.key == pygame.K_DOWN: self.down = 1 if event.key == pygame.K_UP: self.up = 1 if event.key == pygame.K_LEFT: self.left = 1 if event.key == pygame.K_RIGHT: self.right = 1 if event.key == pygame.K_a: self.start = 1 if event.key == pygame.K_s: self.select = 1 if event.key == pygame.K_x: self.b = 1 if event.key == pygame.K_z: self.a = 1
def steer(self): complex_cmd = False while self.send_inst: for event in pygame.event.get(): if event.type == KEYDOWN or complex_cmd: key_input = pygame.key.get_pressed() complex_cmd = False # complex car controls if key_input[pygame.K_UP] and key_input[pygame.K_RIGHT]: print("Forward Right") complex_cmd = True self.ser.write(b'5') elif key_input[pygame.K_UP] and key_input[pygame.K_LEFT]: print("Forward Left") complex_cmd = True self.ser.write(b'6') elif key_input[pygame.K_DOWN] and key_input[pygame.K_RIGHT]: print("Reverse Right") complex_cmd = True self.ser.write(b'7') elif key_input[pygame.K_DOWN] and key_input[pygame.K_LEFT]: print("Reverse Left") complex_cmd = True self.ser.write(b'8') # simple car controls elif key_input[pygame.K_UP]: print("Forward") self.ser.write(b'1') elif key_input[pygame.K_DOWN]: print("Reverse") self.ser.write(b'2') elif key_input[pygame.K_RIGHT]: print("Right") self.ser.write(b'3') elif key_input[pygame.K_LEFT]: print("Left") self.ser.write(b'4') # exit elif key_input[pygame.K_x] or key_input[pygame.K_q]: self.close_serial_connection() break elif event.type == pygame.KEYUP: self.ser.write(b'0') elif event.type == pygame.QUIT: self.close_serial_connection() break
def keyboard_interaction(): global current_text_tag,last_time_text,animation_speed,NEXT_CRITICAL_ACTION if IS_RASPBERRY: check_hardware_buttons() for event in pygame.event.get(): if event.type == pygame.KEYDOWN: if event.key == pygame.K_ESCAPE: pygame.quit() exit() elif event.key == pygame.K_SPACE: camera.save_frame(frameManager) current_text_tag="scattato" elif event.key == pygame.K_UP: NEXT_CRITICAL_ACTION="changetosession"+str(frameManager.current_session+1) current_text_tag="cambio sessione" elif event.key == pygame.K_DOWN: NEXT_CRITICAL_ACTION="changetosession"+str(frameManager.current_session-1) current_text_tag="cambio sessione" elif event.key == pygame.K_x: frameManager.remove_frame() current_text_tag="rimosso" elif event.key == pygame.K_s: NEXT_CRITICAL_ACTION="save" current_text_tag="saving" elif event.key == pygame.K_r: camera.ruota() elif event.key == pygame.K_DELETE: frameManager.delete_all() elif event.key == pygame.K_BACKSPACE: frameManager.delete_current_scene() elif event.key == pygame.K_p: animation_speed/=2.0 if animation_speed<0.003125: animation_speed=0.003125 elif event.key == pygame.K_o: animation_speed*=2.0 if animation_speed>3.2: animation_speed=3.2 else: for n in range(10): if event.key == pygame.__dict__["K_"+str(n)]: nf=n-1 if nf<0: nf=9 NEXT_CRITICAL_ACTION="changetosession"+str(nf) current_text_tag="cambio sessione" last_time_text=time.time()