Python pygame 模块,KEYUP 实例源码

我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用pygame.KEYUP

项目:project_xcape    作者:OthmanEmpire    | 项目源码 | 文件源码
def handleEvent(self, _):
        for event in pg.event.get():

            if event.type == pg.QUIT:
                sys.exit()
            if event.type == pg.KEYDOWN:
                if event.key == pg.K_F4:
                    sys.exit()

            if (event.type == self.MENU_EVENT
                    or event.type == pg.KEYDOWN):
                self.menuEngine.handleEvent(event)

            if (event.type == self.SCENE_EVENT
                    or event.type == pg.KEYDOWN
                    or event.type == pg.KEYUP):
                self.sceneEngine.handleEvent(event)

            if (event.type == self.CUTSCENE_EVENT
                    or event.type == pg.KEYDOWN):
                self.cutsceneEngine.handleEvent(event)
项目:Tutoriales_juegos_Python    作者:tidus747    | 项目源码 | 文件源码
def handle_event(self, event):
        if event.type == pygame.QUIT:
            game_over = True

        if event.type == pygame.KEYDOWN:

            if event.key == pygame.K_LEFT:
                self.update('left')
            if event.key == pygame.K_RIGHT:
                self.update('right')
            if event.key == pygame.K_UP:
                self.update('up')
            if event.key == pygame.K_DOWN:
                self.update('down')

        if event.type == pygame.KEYUP:

            if event.key == pygame.K_LEFT:
                self.update('stand_left')
            if event.key == pygame.K_RIGHT:
                self.update('stand_right')
            if event.key == pygame.K_UP:
                self.update('stand_up')
            if event.key == pygame.K_DOWN:
                self.update('stand_down')
项目:Physics-2.0    作者:rschwa6308    | 项目源码 | 文件源码
def handle_events(*args):
    settings_window, camera, scroll, done, dims, screen, bodies, G, COR = args
    for event in pg.event.get():
        if event.type == pg.VIDEORESIZE:
            width, height = event.w, event.h
            dims, screen = V2(width, height), pg.display.set_mode((width, height), pg.RESIZABLE)
        elif event.type == pg.KEYDOWN:
            scroll.key(event.key, 1)
            camera.key_down(event.key)
        elif event.type == pg.KEYUP:
            scroll.key(event.key, 0)
            camera.key_up(event.key)
        elif event.type == pg.MOUSEBUTTONDOWN:
            handle_mouse(settings_window, camera, event, bodies, dims, G, COR, scroll)
        done |= event.type == pg.QUIT
    return done, dims, screen
项目:asteroid-invasion    作者:mally1mk    | 项目源码 | 文件源码
def showscreen():   
    BG()
    draw_text(screen, "asteroid invasion", 50, WIDTH / 2, HEIGHT / 4)
    draw_text(screen, "left and right arrow to move", 20,WIDTH / 2, HEIGHT / 2-12.5)
    draw_text(screen, "press space to shoot", 20,WIDTH / 2, HEIGHT / 2-50)
    draw_text(screen, "if red bar turns green ", 20,WIDTH / 2, HEIGHT / 2+22)
    draw_text(screen, "press arrow up to use sonicshot", 20,WIDTH / 2, HEIGHT / 2+44)
    draw_text(screen,'highscore: '+str(highscore),18,WIDTH/2,400)
    draw_text(screen, "Press up arrow to start", 18, WIDTH / 2, HEIGHT * 3 / 4)
    pygame.display.flip()
    waiting = True
    while waiting:
        clock.tick(FPS)
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                exit()
                pygame.exit()
            if event.type == pygame.KEYUP:
                if event.key == pygame.K_UP:
                    waiting = False
项目:spygame    作者:sven1977    | 项目源码 | 文件源码
def tick(self):
        """
        Pulls all keyboard events from the event queue and processes them according to our keyboard_registry/descriptions.
        Triggers events for all registered keys like: 'key_down.[desc]' (when  pressed) and 'key_up.[desc]' (when released),
        where desc is the lowercase string after `pygame.K_`... (e.g. 'down', 'up', etc..).
        """
        events = pygame.event.get([pygame.KEYDOWN, pygame.KEYUP])
        for e in events:
            # a key was pressed that we are interested in -> set to True or False
            if e.key in self.keyboard_registry:
                if e.type == pygame.KEYDOWN:
                    self.keyboard_registry[e.key] = True
                    self.trigger_event("key_down." + self.descriptions[e.key])
                else:
                    self.keyboard_registry[e.key] = False
                    self.trigger_event("key_up." + self.descriptions[e.key])
