Python pygame 模块,KEYDOWN 实例源码

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

项目:PyCut    作者:FOSSRIT    | 项目源码 | 文件源码
def ProcessInput(self, events, pressed_keys):
        for event in events:
            if event.type == pygame.KEYDOWN and event.key == pygame.K_RETURN:
                # Move to the next scene when the user pressed Enter
                pass

            if event.type == pygame.MOUSEBUTTONDOWN:
                self.start_button.isClicked(event)
                self.help_button.isClicked(event)
                self.difficulty_button.isClicked(event)

            if event.type == pygame.MOUSEBUTTONUP:
                self.start_button.isClicked(event)
                self.help_button.isClicked(event)
                self.difficulty_button.isClicked(event)

            if event.type == pygame.MOUSEMOTION:
                self.start_button.isHovered(event)
                self.help_button.isHovered(event)
                self.difficulty_button.isHovered(event)
项目:SmartCar    作者:amarlearning    | 项目源码 | 文件源码
def Kaboom(score):
    init()
    gameDisplay.blit(GameOver,(382,175))
    pygame.draw.rect(gameDisplay, white, (200, 400, 550, 50))
    text = smallfont.render("Press [RETURN] to continue and [Q] to quit", True, darkBlue)
    gameDisplay.blit(text, [370,400])
    text = smallfont.render("Score : " + str(score), True, red)
    gameDisplay.blit(text, [450,420])
    pygame.display.update()
    gameExit = True
    while gameExit:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_RETURN:
                    gameExit = False
                    gameloop()
                if event.key == pygame.K_q:
                    pygame.quit()
项目:Projects    作者:it2school    | 项目源码 | 文件源码
def main():
    pygame.init()
    screen = pygame.display.set_mode((500,500))
    screen.fill((255, 0, 0))
    s = pygame.Surface(screen.get_size(), pygame.SRCALPHA, 32)
    pygame.draw.line(s, (0,0,0), (250, 250), (250+200,250))

    width = 1
    for a_radius in range(width):
        radius = 200
        pygame.gfxdraw.aacircle(s, 250, 250, radius-a_radius, (0, 0, 0))

    screen.blit(s, (0, 0))
    pygame.display.flip()
    try:
        while 1:
            event = pygame.event.wait()
            if event.type == pygame.QUIT:
                break
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_ESCAPE or event.unicode == 'q':
                    break
            pygame.display.flip()
    finally:
        pygame.quit()
项目:opseilen    作者:Baal221    | 项目源码 | 文件源码
def program_loop(self):
        while not process_ev.process_events():
            self.update()
            self.draw()

# Handeling pygame events
#def process_events():
#   for event in pygame.event.get():
#       if event.type == pygame.QUIT:
#           return True
#       #elif event.type == pygame.KEYDOWN:
#       #   game.Player1.key_event(event)
#   return False
项目:PyCut    作者:FOSSRIT    | 项目源码 | 文件源码
def ProcessInput(self, events, pressed_keys):
        for event in events:
            if event.type == pygame.KEYDOWN and event.key == pygame.K_RETURN:
                # Move to the next scene when the user pressed Enter
                pass

            if event.type == pygame.MOUSEBUTTONDOWN:
                for button in self.buttons:
                    button.isClicked(event)

            if event.type == pygame.MOUSEBUTTONUP:
                for button in self.buttons:
                    button.isClicked(event)

            if event.type == pygame.MOUSEMOTION:
                for button in self.buttons:
                    button.isHovered(event)
项目:PyCut    作者:FOSSRIT    | 项目源码 | 文件源码
def ProcessInput(self, events, pressed_keys):
        """
        Process Input from user
        Inherited from SceneBase
                Args:   self
                        events - list of pygame events
                        pressed_keys
        """

        for event in events:
            if event.type == pygame.KEYDOWN and event.key == pygame.K_RETURN:
                # Move to the next scene when the user pressed Enter
                pass

            if event.type == pygame.MOUSEBUTTONDOWN:
                self.easy_button.isClicked(event)
                self.adv_button.isClicked(event)

            if event.type == pygame.MOUSEBUTTONUP:
                self.easy_button.isClicked(event)
                self.adv_button.isClicked(event)

            if event.type == pygame.MOUSEMOTION:
                self.easy_button.isHovered(event)
                self.adv_button.isHovered(event)
