我们从Python开源项目中,提取了以下19个代码示例,用于说明如何使用pygame.K_LCTRL。
def __init__(self, gameInstance): BaseController.__init__(self, gameInstance) keys = ( \ pygame.K_LEFT, #left pygame.K_RIGHT,#right pygame.K_UP, #acc pygame.K_DOWN, #brake pygame.K_LCTRL,#reverse pygame.K_r, #restart #pygame.K_ESC, #endGame pygame.K_RCTRL, #pygame.K_SPACE, \ ) self.keyToAction = dict() for key, action in zip(keys, self.gameInterface.gameInstance.actionsList): self.keyToAction.update({key: action}) self.keyToAction[pygame.K_RCTRL] = self.keyToAction[pygame.K_LCTRL]
def handle_keyboard_event(self, event): """ Keyboard event handler. Wraps keyboard events into user event. Exits upon Ctrl-C. Distinguishes key up and key down. :param event: event to handle """ keys = pygame.key.get_pressed() if (keys[pygame.K_LCTRL] or keys[pygame.K_RCTRL]) and event.key == pygame.K_c: self.shutdown(event) elif event.type == pygame.KEYDOWN or event.type == pygame.KEYUP: if self.screensaver_dispatcher.saver_running: self.screensaver_dispatcher.cancel_screensaver() return self.handle_event(event) d = {} d[KEY_SUB_TYPE] = SUB_TYPE_KEYBOARD d[KEY_ACTION] = event.type d[KEY_KEYBOARD_KEY] = event.key event = pygame.event.Event(USER_EVENT_TYPE, **d) pygame.event.post(event)
def process_events(self): keys = pygame.key.get_pressed() self.B1 = Button(self.width * 0.88, self.height * 0.04, self.width * 0.1, self.height * 0.07, I5) self.M1 = Menu(self.width, self.height, I0) for event in pygame.event.get(): if event.type == VIDEORESIZE: self.screen = pygame.display.set_mode(event.dict['size'], HWSURFACE | DOUBLEBUF | RESIZABLE) self.width = event.dict['size'][0] self.height = event.dict['size'][1] if event.type == pygame.QUIT: return True if keys[pygame.K_LCTRL] and keys[pygame.K_w]: return True if event.type == pygame.MOUSEBUTTONUP: if self.B1.rect.collidepoint(pygame.mouse.get_pos()) and self.S0[1] == 1: self.S0 = [1, 0] if self.M1.B1.rect.collidepoint(pygame.mouse.get_pos()) and self.S0[0] == 1: self.S0 = [0, 1] if self.M1.B4.rect.collidepoint(pygame.mouse.get_pos()) and self.S0[0] == 1: return True return False
def Refresh(self): self.screen.fill((255,255,255)) self.App.Refresh() pygame.display.update() if not pygame.key.get_pressed()[pygame.K_LCTRL]: self.flag = False if not pygame.key.get_pressed()[pygame.K_LCTRL]: self.flag = False if pygame.key.get_pressed()[pygame.K_LCTRL] and pygame.key.get_pressed()[pygame.K_s] and not self.flag: self.flag = True name = str( time.time() )+ ".png" pygame.image.save(self.screen , str( time.time() )+ ".png") print "screenshot ",name," saved" if pygame.key.get_pressed()[ pygame.K_F11 ] and not self.lastpresssed: self.lastpresssed = True if self.fullscreen == 0: self.screen = pygame.display.set_mode((SCREEN_WIDTH,SCREEN_HEIGHT),pygame.FULLSCREEN) self.fullscreen = 1 else: self.fullscreen = 0 self.screen = pygame.display.set_mode((SCREEN_WIDTH,SCREEN_HEIGHT)) if not pygame.key.get_pressed()[pygame.K_F11]: self.lastpresssed = False
def process_events(self): keys = pygame.key.get_pressed() self.B1 = Button(self.width * 0.88, self.height * 0.04, self.width * 0.1, self.height * 0.07, I4) self.M1 = Menu(self.width, self.height, I0) for event in pygame.event.get(): if event.type == VIDEORESIZE: self.screen = pygame.display.set_mode(event.dict['size'], HWSURFACE | DOUBLEBUF | RESIZABLE) self.width = event.dict['size'][0] self.height = event.dict['size'][1] if event.type == pygame.QUIT: return True if keys[pygame.K_LCTRL] and keys[pygame.K_w]: return True if event.type == pygame.MOUSEBUTTONUP: if self.B1.rect.collidepoint(pygame.mouse.get_pos()) and self.S1 == 1: self.S0 = 1 self.S1 = 0 if self.M1.B1.rect.collidepoint(pygame.mouse.get_pos()) and self.S0 == 1: self.S0 = 0 self.S1 = 1 if self.M1.B4.rect.collidepoint(pygame.mouse.get_pos()) and self.S0 == 1: return True return False
def process_events(self): keys = pygame.key.get_pressed() self.B1 = Button(self.width * 0.88, self.height * 0.04, self.width * 0.1, self.height * 0.07, I5) self.B2 = Button(self.width * 0.88, self.height * 0.04, self.width * 0.1, self.height * 0.07, I5) self.B3 = Button(self.width * 0.88, self.height * 0.04, self.width * 0.1, self.height * 0.07, I5) self.M1 = Menu(self.width, self.height, I0) for event in pygame.event.get(): if event.type == VIDEORESIZE: self.screen = pygame.display.set_mode(event.dict['size'], HWSURFACE | DOUBLEBUF | RESIZABLE) self.width = event.dict['size'][0] self.height = event.dict['size'][1] if event.type == pygame.QUIT: return True if keys[pygame.K_LCTRL] and keys[pygame.K_w]: return True if keys[pygame.K_LALT] and keys[pygame.K_F4]: return True if keys[pygame.K_ESCAPE]: if self.S0[1] == 1 or self.S0[2] == 1 or self.S0[3] == 1: self.S0 = [1, 0, 0, 0] if event.type == pygame.MOUSEBUTTONUP: if self.B1.rect.collidepoint(pygame.mouse.get_pos()) and self.S0[1] == 1: self.S0 = [1, 0, 0, 0] if self.B2.rect.collidepoint(pygame.mouse.get_pos()) and self.S0[2] == 1: self.S0 = [1, 0, 0, 0] if self.B3.rect.collidepoint(pygame.mouse.get_pos()) and self.S0[3] == 1: self.S0 = [1, 0, 0, 0] if self.M1.B1.rect.collidepoint(pygame.mouse.get_pos()) and self.S0[0] == 1: self.S0 = [0, 1, 0, 0] if self.M1.B2.rect.collidepoint(pygame.mouse.get_pos()) and self.S0[0] == 1: self.S0 = [0, 0, 1, 0] if self.M1.B3.rect.collidepoint(pygame.mouse.get_pos()) and self.S0[0] == 1: self.S0 = [0, 0, 0, 1] if self.M1.B4.rect.collidepoint(pygame.mouse.get_pos()) and self.S0[0] == 1: return True return False
def run(self): # while no other GUI elements are visible or not in battle while this.drawing & (not (this.text_box_visible | this.text_menu_visible | this.inbattle)): pygame.event.pump() event = pygame.event.poll() if event.type == pygame.KEYDOWN: # get keys pressed using pygame.key.get_pressed() as it is more continous than events. if event.key == pygame.K_LCTRL: # seperate hide and show buttons as they would counteract eachother. self.player_menu.show() elif event.key == pygame.K_z: self.activate() elif event.key == pygame.K_f: # quick testing key to find if the battles work has to be with a background # where Lucidia Bright is present. battle(self, this.onscreen_sprites["Lucida Bright"]) pygame.time.delay(5) keys = pygame.key.get_pressed() if keys[pygame.K_UP]: self.facing("backward") self.move(0, -1) elif keys[pygame.K_DOWN]: self.facing("forward") self.move(0, 1) elif keys[pygame.K_LEFT]: self.facing("left") self.move(-1, 0) elif keys[pygame.K_RIGHT]: self.facing("right") self.move(1, 0)
def zoom(self, rel, amount): if self.cds.check("zoom"): if pygame.key.get_pressed()[pygame.K_LCTRL]: amount = [amount[0]*4, amount[1]*4] xtilepos = (self.offset[0] + rel[0]) / self.tilemap.tile_width ytilepos = (self.offset[1] + rel[1]) / self.tilemap.tile_height self.tilemap.setTileSize(self.tilemap.tile_width + amount[0], self.tilemap.tile_height + amount[1]) self.offset[0] = (xtilepos * self.tilemap.tile_width) - rel[0] self.offset[1] = (ytilepos * self.tilemap.tile_height) - rel[1] self.change = True self.cds.start()
def scroll(self, amount): if pygame.key.get_pressed()[pygame.K_LCTRL]: amount = amount * 4 self.offset = min((main.tilemap.im.iconAmount()-1)*self.tile_height, max(0, self.offset + amount))
def scroll(self, amount): if pygame.key.get_pressed()[pygame.K_LCTRL]: amount = amount * 4 self.offset = min((main.tilemap.im.iconIdAmount(main.paint[0])-1)*self.tile_height, max(0, self.offset + amount))
def left_click(self, button, event, down): if down == True: mod = 3 if pygame.key.get_pressed()[pygame.K_LCTRL]: mod = 5 if self.left: propbox.offset[0] = max(0, propbox.offset[0] + (self.direction*mod)) else: propbox.offset[2] = max(0, propbox.offset[2] + (self.direction*mod)) propbox.render()
def scroll_up(self, button, event, down): mod = 2 if pygame.key.get_pressed()[pygame.K_LCTRL]: mod = 6 self.offset[1] = max(0, self.offset[1] - mod) self.render()
def Refresh(self): self.screen.fill((255,255,255)) self.App.Refresh() pygame.display.update() if not pygame.key.get_pressed()[pygame.K_LCTRL]: self.flag = False if not pygame.key.get_pressed()[pygame.K_LCTRL]: self.flag = False if pygame.key.get_pressed()[pygame.K_LCTRL] and pygame.key.get_pressed()[pygame.K_s] and not self.flag: self.flag = True name = str( time.time() )+ ".png" pygame.image.save(self.screen , str( time.time() )+ ".png") print "screenshot ",name," saved"
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 process_events(self): keys = pygame.key.get_pressed() self.B1 = Button(self.width * 0.88, self.height * 0.04, self.width * 0.1, self.height * 0.07, I5) self.B2 = Button(self.width * 0.88, self.height * 0.04, self.width * 0.1, self.height * 0.07, I5) self.B3 = Button(self.width * 0.88, self.height * 0.04, self.width * 0.1, self.height * 0.07, I5) self.H1 = Button(self.width * 0.88, self.height * 0.84, self.width * 0.1, self.height * 0.07, I6) self.H2 = Button(self.width * 0.77, self.height * 0.84, self.width * 0.1, self.height * 0.07, I7) self.M1 = Menu(self.width, self.height, I0) self.screen_rect = self.screen.get_rect() for event in pygame.event.get(): if event.type == VIDEORESIZE: self.screen = pygame.display.set_mode(event.dict['size'], HWSURFACE | DOUBLEBUF | RESIZABLE) self.width = event.dict['size'][0] self.height = event.dict['size'][1] if event.type == pygame.QUIT: return True if keys[pygame.K_LCTRL] and keys[pygame.K_w]: return True if keys[pygame.K_LALT] and keys[pygame.K_F4]: return True if keys[pygame.K_ESCAPE]: if self.S0[1] == 1 or self.S0[2] == 1 or self.S0[3] == 1: self.S0 = [1, 0, 0, 0] if keys[pygame.K_r]: self.D1 self.D1 = Dice(self.width * 0.5, self.height * 0.5, self.width * 0.1, self.width * 0.1) if event.type == pygame.MOUSEBUTTONDOWN and event.button == 1 and self.D1.rc == 0: self.D1.check_click(event.pos) if event.type == pygame.MOUSEBUTTONUP and event.button == 1: self.D1.click = False if self.D1.rc == 1: self.D1.rc = 2 if self.D1.rc == 3 and self.D1.vcc < 30: self.D1.rc = 0 self.D1.vcc = 0 if self.B1.rect.collidepoint(pygame.mouse.get_pos()) and self.S0[1] == 1: self.S0 = [1, 0, 0, 0] if self.B2.rect.collidepoint(pygame.mouse.get_pos()) and self.S0[2] == 1: self.S0 = [1, 0, 0, 0] if self.H1.rect.collidepoint(pygame.mouse.get_pos()) and self.S0[2] == 1: self.S0 = [1, 0, 0, 0] if self.H2.rect.collidepoint(pygame.mouse.get_pos()) and self.S0[2] == 1: self.S0 = [1, 0, 0, 0] if self.B3.rect.collidepoint(pygame.mouse.get_pos()) and self.S0[3] == 1: self.S0 = [1, 0, 0, 0] if self.M1.B1.rect.collidepoint(pygame.mouse.get_pos()) and self.S0[0] == 1: self.S0 = [0, 1, 0, 0] if self.M1.B2.rect.collidepoint(pygame.mouse.get_pos()) and self.S0[0] == 1: self.S0 = [0, 0, 1, 0] if self.M1.B3.rect.collidepoint(pygame.mouse.get_pos()) and self.S0[0] == 1: self.S0 = [0, 0, 0, 1] if self.M1.B4.rect.collidepoint(pygame.mouse.get_pos()) and self.S0[0] == 1: return True return False
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