项目:Jeff-Long-Run    作者:matthiasrigaud    | 项目源码 | 文件源码
def manager(field):
    put_tile = False
    for event in pygame.event.get():
        if event.type == pygame.QUIT or (event.type == pygame.KEYDOWN and event.dict["key"] == pygame.K_ESCAPE):
            sys.exit()
        elif event.type == pygame.KEYDOWN and (event.dict["key"] == pygame.K_RIGHT or event.dict["key"] == pygame.K_d):
            field.change_right_move(True)
        elif event.type == pygame.KEYUP and (event.dict["key"] == pygame.K_RIGHT or event.dict["key"] == pygame.K_d):
            field.change_right_move(False)
        elif event.type == pygame.KEYDOWN and (event.dict["key"] == pygame.K_LEFT or event.dict["key"] == pygame.K_q):
            field.change_left_move(True)
        elif event.type == pygame.KEYUP and (event.dict["key"] == pygame.K_LEFT or event.dict["key"] == pygame.K_q):
            field.change_left_move(False)
        elif event.type == pygame.MOUSEBUTTONDOWN and event.dict["button"] == 4:
            field.change_tile(1)
        elif event.type == pygame.MOUSEBUTTONDOWN and event.dict["button"] == 5:
            field.change_tile(-1)
        elif event.type == pygame.MOUSEBUTTONDOWN and event.dict["button"] == 1:
            field.put_tile()
项目:Jeff-Long-Run    作者:matthiasrigaud    | 项目源码 | 文件源码
def manager(jeff, field, frame, level_select):
    for event in pygame.event.get():
        if event.type == pygame.QUIT or (event.type == pygame.KEYDOWN and event.dict["key"] == pygame.K_ESCAPE):
            sys.exit()
        elif event.type == pygame.KEYDOWN and jeff.is_dead() and event.dict["key"] == pygame.K_r:
            jeff = Jeff.Jeff([300, Constant.GROUND_HEIGHT - 50])
            field.reload_level()
        elif event.type == pygame.KEYDOWN and (jeff.is_dead() or field.is_level_ended()) and event.dict["key"] == pygame.K_m:
            jeff = Jeff.Jeff([300, Constant.GROUND_HEIGHT - 50])
            frame = "MENU"
        elif event.type == pygame.KEYDOWN and field.is_level_ended() and event.dict["key"] == pygame.K_n:
            next_level = level_select.get_next_level(field.get_level_file())
            if next_level != "":
                jeff = Jeff.Jeff([300, Constant.GROUND_HEIGHT - 50])
                field.load_level(next_level)
        elif event.type == pygame.KEYDOWN and event.dict["key"] == pygame.K_SPACE:
            jeff.jump(True)
        elif event.type == pygame.KEYUP and event.dict["key"] == pygame.K_SPACE:
            jeff.jump(False)
    return jeff, frame
项目:pytari2600    作者:ajgrah2000    | 项目源码 | 文件源码
def test_input(self):
        i = inputs.Input()
        test_inputs = [(pygame.KEYDOWN, {'key':pygame.K_1}),
                       (pygame.KEYDOWN, {'key':pygame.K_2}),
                       (pygame.KEYDOWN, {'key':pygame.K_2}),
                       (pygame.KEYDOWN, {'key':pygame.K_UP}),
                       (pygame.KEYDOWN, {'key':pygame.K_LEFT}),
                       (pygame.KEYUP,   {'key':pygame.K_r}),
#                       (pygame.KEYDOWN, {'key':pygame.K_q})
                       ]
        for e in [pygame.event.Event(*x) for x in test_inputs]:
            i.handle_events(e)

        self.assertEqual(i.get_swcha(),   0xAF)
        self.assertEqual(i.get_swchb(),   0x7F)
        self.assertEqual(i.get_paddle0(),  0x1)
        self.assertEqual(i.get_input7(),  0xFF)
项目:Peppy    作者:project-owner    | 项目源码 | 文件源码
def mouse_action(self, event):
        """ Mouse event handler

        :param event: event to handle
        """
        pos = event.pos

        if self.selected and not(self.last_knob_position < pos[0] < self.last_knob_position + self.knob_width and pos[1] > self.bounding_box.y) and event.type != pygame.KEYUP:
            return

        button_press_simulation = getattr(event, "p", None)

        if event.type == pygame.MOUSEBUTTONUP and self.clicked:
            self.release_action(pos)                
        elif event.type == pygame.MOUSEBUTTONDOWN and self.bounding_box.collidepoint(pos):
            self.press_action()            
        elif event.type == pygame.MOUSEMOTION and (pygame.mouse.get_pressed()[0] or button_press_simulation) and self.bounding_box.collidepoint(pos) and self.clicked:
            self.motion_action(pos)
项目:Peppy    作者:project-owner    | 项目源码 | 文件源码
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)
项目:Pythonlearn    作者:godzoco    | 项目源码 | 文件源码
def check_events(ship):
    """???? 126 ????ship ??ship"""

    #??elif event.type == pygame.KEYDOWN:
    #???? ???? ????? ??
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
                #event.type == pygame.QUIT: ?????????
            sys.exit()
            '''???? ?? 1262?? ???????? ?????
        elif event.type == pygame.KEYDOWN:
            if event.key == pygame.K_RIGHT:
                ship.rect.centerx += 1
            '''
        elif event.type == pygame.KEYDOWN:
            if event.key == pygame.K_RIGHT:
                ship.moving_right = True
        elif event.type == pygame.KEYUP:
            if event.key == pygame.K_RIGHT:
                ship.moving_right = False