项目:project_xcape    作者:OthmanEmpire    | 项目源码 | 文件源码
def handleEvent(self, event):
        if self.mode:
            self.mode.handleEvent(event)

        if event.type == pg.KEYDOWN:
            if event.key == pg.K_ESCAPE:
                self.pause = not self.pause
                if self.pause:
                    self.messageScene("pause")
                else:
                    self.messageScene("unpause")

        if event.type == self.SCENE_EVENT:
            if event.category == "start_game":
                if event.data == "solo":
                    self.mode = SinglePlayer(self.screen)
                    self.mode.startGame()
                if event.data == "coop":
                    self.mode = MultiPlayer(self.screen)
                    self.mode.startGame()

            if event.category == "no_mode":
                self.mode = None
            if event.category == "screen":
                self.screen = pg.display.get_surface()
项目:project_xcape    作者:OthmanEmpire    | 项目源码 | 文件源码
def handleEvent(self, event):
        self.collisionEngine.eventHandler(event)
        self.scene.handleEvent(event)

        if event.type == pg.KEYDOWN:
            if event.key == pg.K_RETURN:
                self.camera.duration = 0

        if event.type == self.SCENE_EVENT:
            if event.category == "complete":
                self._nextScene()
            if event.category == "transition":
                self._handleTransition(event)
            if event.category == "death":
                self._handleDeath()
            if event.category == "revive":
                self._handleRevive()

            if event.category == "pause":
                if self.lives != 0:
                    self.pause = True
                    self.messageMenu("transition", "pause_menu")
            if event.category == "unpause":
                self.pause = False
                self._loadUI(self.maxLives, self.lives)
项目:project_xcape    作者:OthmanEmpire    | 项目源码 | 文件源码
def handleEvent(self, event):
        if event.type == pg.KEYDOWN:

            if event.key == pg.K_UP:
                self.arrow.moveUp()
            if event.key == pg.K_DOWN:
                self.arrow.moveDown()

            if event.key == pg.K_RETURN:
                self.audio.state = "enter"
                if self.arrow.index == 0:
                    self.messageMenu("transition", "blank_menu")
                    self.messageCutScene("transition", "office_cutscene")
                if self.arrow.index == 1:
                    self.messageMenu("transition", "blank_menu")
                    self.messageScene("start_game", "coop")
                if self.arrow.index == 2:
                    self.messageMenu("transition", "options_menu")
                if self.arrow.index == 3:
                    quit()
项目: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
项目:LD39    作者:Bobsleigh    | 项目源码 | 文件源码
def notify(self, event):
        if self.isActivated:
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_UP:
                    self.optionList[self.selector.selectedIndex].deselect()
                    self.selector.moveUp()
                    self.scrollUp()
                    self.optionList[self.selector.selectedIndex].select()
                elif event.key == pygame.K_DOWN:
                    self.optionList[self.selector.selectedIndex].deselect()
                    self.selector.moveDown()
                    self.scrollDown()
                    self.optionList[self.selector.selectedIndex].select()
                elif event.key == pygame.K_SPACE:
                    self.chosenOptionIndex = self.selectedIndex()
                    self.isActivated = False
                elif event.key == pygame.K_RETURN:
                    self.chosenOptionIndex = self.selectedIndex()
                    self.isActivated = 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
项目:Circadia    作者:hooyah    | 项目源码 | 文件源码
def getEvent():
    """
    retrieve events from the clock, such as button clicks
    :return (tuple): (string(messageName), messageParam0, ...)
    """

    for event in pygame.event.get():
        if event.type == pygame.QUIT or (event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE):
            return ('end', 0)
        elif event.type == pygame.KEYDOWN and event.key == 257:
            return ('buttonClick', 1)
        elif event.type == pygame.KEYDOWN and event.key == 258:
            return ('buttonClick', 2)
        elif event.type == pygame.KEYDOWN and event.key == 259:
            return ('buttonClick', 4)
        #elif event.type == pygame.KEYDOWN:
        #    print event.key

    return None
