我们从Python开源项目中,提取了以下9个代码示例,用于说明如何使用pygame.K_DELETE。
def onKeyDown(self, event): if not self.select_item: if event.type == pygame.KEYDOWN and event.key == pygame.K_DELETE: pass elif event.type == pygame.KEYDOWN and event.key != pygame.K_RETURN and event.key != pygame.K_KP_ENTER and event.key != pygame.K_TAB: lhv = len(self.value) if event.key == pygame.K_BACKSPACE: if lhv > 0: if self.ls.lang.ltr_text: self.value = self.value[0:lhv - 1] else: self.value = self.value[1:lhv] else: char = event.unicode if len(char) > 0 and lhv < 21: if self.ls.lang.ltr_text: self.value = self.value + char else: self.value = char + self.value self.ls.reload_selects() self.ls.set_scrollbar_top(self.ls.scroll_min_top) elif event.key == pygame.K_RETURN or event.key == pygame.K_KP_ENTER or event.key == pygame.K_TAB: self.nextFocus() self.update_trigger()
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 main(self): """ Start the game :return: None """ logging.info("Starting game") self.board.initUI() winner = None while not self.exit: for event in pygame.event.get(): if event.type == pygame.QUIT: self.exit = True elif not self.gameOver: currentPlayer = self.players[self.turn] move = currentPlayer.getMove() self.turn = 'x' if self.turn == 'o' else 'o' winner = self.board.checkForWin(move)[0] if winner in ['x', 'o', 't']: logging.info("Game has ended with status: {}".format(winner)) self.gameOver = True self.board.displayWinner(self.board.checkForWin(move)) else: if event.type == pygame.KEYDOWN: if event.key in [pygame.K_RETURN, pygame.K_SPACE]: self.gameOver = False self.board.reset() self.board.initUI() elif event.key in [pygame.K_ESCAPE, pygame.K_DELETE, pygame.K_BACKSPACE]: self.exit = True pygame.display.flip() self.clock.tick(self.fps) self.exit = False self.gameOver = False self.board.reset() return winner
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 update(self, *args): """ Handles the selection parameters: tuple arguments for the update (first argument should be an instance pygame.event.Event) return values: - """ if len(args) > 0 and self.isActive(): event = args[0] if event.type == pygame.KEYDOWN and self.isFocused(): if event.key == pygame.K_UP: self.moveCursor(-1) elif event.key == pygame.K_DOWN: self.moveCursor(1) elif event.key == pygame.K_BACKSPACE or event.key == pygame.K_DELETE: if self.isEditable(): if self._selection == self._cursor: self.delete(self._selection - 1, CURSOR) self.moveCursor(-1) else: self.delete(SELECTION, CURSOR) self.setCursor(self._selection) elif event.type == pygame.MOUSEBUTTONUP: if self.rect.collidepoint(event.pos): self.setSelection(CURSOR, self._posToIndex(event.pos[1] - self.rect.y)) elif event.type == pygame.MOUSEBUTTONDOWN: if self.rect.collidepoint(event.pos): self.setCursor(self._posToIndex(event.pos[1] - self.rect.y)) super(Listbox, self).update(*args)
def update(self, *args): """ Handles the selection and keyboard-input parameters: tuple arguments for the update (first argument should be an instance pygame.event.Event) return values: - """ if len(args) > 0 and self.isActive(): event = args[0] if event.type == pygame.KEYDOWN and self.isFocused(): if event.key == pygame.K_LEFT: self.moveCursor(-1) elif event.key == pygame.K_RIGHT: self.moveCursor(1) elif event.key == pygame.K_BACKSPACE or event.key == pygame.K_DELETE: if self._selection == self._cursor: if event.key == pygame.K_DELETE: self.delete(self._selection + 1, CURSOR) else: self.delete(self._selection - 1, CURSOR) self.moveCursor(-1) else: self.delete(SELECTION, CURSOR) self.setCursor(self._sort(SELECTION, CURSOR)[0]) else: char = event.unicode.encode("ascii", "ignore") if (char != "" and (char == " " or not char.isspace()) and self._validation(self._text + char, self._text, self)): self.delete(SELECTION, CURSOR) s = self._sort(SELECTION, CURSOR)[0] self.insert(s, char) self.setCursor(s + 1) elif event.type == pygame.MOUSEMOTION: if self.rect.collidepoint(event.pos) and event.buttons[0]: self.setSelection(SELECTION, self._posToIndex(event.pos[0] - self.rect.x)) elif event.type == pygame.MOUSEBUTTONDOWN: if self.rect.collidepoint(event.pos): self.setCursor(self._posToIndex(event.pos[0] - self.rect.x)) super(Entry, self).update(*args)
def handle_event(self, event): ''' Handle input events while the code editor is up. Overrides the code editor version ''' if event.type == pygame.KEYDOWN: self.text_change = True if not self.initial_edit and event.key != pygame.K_RETURN: self.initial_edit = True self.text = "" if event.key == pygame.K_RETURN and self.initial_edit: self.stop() elif event.key == pygame.K_RETURN: pass elif event.key == pygame.K_DELETE: self.k_delete() elif event.key == pygame.K_LEFT: self.k_left() elif event.key == pygame.K_RIGHT: self.k_right() elif event.key == pygame.K_BACKSPACE: self.k_backspace() elif event.key == pygame.K_TAB: pass elif event.key == pygame.K_ESCAPE: pass else: self.character_key(event.key) return True # keep processing events
def handle_event(self, event): ''' Handle input events while the code editor is up ''' if event.type == pygame.KEYDOWN: self.text_change = True if event.key == pygame.K_ESCAPE: self.stop() elif event.key == pygame.K_DELETE: self.k_delete() elif event.key == pygame.K_LEFT: self.k_left() elif event.key == pygame.K_RIGHT: self.k_right() elif event.key == pygame.K_BACKSPACE: self.k_backspace() elif event.key == pygame.K_TAB: self.k_tab() elif event.key == pygame.K_RETURN: self.k_return() elif event.key == pygame.K_UP: self.k_up() elif event.key == pygame.K_DOWN: self.k_down() else: self.character_key(event.key) return True # keep processing events
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()