项目:Pythonlearn    作者:godzoco    | 项目源码 | 文件源码
def check_events(ship):
    """???? 126 ????ship ??ship"""

    #??elif event.type == pygame.KEYDOWN:
    #???? ???? ????? ??
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
                #event.type == pygame.QUIT: ?????????
            sys.exit()
            '''???? ?? 1262?? ???????? ?????
        elif event.type == pygame.KEYDOWN:
            if event.key == pygame.K_RIGHT:
                ship.rect.centerx += 1
            '''
            #??down ???? ??????????  ??? ??? ??  ? ????? ? ? ????
        elif event.type == pygame.KEYDOWN:
            if event.key == pygame.K_RIGHT:
                ship.moving_right = True
            if event.key == pygame.K_LEFT:
                ship.moving_left = True
        elif event.type == pygame.KEYUP:
            if event.key == pygame.K_RIGHT:
                ship.moving_right = False
            if event.key == pygame.K_LEFT:
                ship.moving_left = False
项目:zeroids-16.2    作者:ProgrammaBol    | 项目源码 | 文件源码
def handle_events():
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()
            sys.exit(0)
        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_UP:
                player_one.speed = 10
            if event.key == pygame.K_RIGHT:
                player_one.angular_speed = 5
            if event.key == pygame.K_LEFT:
                player_one.angular_speed = -5
        if event.type == pygame.KEYUP:
            if event.key == pygame.K_UP:
                player_one.speed = 0
            if event.key == pygame.K_RIGHT:
                player_one.angular_speed = 0
            if event.key == pygame.K_LEFT:
                player_one.angular_speed = 0
项目:Slither    作者:PySlither    | 项目源码 | 文件源码
def runMainLoop(frameFunc):
    while True:
        blit(globalscreen)
        frameFunc()
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                if runQuitCallback():
                    # runQuitCallback would run the function
                    # given to setQuitCallback, and return its result
                    pygame.quit()
                    sys.exit()
            else:
                if event.type == pygame.KEYDOWN:
                    keysPressed.append(pygame.key.name(event.key))
                elif event.type == pygame.KEYUP:
                    keysPressed.remove(pygame.key.name(event.key))
                eventCallbacks[event.type](event)
                # eventCallbacks would be a dictionary mapping
                # event types to handler functions.
        pygame.display.flip() # Always flip at the end
        clock.tick(projectFPS) # Run at however many FPS the user specifies
项目:Snakis    作者:fbessou    | 项目源码 | 文件源码
def read(self):
        inputs = []
        unused_events = []
        while True:
            event = pygame.event.poll()
            if event.type == pygame.NOEVENT:
                break

            keydown = False
            used = False
            if event.type == pygame.KEYDOWN:
                keydown = True
            if event.type == pygame.KEYUP or keydown:
                for player in range(len(self._mapping)):
                    if event.key in self._mapping[player]:
                        inputs.append(PlayerInput(player, self._mapping[player][event.key], keydown))
                        used = True
            if not used:
                unused_events.append(event)

        for event in unused_events:
            pygame.event.post(event)

        return inputs
项目:LovelySpace    作者:lmb753    | 项目源码 | 文件源码
def Refresh(self):
        self.ResetKeys()
        events = pygame.event.get()
        for event in events:
            if(event.type == pygame.KEYDOWN):
                self.CheckInputCache(event.key)
                self.pressed[event.key] = True
                self.keyDown[event.key] = True

                self.instantKey = event.key

            elif(event.type == pygame.KEYUP):
                self.pressed[event.key] = False
                self.keyUp[event.key] = True

            elif(event.type == pygame.MOUSEBUTTONDOWN):
                self.pressed[self.mouseButtons[event.button-1]] = True
                self.btnDown[self.mouseButtons[event.button-1]] = True

            elif(event.type == pygame.MOUSEBUTTONUP):
                self.pressed[self.mouseButtons[event.button-1]] = False
                self.btnUp[self.mouseButtons[event.button-1]] = True
项目:uit-inf-1400-2017.github.io    作者:uit-inf-1400-2017    | 项目源码 | 文件源码
def handle_events(self):
    for event in pygame.event.get():
      if event.type == pygame.QUIT:
    exit()
      elif event.type == pygame.KEYDOWN:
    if event.key == pygame.K_UP:
      self.up_pressed = True
    elif event.key == pygame.K_DOWN:
      self.down_pressed = True
    elif event.key == pygame.K_LEFT:
      self.left_pressed = True
    elif event.key == pygame.K_RIGHT:
      self.right_pressed = True
    elif event.key == pygame.K_ESCAPE:
      exit()
      elif event.type == pygame.KEYUP:
    if event.key == pygame.K_UP:
      self.up_pressed = False
    elif event.key == pygame.K_DOWN:
      self.down_pressed = False
    elif event.key == pygame.K_LEFT:
      self.left_pressed = False
    elif event.key == pygame.K_RIGHT:
      self.right_pressed = False