项目:pygame-flipclock    作者:prehensile    | 项目源码 | 文件源码
def update( self, dt, fps=8 ):

        self.display_time( dt.hour, dt.minute )    
        pygame.display.flip()

        # handle exits
        was_quit = False
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                was_quit = True
            elif event.type == pygame.KEYDOWN:
                if event.key == pygame.K_ESCAPE:
                    was_quit = True

        if not was_quit:
            self.clock.tick( fps )

        return was_quit
项目:eduActiv8    作者:imiolek-ireneusz    | 项目源码 | 文件源码
def handle(self, event):
        gd.BoardGame.handle(self, event)  # send event handling up
        if self.show_msg == False:
            if event.type == pygame.KEYDOWN and event.key != pygame.K_RETURN:
                lhv = len(self.home_square.value)
                self.changed_since_check = True
                if event.key == pygame.K_BACKSPACE:
                    if lhv > 0:
                        self.home_square.value = self.home_square.value[0:lhv - 1]
                elif not self.board.grid[4][18]:
                    char = event.unicode
                    if len(char) > 0 and lhv < 2 and char in self.digits:
                        self.home_square.value += char
                self.home_square.update_me = True
                self.mainloop.redraw_needed[0] = True
            elif event.type == pygame.MOUSEMOTION and self.drag:
                if self.board.grid[4][18]:
                    self.home_square.value = ""
                    self.home_square.update_me = True
            elif 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)
项目:eduActiv8    作者:imiolek-ireneusz    | 项目源码 | 文件源码
def handle(self, event):
        gd.BoardGame.handle(self, event)  # send event handling up
        if self.show_msg == False:
            if event.type == pygame.KEYDOWN and event.key != pygame.K_RETURN:
                char = event.unicode
                if len(char) > 0:
                    if char == self.middle.value:
                        if len(self.right.value) > 0:
                            self.left.value += char
                            next_letter = self.right.value[0]
                            self.middle.value = next_letter
                            self.right.value = self.right.value[1:]
                            self.kbrd.get_btns_to_hl(next_letter)
                            self.mainloop.sfx.play(15)
                        elif len(self.middle.value) > 0:
                            self.left.value += char
                            self.middle.value = ""
                            self.check_entry()
                        for each in [self.left, self.middle, self.right]:
                            each.update_me = True
                    else:
                        self.mainloop.sfx.play(16)

                self.mainloop.redraw_needed[0] = True
项目:eduActiv8    作者:imiolek-ireneusz    | 项目源码 | 文件源码
def handle(self, event):
        gd.BoardGame.handle(self, event)  # send event handling up
        if self.show_msg == False:
            if event.type == pygame.KEYDOWN and event.key != pygame.K_RETURN:
                char = event.unicode
                if len(char) > 0:
                    if char == self.middle.value:
                        if len(self.right.value) > 0:
                            self.left.value += char
                            next_letter = self.right.value[0]
                            self.middle.value = next_letter
                            self.right.value = self.right.value[1:]
                            self.kbrd.get_btns_to_hl(next_letter)
                            self.mainloop.sfx.play(15)
                        elif len(self.middle.value) > 0:
                            self.left.value += char
                            self.middle.value = ""
                            self.check_entry()
                        for each in [self.left, self.middle, self.right]:
                            each.update_me = True
                    else:
                        self.mainloop.sfx.play(16)

                self.mainloop.redraw_needed[0] = True
项目:eduActiv8    作者:imiolek-ireneusz    | 项目源码 | 文件源码
def handle(self, event):
        gd.BoardGame.handle(self, event)  # send event handling up
        if self.show_msg == False:
            if event.type == pygame.KEYDOWN and event.key != pygame.K_RETURN:
                char = event.unicode
                if len(char) > 0:
                    if char == self.middle.value:
                        if len(self.right.value) > 0:
                            self.left.value += char
                            next_letter = self.right.value[0]
                            self.middle.value = next_letter
                            self.right.value = self.right.value[1:]
                            self.kbrd.get_btns_to_hl(next_letter)
                            self.mainloop.sfx.play(15)
                        elif len(self.middle.value) > 0:
                            self.left.value += char
                            self.middle.value = ""
                            self.check_entry()
                        for each in [self.left, self.middle, self.right]:
                            each.update_me = True
                    else:
                        self.mainloop.sfx.play(16)

                self.mainloop.redraw_needed[0] = True