项目:planet-hopper    作者:reddit-pygame    | 项目源码 | 文件源码
def get_event(self, event):
        if event.type == pg.QUIT:
            self.quit = True
        elif event.type == pg.KEYUP:
            if event.key == pg.K_ESCAPE:
                self.quit = True
            elif event.key == pg.K_SPACE:
                self.running_sim = not self.running_sim
            elif event.key == pg.K_UP:
                if self.tick_index < len(self.tick_lengths) - 1:
                    self.tick_index += 1
                    self.tick_length = self.tick_lengths[self.tick_index]
            elif event.key == pg.K_DOWN:
                if self.tick_index > 0:
                    self.tick_index -= 1
                    self.tick_length = self.tick_lengths[self.tick_index]
项目:alien_invasion    作者:samnew    | 项目源码 | 文件源码
def check_events(ai_settings, screen, stats, sb, play_button, ship, aliens, bullets):
    """?????????"""
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            stats.save_high_score()
            sys.exit()

        elif event.type == pygame.KEYDOWN:
            check_keydown_events(event, ai_settings, screen, stats,sb, ship, aliens, bullets)
        elif event.type == pygame.KEYUP:
            check_keyup_events(event, ship)
        elif event.type == pygame.MOUSEBUTTONDOWN:
            mouse_x, mouse_y = pygame.mouse.get_pos()
            check_play_button(ai_settings, screen, stats, sb, play_button, ship, aliens, bullets, mouse_x, mouse_y)
项目:PyCut    作者:FOSSRIT    | 项目源码 | 文件源码
def _keyup_cb(self, widget, event):
        key = event.keyval
        if self.__repeat[0] is not None:
            if key in self.__held:
                # This is possibly false if set_repeat() is called with a key held
                del self.__held_time_left[key]
                del self.__held_last_time[key]
        self.__held.discard(key)

        return self._keyevent(widget, event, pygame.KEYUP)
项目:PyCut    作者:FOSSRIT    | 项目源码 | 文件源码
def _keyevent(self, widget, event, type):
        key = Gdk.keyval_name(event.keyval)
        if key is None:
            # No idea what this key is.
            return False 

        keycode = None
        if key in self.key_trans:
            keycode = self.key_trans[key]
        elif hasattr(pygame, 'K_'+key.upper()):
            keycode = getattr(pygame, 'K_'+key.upper())
        elif hasattr(pygame, 'K_'+key.lower()):
            keycode = getattr(pygame, 'K_'+key.lower())
        elif key == 'XF86Start':
            # view source request, specially handled...
            self._mainwindow.view_source()
        else:
            print 'Key %s unrecognized' % key

        if keycode is not None:
            if type == pygame.KEYDOWN:
                mod = self._keymods()
            self.__keystate[keycode] = type == pygame.KEYDOWN
            if type == pygame.KEYUP:
                mod = self._keymods()
            ukey = unichr(Gdk.keyval_to_unicode(event.keyval))
            if ukey == '\000':
                ukey = ''
            evt = pygame.event.Event(type, key=keycode, unicode=ukey, mod=mod)
            self._post(evt)

        return True
项目:pyclimber    作者:manixaist    | 项目源码 | 文件源码
def check_events(settings, screen, tile_map):
    """Watch for keyboard and mouse events"""
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            sys.exit()

        elif event.type == pygame.KEYDOWN:
            check_keydown_events(settings, event, screen, tile_map)
        elif event.type == pygame.KEYUP:
            check_keyup_events(settings, event, screen, tile_map)
项目:project_xcape    作者:OthmanEmpire    | 项目源码 | 文件源码
def handleEvent(self, event):
        if event.type == pg.KEYDOWN:
            if event.key == self.keybinds["jump"]:
                self.jump()

        if event.type == pg.KEYUP:
            if event.key == self.keybinds["move_left"]:
                self.stop()
            if event.key == self.keybinds["move_right"]:
                self.stop()
项目:Galaxian-Against-COMP140    作者:tomjlw    | 项目源码 | 文件源码
def check_events(ai_settings, screen, stats, sb, play_button, ship, aliens, bullets):
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            sys.exit()
        elif event.type == pygame.KEYDOWN:
            check_keydown_events(event, ai_settings, screen, ship, bullets)
        elif event.type == pygame.KEYUP:
            check_keyup_events(event, ship)
        elif event.type == pygame.MOUSEBUTTONDOWN:
            mouse_x, mouse_y = pygame.mouse.get_pos()
            check_play_button(ai_settings, screen, stats, sb, play_button, ship, aliens, bullets, mouse_x, mouse_y)
项目:Tuxemon-Server    作者:Tuxemon    | 项目源码 | 文件源码
def process_event(self, event):
        # NOTE: getattr on pygame is a little dangerous. We should sanitize input.
        if self.button and event.type == pygame.KEYUP and event.key == getattr(pygame, self.button):
            self.state = "running"
            self.button = None
            return None

        return event
项目:tensorflow_dqn_supermario    作者:JSDanielPark    | 项目源码 | 文件源码
def event_loop(self, key):
        if key != None and self.keys != key:
            self.keys = key

        else:
            for event in pg.event.get():
                if event.type == pg.QUIT:
                    self.done = True
                elif event.type == pg.KEYDOWN:
                    self.keys = pg.key.get_pressed()
                    self.toggle_show_fps(event.key)
                elif event.type == pg.KEYUP:
                    self.keys = pg.key.get_pressed()
                self.state.get_event(event)
项目:ice-mud-game    作者:PyBargain    | 项目源码 | 文件源码
def handle_key(self, time):
        """
        ??????
        """
        for event in pygame.event.get():
            if event.type == pygame.KEYUP and event.key == pygame.K_ESCAPE: self.stop()
        self.state_changed = self.key_binding.update(lambda key: pygame.key.get_pressed()[key], time, self)
项目:neuroblast    作者:ActiveState    | 项目源码 | 文件源码
def update(self,screen,event_queue,dt,clock, joystick, netmodel, vizmodel):
        nextState = self        
        self.name = gameover.enter_text(event_queue,screen, 8)
        for event in event_queue:
            if event.type == pygame.KEYUP:
                if event.key == pygame.K_RETURN:
                    self.name = gameover.pressed
                    leaderboard.StoreScore(self.name,self.score)
                    nextState = Leaderboard(self.name)                    
        return nextState
项目:python-kinect    作者:jgerschler    | 项目源码 | 文件源码
def run(self):
        self.score = 0
        while not self.finished:
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    self.finished = True
                if event.type == pygame.KEYUP and event.key == pygame.K_SPACE:
                    self.start_ticks = pygame.time.get_ticks()
                    self.new_round()

        self._kinect.close()
        pygame.quit()
项目:python-kinect    作者:jgerschler    | 项目源码 | 文件源码
def run(self):
        self.score = 0
        while not self.finished:
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    self.finished = True
                if event.type == pygame.KEYUP and event.key == pygame.K_SPACE:
                    self.start_ticks = pygame.time.get_ticks()
                    self.new_round()

        self._kinect.close()
        pygame.quit()
项目:eduActiv8    作者:imiolek-ireneusz    | 项目源码 | 文件源码
def handle(self, event):
        gd.BoardGame.handle(self, event)  # send event handling up
        if event.type == pygame.MOUSEBUTTONUP:
            for each in self.board.units:
                if each.is_door is True:
                    self.board.all_sprites_list.move_to_front(each)
            self.check_result()

        if event.type == pygame.KEYDOWN or event.type == pygame.MOUSEBUTTONDOWN:
            self.auto_check_reset()
        elif event.type == pygame.KEYUP:
            self.check_result()
项目:eduActiv8    作者:imiolek-ireneusz    | 项目源码 | 文件源码
def handle(self, event):
        gd.BoardGame.handle(self, event)  # send event handling up
        if self.ship_id < 0 and event.type == pygame.MOUSEBUTTONDOWN:
            # make it impossible to deselect the main character
            self.board.active_ship = 0
            self.ship_id = 0
            if self.moveable == True:
                pos = event.pos
                column = (pos[0] - self.layout.menu_w) // (self.layout.width)
                row = (pos[1] - self.layout.top_margin) // (self.layout.height)
                self.direction = [0, 0]
                arrow_clicked = False
                if column == self.owl_pos[0] - 1 and row == self.owl_pos[1]:
                    self.direction[0] = -1
                    arrow_clicked = True
                elif column == self.owl_pos[0] + 1 and row == self.owl_pos[1]:
                    self.direction[0] = 1
                    arrow_clicked = True
                elif column == self.owl_pos[0] and row == self.owl_pos[1] - 1:
                    self.direction[1] = -1
                    arrow_clicked = True
                elif column == self.owl_pos[0] and row == self.owl_pos[1] + 1:
                    self.direction[1] = 1
                    arrow_clicked = True

                if arrow_clicked:
                    self.check_direction_kdown()
        if (event.type == pygame.KEYDOWN or event.type == pygame.MOUSEBUTTONDOWN) and self.moveable == False:
            self.move = False
        elif event.type == pygame.KEYUP or event.type == pygame.MOUSEBUTTONUP:
            self.highlight_color(-1)
            self.mainloop.redraw_needed[0] = True
            self.move = False
项目:eduActiv8    作者:imiolek-ireneusz    | 项目源码 | 文件源码
def handle(self, event):
        gd.BoardGame.handle(self, event)  # send event handling up
        if event.type == pygame.MOUSEBUTTONUP:
            for each in self.board.units:
                if each.is_door is True:
                    self.board.all_sprites_list.move_to_front(each)
            self.check_result()

        if event.type == pygame.KEYDOWN or event.type == pygame.MOUSEBUTTONDOWN:
            self.auto_check_reset()
        elif event.type == pygame.KEYUP:
            self.check_result()