项目:eduActiv8    作者:imiolek-ireneusz    | 项目源码 | 文件源码
def handle(self, event):
        gd.BoardGame.handle(self, event)  # send event handling up
        if self.show_msg == False:
            if event.type == pygame.KEYDOWN and event.key != pygame.K_RETURN:
                lhv = len(self.home_square.value)
                self.changed_since_check = True
                if event.key == pygame.K_BACKSPACE:
                    if lhv > 0:
                        self.home_square.value = self.home_square.value[0:lhv - 1]
                elif not self.board.grid[4][18]:
                    char = event.unicode
                    if len(char) > 0 and char in self.digits:
                        self.home_square.value = char
                self.home_square.update_me = True
                self.mainloop.redraw_needed[0] = True
            elif event.type == pygame.MOUSEMOTION and self.drag:
                if self.board.grid[4][18]:
                    self.home_square.value = ""
                    self.home_square.update_me = True
            elif 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)
项目:eduActiv8    作者:imiolek-ireneusz    | 项目源码 | 文件源码
def handle(self, event):
        gd.BoardGame.handle(self, event)  # send event handling up
        if self.show_msg == False:
            if event.type == pygame.KEYDOWN and event.key != pygame.K_RETURN:
                lhv = len(self.home_square.value)
                self.changed_since_check = True
                if event.key == pygame.K_BACKSPACE:
                    if lhv > 0:
                        self.home_square.value = self.home_square.value[0:lhv - 1]
                elif not self.board.grid[4][16]:
                    char = event.unicode
                    if len(char) > 0 and char in self.digits:
                        self.home_square.value = char
                self.home_square.update_me = True
                self.mainloop.redraw_needed[0] = True
            elif event.type == pygame.MOUSEMOTION and self.drag:
                if self.board.grid[4][16]:
                    self.home_square.value = ""
                    self.home_square.update_me = True
            elif 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)
项目:eduActiv8    作者:imiolek-ireneusz    | 项目源码 | 文件源码
def handle(self, event):
        gd.BoardGame.handle(self, event)  # send event handling up
        if self.show_msg == False:
            if event.type == pygame.KEYDOWN and event.key != pygame.K_RETURN and not self.correct:
                lhv = len(self.home_square.value)
                self.changed_since_check = True
                if event.key == pygame.K_BACKSPACE:
                    if lhv > 0:
                        self.home_square.value = self.home_square.value[0:lhv - 1]
                else:
                    char = event.unicode
                    if (len(char) > 0 and lhv < 5 and char in self.digits):
                        self.home_square.value += char
                self.home_square.update_me = True
                self.mainloop.redraw_needed[0] = True

            elif event.type == pygame.MOUSEBUTTONUP:
                self.home_square.update_me = True
                if self.board.active_ship == self.home_square.unit_id:
                    self.home_square.perm_outline_width = 5
                    self.home_square = self.ans_h
                    self.board.active_ship = self.home_square.unit_id
                self.home_square.update_me = True
                self.mainloop.redraw_needed[0] = True
项目:eduActiv8    作者:imiolek-ireneusz    | 项目源码 | 文件源码
def handle(self, event):
        gd.BoardGame.handle(self, event)  # send event handling up
        if self.show_msg == False:
            if event.type == pygame.KEYDOWN and event.key != pygame.K_RETURN:
                lhv = len(self.home_square.value)
                self.changed_since_check = True
                if event.key == pygame.K_BACKSPACE:
                    if lhv > 0:
                        self.home_square.value = self.home_square.value[0:lhv - 1]
                else:
                    char = event.unicode
                    if char in self.digits:
                        if len(char) > 0 and lhv < self.max_len:
                            self.home_square.value += char
                        else:
                            self.home_square.value = char
                self.home_square.update_me = True
                self.mainloop.redraw_needed[0] = True
项目:eduActiv8    作者:imiolek-ireneusz    | 项目源码 | 文件源码
def handle(self, event):
        gd.BoardGame.handle(self, event)  # send event handling up
        if self.show_msg == False:
            if event.type == pygame.KEYDOWN and event.key != pygame.K_RETURN:
                lhv = len(self.home_square.value)
                self.changed_since_check = True
                if event.key == pygame.K_BACKSPACE:
                    if lhv > 0:
                        self.home_square.value = self.home_square.value[0:lhv - 1]
                else:
                    char = event.unicode
                    if char in self.digits:
                        if len(char) > 0 and lhv < 3:
                            self.home_square.value += char
                        else:
                            self.home_square.value = char
                self.home_square.update_me = True
                self.mainloop.redraw_needed[0] = True