项目:eduActiv8    作者:imiolek-ireneusz    | 项目源码 | 文件源码
def handle(self, event):
        gd.BoardGame.handle(self, event)  # send event handling up
        if event.type == pygame.MOUSEBUTTONUP:
            for each in self.board.units:
                if each.is_door is True:
                    self.board.all_sprites_list.move_to_front(each)

        if event.type == pygame.KEYDOWN or event.type == pygame.MOUSEBUTTONDOWN:
            self.auto_check_reset()
        elif event.type == pygame.KEYUP or event.type == pygame.MOUSEBUTTONUP:
            self.check_result()
项目:python-fsm    作者:axelhj    | 项目源码 | 文件源码
def putEvent(self, event):

        # keys down
        if event.type == pygame.KEYDOWN \
           and event.key in self.keyToAction:
                self.gameInterface.activateGameAction(self.keyToAction[event.key])
        # keys up
        elif event.type == pygame.KEYUP \
             and event.key in self.keyToAction:
                self.gameInterface.deactivateGameAction(self.keyToAction[event.key])
项目:Peppy    作者:project-owner    | 项目源码 | 文件源码
def user_event_action(self, event):
        """ User event handler

        :param event: the event to handle
        """
        if event.sub_type == SUB_TYPE_KEYBOARD and self.state.keyboard_key == event.keyboard_key:
            if event.action == pygame.KEYDOWN:
                self.press_action()
            elif event.action == pygame.KEYUP:
                self.release_action()
项目:Peppy    作者:project-owner    | 项目源码 | 文件源码
def user_event_action(self, event):
        """ User event dispatcher

        :param event: the event to handle
        """
        key = getattr(self.state, "keyboard_key", None)
        if event.sub_type == SUB_TYPE_KEYBOARD and key and key == event.keyboard_key:
            if event.action == pygame.KEYDOWN:
                self.press_action()
            elif event.action == pygame.KEYUP:
                self.release_action()
项目:Peppy    作者:project-owner    | 项目源码 | 文件源码
def keyboard_action(self, event):
        """  Keyboard event handler 

        :param event: the event to handle
        """
        if event.action == pygame.KEYDOWN:
            self.press_action()
        elif event.action == pygame.KEYUP:
            self.release_action(self.state)
项目:Peppy    作者:project-owner    | 项目源码 | 文件源码
def keyboard_action(self, event):
        """ Keyboard event handler

        :param event: event to handle
        """
        if event.keyboard_key == self.key_knob:
            self.knob_event(event)
            return

        if event.action == pygame.KEYUP:
            self.current_img = self.img_knob
            self.current_filename = self.knob_filename
            self.clicked = False
            self.update_position()
            self.update_knob_image()
            self.notify_slide_listeners()
            return
        elif event.action == pygame.KEYDOWN:
            self.press_action()

        if event.keyboard_key == self.key_incr:
            self.last_knob_position += self.step
        elif event.keyboard_key == self.key_decr:
            self.last_knob_position -= self.step

        if self.img_selected:
            self.current_img = self.img_selected
        else:
            self.current_img = self.img_knob_on
项目:Peppy    作者:project-owner    | 项目源码 | 文件源码
def handle_event(self, event):
        """ Screensaver screen event handler

        :param event: event to handle
        """
        if not self.visible: return

        if event.type == USER_EVENT_TYPE and event.sub_type == SUB_TYPE_KEYBOARD and event.action == pygame.KEYUP:
            if event.keyboard_key == kbd_keys[KEY_UP] or event.keyboard_key == kbd_keys[KEY_DOWN]:
                if self.top_menu_enabled:
                    index = self.saver_menu.get_selected_index()
                    self.top_menu_enabled = False
                    self.delay_menu.unselect()
                    s = len(self.delay_menu.delays)
                    if index > (s - 1):
                        index = s - 1
                    self.delay_menu.select_by_index(index)
                else:
                    index = self.delay_menu.get_selected_index()
                    self.top_menu_enabled = True
                    self.saver_menu.unselect()
                    s = len(self.delay_menu.delays)
                    if index == (s - 1):
                        index = len(self.saver_menu.savers) - 1
                    self.saver_menu.select_by_index(index)
            elif event.keyboard_key == kbd_keys[KEY_HOME]:
                self.home_button.handle_event(event)
            elif event.keyboard_key == kbd_keys[KEY_PLAY_PAUSE]:
                self.player_button.handle_event(event)
            else:
                if self.top_menu_enabled:
                    self.saver_menu.handle_event(event)
                else:
                    self.delay_menu.handle_event(event) 
        else:
            Container.handle_event(self, event)
项目:Peppy    作者:project-owner    | 项目源码 | 文件源码
def handle_event(self, event):
        """ About Screen event handler

        :param evenr: event to hanle
        """
        if not self.visible: return
        mouse_events = [pygame.MOUSEBUTTONUP, pygame.MOUSEBUTTONDOWN]        

        if (event.type in mouse_events) or (event.type == USER_EVENT_TYPE and event.sub_type == SUB_TYPE_KEYBOARD and event.action == pygame.KEYUP):
            self.notify_listeners(None)
项目:Peppy    作者:project-owner    | 项目源码 | 文件源码
def handle_event(self, event):
        """ File menu event handler

        :param event: event to handle
        """
        if not self.visible: return

        if event.type == USER_EVENT_TYPE and event.sub_type == SUB_TYPE_KEYBOARD and event.action == pygame.KEYUP:
            if event.keyboard_key == kbd_keys[KEY_LEFT]:
                if (self.filelist.current_item_index_in_page == 0 and self.filelist.current_item_index != 0) or self.filelist.current_item_index == 0:
                    if self.filelist.length <= self.filelist.items_per_page:
                        self.select_item_on_page(self.filelist.length - 1)
                    else:
                        self.turn_page_left()
                else:
                    self.select_item_on_page(self.filelist.current_item_index - 1) 
            elif event.keyboard_key == kbd_keys[KEY_RIGHT]:
                if self.filelist.current_item_index == self.filelist.length - 1 or self.filelist.current_item_index_in_page == self.filelist.items_per_page - 1:
                    if self.filelist.length <= self.filelist.items_per_page:
                        self.select_item_on_page(0)
                    else:
                        self.turn_page_right()
                else:
                    self.select_item_on_page(self.filelist.current_item_index + 1) 
            elif event.keyboard_key == kbd_keys[KEY_UP] or event.keyboard_key == kbd_keys[KEY_DOWN]:
                Menu.handle_event(self, event)
                self.filelist.set_current_item(self.selected_index)
                self.notify_menu_navigation_listeners(self.empty_state)
            elif event.keyboard_key == kbd_keys[KEY_SELECT]:
                Menu.handle_event(self, event)
        else:
            Menu.handle_event(self, event)
项目:Peppy    作者:project-owner    | 项目源码 | 文件源码
def handle_lirc_event(self, code):
        """ LIRC event handler. 

        To simplify event handling it wraps IR events into user event with keyboard sub-type. 
        For one IR event it generates two events - one for key down and one for key up.

        :param code: IR code
        """
        if self.screensaver_dispatcher.saver_running:
                self.screensaver_dispatcher.cancel_screensaver()
                return        
        d = {}
        d[KEY_SUB_TYPE] = SUB_TYPE_KEYBOARD
        d[KEY_ACTION] = pygame.KEYDOWN
        d[KEY_KEYBOARD_KEY] = None

        try:
            d[KEY_KEYBOARD_KEY] = lirc_keyboard_map[code[0]]
            station_screen = isinstance(self.current_screen, StationScreen)
            file_player_screen = isinstance(self.current_screen, FilePlayerScreen)

            if file_player_screen or (station_screen and self.current_screen.station_menu.current_mode == StationMenu.STATION_MODE):
                if code[0] == "up":
                    d[KEY_KEYBOARD_KEY] = kbd_keys[KEY_VOLUME_UP]
                elif code[0] == "down":
                    d[KEY_KEYBOARD_KEY] = kbd_keys[KEY_VOLUME_DOWN]

            logging.debug("Received IR key: %s", d[KEY_KEYBOARD_KEY])
        except KeyError:
            logging.debug("Received not supported key: %s", code[0])
            pass

        if d[KEY_KEYBOARD_KEY]:
            event = pygame.event.Event(USER_EVENT_TYPE, **d)
            pygame.event.post(event)
            d[KEY_ACTION] = pygame.KEYUP
            event = pygame.event.Event(USER_EVENT_TYPE, **d)
            pygame.event.post(event)
项目:Peppy    作者:project-owner    | 项目源码 | 文件源码
def dispatch(self, player, shutdown):
        """ Dispatch events.  

        Runs the main event loop. Redirects events to corresponding handler.
        Distinguishes four types of events:
        - Quit event - when user closes window (Windows only)
        - Keyboard events
        - Mouse events
        - User Events    

        :param player: reference to player object
        "param shutdown: shutdown method to use when user exits
        """        
        self.player = player
        self.shutdown = shutdown
        mouse_events = [pygame.MOUSEBUTTONDOWN, pygame.MOUSEBUTTONUP, pygame.MOUSEMOTION]
        pygame.event.clear()
        clock = Clock()        

        while self.run_dispatcher:
            for event in pygame.event.get():
                s = str(event)
                logging.debug("Received event: %s", s) 
                if event.type == pygame.QUIT:
                    self.shutdown(event) 
                elif (event.type == pygame.KEYDOWN or event.type == pygame.KEYUP) and not self.config[USAGE][USE_LIRC]:
                    self.handle_keyboard_event(event)                                
                elif event.type in mouse_events or event.type == USER_EVENT_TYPE:
                    self.handle_event(event)                    
            if self.lirc != None:
                code = self.lirc.nextcode()
                if code != None:
                    self.handle_lirc_event(code)
            self.current_screen.refresh()
            self.screensaver_dispatcher.refresh()
            clock.tick(self.frame_rate)