项目:eduActiv8    作者:imiolek-ireneusz    | 项目源码 | 文件源码
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()
项目:tingbot-gui    作者:furbrain    | 项目源码 | 文件源码
def touch_handler(self, event):
        #handle keypresses...
        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_BACKSPACE:
                self.panel.text.del_letter()
            elif event.key == pygame.K_RETURN or event.key == pygame.K_KP_ENTER:
                self.panel.new_line()
            elif event.key == pygame.K_ESCAPE:
                self.close(None)
            elif event.key == pygame.K_LEFT:
                self.panel.text.cursor_left()
            elif event.key == pygame.K_RIGHT:
                self.panel.text.cursor_right()
            elif len(event.unicode) > 0:
                self.panel.text.add_letter(event.unicode)
        super(Keyboard,self).touch_handler(event)
项目:pyDino    作者:lucaspbordignon    | 项目源码 | 文件源码
def show(self):
        """
        Shows the game over panel.
        """
        self.display.set_screen_caption('Game Over')
        for event in pygame.event.get():
            if (event.type == pygame.KEYDOWN):
                if (event.key == pygame.K_RETURN):
                    return (True, "main_menu", None)
                if (event.key == pygame.K_s):
                    return (True, "save_progress", None)
            if (event.type == pygame.QUIT):
                return (False, '', None)

        self.display.display_single_image(self.resources['game_over_msg'],
                                          self.resources['game_over_pos'])
        self.display.display_single_image(self.resources['game_over_char'],
                                          self.resources['game_over_pos'])
        self.display.display_single_image(self.resources['press_enter'],
                                          self.resources['press_enter_pos'])
        self.display.display_single_image(self.resources['save_msg'],
                                          self.resources['save_msg_pos'])
        return (True, 'game_over', None)
项目: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)
项目:Akkers2Beurs    作者:RensBoeser    | 项目源码 | 文件源码
def Loop(self): # game loop
        while not self.Exit:

            if self.Level == "menu": # loop only goes here if the level is 'menu'
                for event in pygame.event.get(): # checking for any events

                    if event.type == pygame.QUIT: # checks if someone tries to close the window
                        self.Exit = True # stops the while-loop
                    if event.type == pygame.KEYDOWN:
                        if event.key == pygame.K_ESCAPE:
                            self.Exit = True

                self.Draw() # black screen. draw all your things after this line

                grid.Draw()
                player1.Draw()
                player2.Draw()

                self.Tick() # refreshes the window. this is the end of the loop

            # you can use elifs here to make new levels

            else: self.Exit = True # if self.Level is not a valid level, it will terminate the while-loop

### FUNCTION DEFINITIONS ###
项目: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)
项目:Pygame_Functions    作者:StevePaget    | 项目源码 | 文件源码
def textBoxInput(textbox):
    # starts grabbing key inputs, putting into textbox until enter pressed
    global keydict
    textbox.text = ""
    while True:
        updateDisplay()
        for event in pygame.event.get():
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_RETURN:
                    textbox.clear()
                    return textbox.text
                elif event.key == pygame.K_ESCAPE:
                    pygame.quit()
                    sys.exit()
                else:
                    textbox.update(event)
            elif event.type == pygame.QUIT:
                pygame.quit()
                sys.exit()
项目:Pygame_Functions    作者:StevePaget    | 项目源码 | 文件源码
def textBoxInput(textbox):
    # starts grabbing key inputs, putting into textbox until enter pressed
    global keydict
    textbox.text = ""
    while True:
        updateDisplay()
        for event in pygame.event.get():
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_RETURN:
                    textbox.clear()
                    return textbox.text
                elif event.key == pygame.K_ESCAPE:
                    pygame.quit()
                    sys.exit()
                else:
                    textbox.update(event)
            elif event.type == pygame.QUIT:
                pygame.quit()
                sys.exit()