项目:CritterEvolution    作者:apockill    | 项目源码 | 文件源码
def updateKeys(self, event):
        if event.type == pygame.KEYDOWN:
            if event.key == K_r:
                keys["r"] = True
            elif event.key == pygame.K_e:
                keys["e"] = True
            elif event.key == pygame.K_p:
                keys["p"] = True
            elif event.key == pygame.K_n:
                keys["n"] = True

        if event.type == pygame.KEYUP:
            if event.key == pygame.K_r:
                keys["r"] = False
            elif event.key == pygame.K_e:
                keys["e"] = False
            elif event.key == pygame.K_p:
                keys["p"] = False
            elif event.key == pygame.K_n:
                keys["n"] = False

        if event.type == pygame.MOUSEBUTTONDOWN:
            if event.button == 1:  # Left Mouse
                keys["mouseL"] = True
            if event.button == 3:  # Right Mouse
                keys["mouseR"] = True

        if event.type == pygame.MOUSEBUTTONUP:
            if event.button == 1:  # Left Mouse
                keys["mouseL"] = False
            if event.button == 3:  # Right Mouse
                keys["mouseR"] = False

        keys["mousePos"] =  pygame.mouse.get_pos()
项目:myelin-acorn-electron-hardware    作者:google    | 项目源码 | 文件源码
def main(self):
        self.keys_down = []

        print "Opening port"
        self.ser = serial.Serial(guess_port(), timeout=2)

        print "Forwarding key input through to the connected MCU"
        pygame.init()
        pygame.display.set_mode((100, 100))
        while True:
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    pygame.quit()
                    return
                elif event.type == pygame.KEYDOWN:
                    v = scancodes_to_beebcodes.get(event.key, None)
                    if v is not None:
                        print "beebcode %02x" % v
                        if v not in self.keys_down:
                            self.keys_down.append(v)
                            self.send_keys()
                    print("KEYDOWN %s %s" % (
                        event.key,
                        '' if (event.key < 32 or event.key > 127) else '(%s)' % chr(event.key)))
                elif event.type == pygame.KEYUP:
                    print("KEYUP %s" % event.key)
                    v = scancodes_to_beebcodes.get(event.key, None)
                    if v is not None:
                        print "beebcode %02x" % v
                        if v in self.keys_down:
                            while v in self.keys_down:
                                self.keys_down.remove(v)
                            self.send_keys()
项目:backround-maker    作者:Fooliery887    | 项目源码 | 文件源码
def see_thru_pause(self):
        self.running = True
        while self.running:
            for e in pygame.event.get():
                if e.type == pygame.KEYUP:
                    self.running = False
            #pygame.display.flip()
项目:backround-maker    作者:Fooliery887    | 项目源码 | 文件源码
def black_out_pause(self,game):
        while self.running:
            game.screen.fill(black)
            for e in pygame.event.get():
                if e.type == pygame.KEYUP:
                    self.running = False
            pygame.display.flip()
项目:HFOSSFinal    作者:AlanLeeson    | 项目源码 | 文件源码
def _keyup_cb(self, widget, event):
        key = event.keyval
        if self.__repeat[0] is not None:
            if key in self.__held:
                # This is possibly false if set_repeat() is called with a key held
                del self.__held_time_left[key]
                del self.__held_last_time[key]
        self.__held.discard(key)

        return self._keyevent(widget, event, pygame.KEYUP)
项目:HFOSSFinal    作者:AlanLeeson    | 项目源码 | 文件源码
def _keyevent(self, widget, event, type):
        key = Gdk.keyval_name(event.keyval)
        if key is None:
            # No idea what this key is.
            return False 

        keycode = None
        if key in self.key_trans:
            keycode = self.key_trans[key]
        elif hasattr(pygame, 'K_'+key.upper()):
            keycode = getattr(pygame, 'K_'+key.upper())
        elif hasattr(pygame, 'K_'+key.lower()):
            keycode = getattr(pygame, 'K_'+key.lower())
        elif key == 'XF86Start':
            # view source request, specially handled...
            self._mainwindow.view_source()
        else:
            print 'Key %s unrecognized' % key

        if keycode is not None:
            if type == pygame.KEYDOWN:
                mod = self._keymods()
            self.__keystate[keycode] = type == pygame.KEYDOWN
            if type == pygame.KEYUP:
                mod = self._keymods()
            ukey = unichr(Gdk.keyval_to_unicode(event.keyval))
            if ukey == '\000':
                ukey = ''
            evt = pygame.event.Event(type, key=keycode, unicode=ukey, mod=mod)
            self._post(evt)

        return True