项目:solarwolf    作者:pygame    | 项目源码 | 文件源码
def event(self, e):
        if e.type == pygame.KEYDOWN:
            #What are you doing? Looking for Cheats?
            #shame shame
            if input.Cheatstring == "wheat":
                snd.play('gameover')
                snd.play('delete')
                game.player.cheater = 1
                self.textobjs.append(objtext.Text('"wheat" Cheat: Extra Lives'))
                self.lives_left += 10
                self.hud.drawlives(self.lives_left)
            elif input.Cheatstring == "shred":
                snd.play('gameover')
                snd.play('delete')
                game.player.cheater = 1
                self.grabbedboxes = 0 #less not give any fake complements
                self.levelnum = 49
                self.textobjs.append(objtext.Text('"shred" Cheat: Warp Level 50'))
                self.changestate('levelend')
            if e.key == pygame.K_PAUSE or e.key == pygame.K_p:
                if game.handler is self: #just in case some "help" gets in first?
                    game.handler = gamepause.GamePause(self)
项目:backround-maker    作者:Fooliery887    | 项目源码 | 文件源码
def ask(self,question):
        word=""
        Text(self.game).draw_text2(self.default,question,green,wth//2,50) #example asking name
        pygame.display.flip()
        done = True
        while done:
            for event in pygame.event.get():
                if event.type==pygame.QUIT:
                    pygame.quit()
                    quit()
                if event.type == pygame.KEYDOWN:
                    if event.key == pygame.K_a:
                        word+=str(chr(event.key))
                    if event.key == pygame.K_b:
                        word+=chr(event.key)
                    if event.key == pygame.K_c:
                        word+=chr(event.key)
                    if event.key == pygame.K_d:
                        word+=chr(event.key)
                    if event.key == pygame.K_RETURN:
                        done=False
                    #events...
        return Text(self.game).draw_text2(self.default,word,green,wth//2,100)
项目: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
项目:rapidpythonprogramming    作者:thecount12    | 项目源码 | 文件源码
def splash():
    intro=True
    while intro:
        for event in pygame.event.get():
            if event.type==pygame.QUIT:
                pygame.quit()
                quit()
            if event.type==pygame.KEYDOWN:
                if event.key == pygame.K_c:
                    intro=False
                if event.key==pygame.K_q:
                    pygame.quit()
                    quit()
        display.fill(white)
        message("Wellcome!!!", black,300,300 )
        message("Press 'c' to continue or 'q' to Quit",black,300,400)
        pygame.display.update()
        clock.tick(15)
项目:pool    作者:max-kov    | 项目源码 | 文件源码
def game_over(self, p1_won):
        font = config.get_default_font(config.game_over_label_font_size)
        if p1_won:
            text = "PLAYER 1 WON!"
        else:
            text = "PLAYER 2 WON!"
        rendered_text = font.render(text, False, (255, 255, 255))
        self.canvas.surface.blit(rendered_text, (config.resolution - font.size(text)) / 2)
        pygame.display.flip()
        pygame.event.clear()
        paused = True
        while paused:
            event = pygame.event.wait()
            if event.type == pygame.QUIT or event.type == pygame.KEYDOWN or event.type == pygame.MOUSEBUTTONDOWN:
                paused = False
        self.is_game_over = True
项目:team-brisket-pyweek21    作者:AjaxVM    | 项目源码 | 文件源码
def handleEvents(self, events):
        for event in events:
            if event.type == pygame.QUIT:
                self.doQuit()
                return
            elif event.type == pygame.KEYDOWN:
                if event.key == pygame.K_ESCAPE:
                    self.doQuit()
                    return

                elif event.key == pygame.K_DOWN:
                    self.current_option += 1
                    if self.current_option >= len(self.options):
                        self.current_option = 0
                elif event.key == pygame.K_UP:
                    self.current_option -= 1
                    if self.current_option < 0:
                        self.current_option = len(self.options)-1
                elif event.key == pygame.K_RETURN:
                    self.currentOptionExecute()
                    return
项目:team-brisket-pyweek21    作者:AjaxVM    | 项目源码 | 文件源码
def handleEvents(self, events):
        for event in events:
            if event.type == pygame.QUIT:
                self.game.forceQuit()
                return
            elif event.type == pygame.KEYDOWN:
                log.info('Got Key Event: '+str(event))
                if event.key == pygame.K_ESCAPE:
                    self.backToMenu()
                    return
                elif event.key in settings.CONTROLS:
                    self.doAction(settings.CONTROLS[event.key])
        held_keys = pygame.key.get_pressed()
        for key, action in settings.HELD_CONTROLS.iteritems():
            if held_keys[key]:
                self.doAction(action)
项目:OfMagesAndMagic    作者:munnellg    | 项目源码 | 文件源码
def handle_keypress(self, event):
        if event.type == pygame.KEYDOWN:
            if event.key in self.directions:
                magnitude = self.directions[event.key]
                if magnitude[0] != 0:
                    self.animation = animations.Timeout(
                        self.menu.move_selection,
                        [magnitude[0]]
                    )
                elif magnitude[1] != 0:
                    self.animation = animations.Timeout(
                        self.menu.click_selected,
                        [magnitude[1]]
                    )
        else:
            if event.key in self.directions:
                self.animation = None
项目:OfMagesAndMagic    作者:munnellg    | 项目源码 | 文件源码
def handle_event(self, event):
        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_ESCAPE:
                self.root.trigger_exit_to_main()
            elif event.key == pygame.K_p:
                self.toggle_pause()
            elif not self.paused:
                if event.key == pygame.K_SPACE:
                    self.skip_turn = True
                elif event.key == pygame.K_RETURN:
                    self.skip_game = True
                elif event.key in [pygame.K_LEFT, pygame.K_1]:
                    self.parent.battle.award_victory(1)
                    self.skip_game = True
                elif event.key in [pygame.K_RIGHT, pygame.K_2]:
                    self.parent.battle.award_victory(2)
                    self.skip_game = True
项目:Pygames    作者:christat    | 项目源码 | 文件源码
def pause():
    paused = True

    message_to_screen("PAUSED", red, -100, mfont)
    message_to_screen("Continue - [ESC]/C", white, 0, sfont)
    message_to_screen("Exit - Q", white, 50, sfont)
    pygame.display.update()

    while paused:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()
                quit()
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_c or event.key == pygame.K_ESCAPE:
                    paused = False
                elif event.key == pygame.K_q:
                    pygame.quit()
                    quit()
#        gameDisplay.fill(background)
        clock.tick(5)
项目: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
项目:Projects    作者:it2school    | 项目源码 | 文件源码
def vPlayer( fName ):
    global ovl
    f= open( fName, 'rb' )
    fmt= f.readline().strip()
    res= f.readline().strip()
    col= f.readline().strip()
    if fmt!= "P5":
        print ('Unknown format( len %d ). Exiting...' % len( fmt ))
        return

    w,h= [ int(x) for x in res.split( ' ' ) ]
    h= ( h* 2 )/ 3
    # Read into strings
    y= f.read( w*h )
    u= []
    v= []
    for i in xrange_( 0, h/2 ):
        u.append( f.read( w/2 ))
        v.append( f.read( w/2 ))

    u= ''.join(u)
    v= ''.join(v)

    # Open overlay with the resolution specified
    ovl= pygame.Overlay(pygame.YV12_OVERLAY, (w,h))
    ovl.set_location(0, 0, w, h)

    ovl.display((y,u,v))
    while 1:
        pygame.time.wait(10)
        for ev in pygame.event.get():
            if ev.type in (pygame.KEYDOWN, pygame.QUIT): 
                return
项目: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 ProcessInput(self, events, pressed_keys):
        """
        Process input from user
        Inherits from SceneBase
                Args:   self
                        events - pygame events
                        pressed_keys
        """

        for event in events:
            if event.type == pygame.KEYDOWN and event.key == pygame.K_RETURN:
                # Move to the next scene when the user pressed Enter
                pass

            if event.type == pygame.MOUSEBUTTONDOWN:
                for button in self.buttons:
                    button.isClicked(event)
                if self.leveling_up:
                    self.continue_button.isClicked(event)

            if event.type == pygame.MOUSEBUTTONUP:
                for button in self.buttons:
                    button.isClicked(event)
                if self.leveling_up:
                    self.continue_button.isClicked(event)

            if event.type == pygame.MOUSEMOTION:
                #for button in self.buttons:
                #    button.isHovered(event)
                if self.leveling_up:
                    self.continue_button.isHovered(event)
项目: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