Python pygame 模块,K_ESCAPE 实例源码

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

项目:ToeBot    作者:barkdong123    | 项目源码 | 文件源码
def turn(self):
        global board,whos_turn,n_of_turn

        for event in pygame.event.get():
            if (event.type == pygame.MOUSEBUTTONDOWN):
                mouse_pos = pygame.mouse.get_pos()
                for i in range(3):
                    for j in range(3):
                        if (sqr_pos[i][j][0] < mouse_pos[0] and sqr_pos[i][j][0] + sqr_size[0] > mouse_pos[0] and
                                    sqr_pos[i][j][1] < mouse_pos[1] and sqr_pos[i][j][1] + sqr_size[1] > mouse_pos[
                            1] and board[i*3+j] == NO_ONE):

                            board[i*3+j] = whos_turn
                            n_of_turn += 1
                            who_won(tuple(board) ,whos_turn, n_of_turn)
                            reward_consider(winner,tuple(board),p1,p2)
                            whos_turn = self.ID ^ 1


            elif (event.type == pygame.K_ESCAPE):
                esc_pause()

            if (event.type == pygame.QUIT):
                sys.exit()
                # -------------------------------------------
项目: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()
项目: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()
项目:third_person_im    作者:bstadie    | 项目源码 | 文件源码
def checkEvents(self):
        """
        Check for pygame events (mainly keyboard/mouse events).
        Passes the events onto the GUI also.
        """
        for event in pygame.event.get():
            if event.type == QUIT or (event.type == KEYDOWN and event.key ==
                                      pygame.K_ESCAPE):
                return False
            elif event.type == KEYDOWN:
                self._Keyboard_Event(event.key, down=True)
            elif event.type == KEYUP:
                self._Keyboard_Event(event.key, down=False)
            elif event.type == MOUSEBUTTONDOWN:
                if event.button == 4:
                    self.viewZoom *= 1.1
                elif event.button == 5:
                    self.viewZoom /= 1.1
            elif event.type == MOUSEMOTION:
                if self.rMouseDown:
                    self.viewCenter -= (event.rel[0] /
                                        5.0, -event.rel[1] / 5.0)

        return True
项目:spygame    作者:sven1977    | 项目源码 | 文件源码
def __init__(self, key_list=None):
        """
        :param Union[list,None] key_list: the list of keys to be added right away to our keyboard_registry dict
        """
        super().__init__()

        # stores the keys that we would like to be registered as important
        # - key: pygame keyboard code (e.g. pygame.K_ESCAPE, pygame.K_UP, etc..)
        # - value: True if currently pressed, False otherwise
        # - needs to be ticked in order to yield up-to-date information (this will be done by a GameLoop playing a Screen)
        self.keyboard_registry = {}
        self.descriptions = {}

        if key_list is None:
            key_list = ["up", "down", "left", "right"]
        self.update_keys(key_list)
项目:rllabplusplus    作者:shaneshixiang    | 项目源码 | 文件源码
def checkEvents(self):
        """
        Check for pygame events (mainly keyboard/mouse events).
        Passes the events onto the GUI also.
        """
        for event in pygame.event.get():
            if event.type == QUIT or (event.type == KEYDOWN and event.key ==
                                      pygame.K_ESCAPE):
                return False
            elif event.type == KEYDOWN:
                self._Keyboard_Event(event.key, down=True)
            elif event.type == KEYUP:
                self._Keyboard_Event(event.key, down=False)
            elif event.type == MOUSEBUTTONDOWN:
                if event.button == 4:
                    self.viewZoom *= 1.1
                elif event.button == 5:
                    self.viewZoom /= 1.1
            elif event.type == MOUSEMOTION:
                if self.rMouseDown:
                    self.viewCenter -= (event.rel[0] /
                                        5.0, -event.rel[1] / 5.0)

        return True
项目: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
项目: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)
项目: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 ###
项目: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()
项目: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)
项目: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)
项目:AIFun    作者:Plottel    | 项目源码 | 文件源码
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.gfxdraw.aacircle(s, 250, 250, 200, (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()
项目:PhotoPi    作者:JulienLegrand    | 项目源码 | 文件源码
def ShowPhoto(photoFile):
    screen = pygameEngine.GetScreen()
    image = pygame.image.load(photoFile).convert()
    image = pygame.transform.scale(image, (config.WIDTH,config.HEIGHT))
    screen.blit(image, (0,0))
    pygame.display.update()
    sleep(1)
    pygameEngine.ShowNavButtons()

    i = 0
    while True:
        # get one pygame event
        event = pygame.event.poll()

        # handle events
        # Button 1 = Quit
        if (event.type == pygame.MOUSEBUTTONUP and event.button == 1) or (event.type == pygame.KEYDOWN and event.key == pygame.K_SPACE) or GPIO.input(config.GPIO_NUMBER_BUTTON_1):
            return -1
        # Button 2 = Cycle old photos
        if (event.type == pygame.MOUSEBUTTONUP and event.button == 3) or (event.type == pygame.KEYDOWN and event.key == pygame.K_RETURN) or GPIO.input(config.GPIO_NUMBER_BUTTON_2):
            return 1
        # Button Esc or Q = Quit keys
        if event.type == pygame.KEYDOWN and (event.key == pygame.K_ESCAPE or event.key == pygame.K_q) :
            return -1
项目: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
项目:gail-driver    作者:sisl    | 项目源码 | 文件源码
def checkEvents(self):
        """
        Check for pygame events (mainly keyboard/mouse events).
        Passes the events onto the GUI also.
        """
        for event in pygame.event.get():
            if event.type == QUIT or (event.type == KEYDOWN and event.key ==
                                      pygame.K_ESCAPE):
                return False
            elif event.type == KEYDOWN:
                self._Keyboard_Event(event.key, down=True)
            elif event.type == KEYUP:
                self._Keyboard_Event(event.key, down=False)
            elif event.type == MOUSEBUTTONDOWN:
                if event.button == 4:
                    self.viewZoom *= 1.1
                elif event.button == 5:
                    self.viewZoom /= 1.1
            elif event.type == MOUSEMOTION:
                if self.rMouseDown:
                    self.viewCenter -= (event.rel[0] /
                                        5.0, -event.rel[1] / 5.0)

        return True
项目: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]
项目:Kuai    作者:Duroktar    | 项目源码 | 文件源码
def run(self):
        while not self.is_done:
            time.sleep(0.01)
            x, y = pygame.mouse.get_pos()
            events = pygame.event.get()
            for event in events:
                if event.type == pygame.KEYDOWN:
                    if event.key == pygame.K_UP:
                        Kuai.emit('key-up', x, y)
                    if event.key == pygame.K_DOWN:
                        Kuai.emit('key-down', x, y)
                    if event.key == pygame.K_LEFT:
                        Kuai.emit('key-left', x, y)
                    if event.key == pygame.K_RIGHT:
                        Kuai.emit('key-right', x, y)
                    if event.key == pygame.K_ESCAPE:
                        Kuai.emit('key-escape')
                    pass
项目:pyimgui    作者:swistakm    | 项目源码 | 文件源码
def _map_keys(self):
        key_map = self.io.key_map

        key_map[imgui.KEY_TAB] = pygame.K_TAB
        key_map[imgui.KEY_LEFT_ARROW] = pygame.K_LEFT
        key_map[imgui.KEY_RIGHT_ARROW] = pygame.K_RIGHT
        key_map[imgui.KEY_UP_ARROW] = pygame.K_UP
        key_map[imgui.KEY_DOWN_ARROW] = pygame.K_DOWN
        key_map[imgui.KEY_PAGE_UP] = pygame.K_PAGEUP
        key_map[imgui.KEY_PAGE_DOWN] = pygame.K_PAGEDOWN
        key_map[imgui.KEY_HOME] = pygame.K_HOME
        key_map[imgui.KEY_END] = pygame.K_END
        key_map[imgui.KEY_DELETE] = pygame.K_DELETE
        key_map[imgui.KEY_BACKSPACE] = pygame.K_BACKSPACE
        key_map[imgui.KEY_ENTER] = pygame.K_RETURN
        key_map[imgui.KEY_ESCAPE] = pygame.K_ESCAPE
        key_map[imgui.KEY_A] = pygame.K_a
        key_map[imgui.KEY_C] = pygame.K_c
        key_map[imgui.KEY_V] = pygame.K_v
        key_map[imgui.KEY_X] = pygame.K_x
        key_map[imgui.KEY_Y] = pygame.K_y
        key_map[imgui.KEY_Z] = pygame.K_z
项目:rllab    作者:rll    | 项目源码 | 文件源码
def checkEvents(self):
        """
        Check for pygame events (mainly keyboard/mouse events).
        Passes the events onto the GUI also.
        """
        for event in pygame.event.get():
            if event.type == QUIT or (event.type == KEYDOWN and event.key ==
                                      pygame.K_ESCAPE):
                return False
            elif event.type == KEYDOWN:
                self._Keyboard_Event(event.key, down=True)
            elif event.type == KEYUP:
                self._Keyboard_Event(event.key, down=False)
            elif event.type == MOUSEBUTTONDOWN:
                if event.button == 4:
                    self.viewZoom *= 1.1
                elif event.button == 5:
                    self.viewZoom /= 1.1
            elif event.type == MOUSEMOTION:
                if self.rMouseDown:
                    self.viewCenter -= (event.rel[0] /
                                        5.0, -event.rel[1] / 5.0)

        return True
项目:maml_rl    作者:cbfinn    | 项目源码 | 文件源码
def checkEvents(self):
        """
        Check for pygame events (mainly keyboard/mouse events).
        Passes the events onto the GUI also.
        """
        for event in pygame.event.get():
            if event.type == QUIT or (event.type == KEYDOWN and event.key ==
                                      pygame.K_ESCAPE):
                return False
            elif event.type == KEYDOWN:
                self._Keyboard_Event(event.key, down=True)
            elif event.type == KEYUP:
                self._Keyboard_Event(event.key, down=False)
            elif event.type == MOUSEBUTTONDOWN:
                if event.button == 4:
                    self.viewZoom *= 1.1
                elif event.button == 5:
                    self.viewZoom /= 1.1
            elif event.type == MOUSEMOTION:
                if self.rMouseDown:
                    self.viewCenter -= (event.rel[0] /
                                        5.0, -event.rel[1] / 5.0)

        return True
项目:pyweather    作者:rbischoff    | 项目源码 | 文件源码
def run(self):
        cnt = 0
        self.display_start()

        running = True
        while running:

            pygame.time.wait(1000)
            self.update_diplay()
            cnt += 1
            if cnt >= 209:
                cnt = 0
                self.update_current_data()
            if time.strftime("%d/%m") != self._system_data.current_date:
                self._system_data.current_date = time.strftime("%d/%m")
                self.update_daily_data()
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    running = False
                elif event.type == pygame.KEYDOWN:
                    if event.key == pygame.K_ESCAPE:
                        running = False
        pygame.quit()
项目:ToeBot    作者:barkdong123    | 项目源码 | 文件源码
def esc_pause():
    pausing = True
    while (pausing):
        print("pause")
        for event in pygame.event.get():
            if (event.type == pygame.K_ESCAPE):
                pausing= False
项目:pyclimber    作者:manixaist    | 项目源码 | 文件源码
def check_keydown_events(settings, event, screen, tile_map):
    """Respond to key down events"""
    player = tile_map.player
    if event.key == pygame.K_ESCAPE:
        sys.exit()

    if event.key == pygame.K_a:
        generate_new_random_blob(settings, screen, settings.image_res.enemy_blob_images, tile_map)

    if event.key == pygame.K_r:
        reset_game(tile_map)

    if event.key == pygame.K_LEFT:
        if not player.idle_top:
            if player.dx == 0.0:
                player.dx = -1 * settings.player_dx
                player.facing_left = True

    if event.key == pygame.K_RIGHT:
        if not player.idle_top:
            if player.dx == 0.0:
                player.dx = settings.player_dx
                player.facing_left = False

    if event.key == pygame.K_F9:
        if settings.fullscreen == True:
            settings.fullscreen = False
            pygame.display.set_mode((800, 600))
        else:
            settings.fullscreen = True
            pygame.display.set_mode((800, 600), pygame.FULLSCREEN)
项目:project_xcape    作者:OthmanEmpire    | 项目源码 | 文件源码
def handleEvent(self, event):
        if event.type == pg.KEYDOWN:

            if event.key == pg.K_ESCAPE:
                self.effect.timeStartDarken = self.effect.time
                self.effect.timeEndDarken = self.effect.time + self.dt
                self.audio.state = "exit"

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

            if self.arrow.index == 0:
                if event.key == pg.K_RIGHT:
                    self.backgroundSetting.next()
                if event.key == pg.K_LEFT:
                    self.backgroundSetting.previous()
                if event.key == pg.K_RETURN:
                    if self.backgroundSetting.index == 0:
                        self.render.flip(True, False)
                    if self.backgroundSetting.index == 1:
                        self.render.flip(False, True)

            if self.arrow.index == 1:
                if event.key == pg.K_RIGHT:
                    self.fullscreenSetting.next()
                if event.key == pg.K_LEFT:
                    self.fullscreenSetting.previous()
                if event.key == pg.K_RETURN:
                    if self.fullscreenSetting.index == 0:
                        pg.display.set_mode((settings.WIDTH, settings.HEIGHT))
                    if self.fullscreenSetting.index == 1:
                        pg.display.set_mode((settings.WIDTH, settings.HEIGHT),
                                            pg.FULLSCREEN)

                    self.messageMenu("screen")
                    self.messageScene("screen")
                    self.messageCutScene("screen")
项目:project_xcape    作者:OthmanEmpire    | 项目源码 | 文件源码
def handleEvent(self, event):
        if event.type == pg.KEYDOWN:
            if event.key == pg.K_ESCAPE:
                self.audio.state = "pause"
项目:Galaxian-Against-COMP140    作者:tomjlw    | 项目源码 | 文件源码
def check_keydown_events(event, ai_settings, screen, ship, bullets):
    if event.key == pygame.K_RIGHT:
        ship.moving_right = True
    elif event.key == pygame.K_LEFT:
        ship.moving_left = True
    elif event.key == pygame.K_SPACE:
        fire_bullet(ai_settings, screen, ship, bullets)
    elif event.key == pygame.K_ESCAPE:
        sys.exit()
项目:BusStopPi    作者:LoveBootCaptain    | 项目源码 | 文件源码
def loop():

    update_data()

    running = True

    while running:

        draw_to_tft()

        for event in pygame.event.get():

            if event.type == pygame.QUIT:

                running = False

                quit_all()

            elif event.type == pygame.KEYDOWN:

                if event.key == pygame.K_ESCAPE:

                    running = False

                    quit_all()

                elif event.key == pygame.K_SPACE:

                    print('\nSPACE')

    quit_all()
项目: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)
项目:eduActiv8    作者:imiolek-ireneusz    | 项目源码 | 文件源码
def main():
    # create configuration object
    if android is not None or len(sys.argv) == 1:
        # Map the back button to the escape key.

        if android is not None:
            pygame.init()
            android.init()
            android.map_key(android.KEYCODE_BACK, pygame.K_ESCAPE)
        configo = classes.config.Config(android)

        # create the language object
        lang = classes.lang.Language(configo, path)

        # create the Thread objects and start the threads
        speaker = classes.speaker.Speaker(lang, configo, android)

        app = GamePlay(speaker, lang, configo)
        if android is None:
            speaker.start()
        app.run()
    elif len(sys.argv) == 2:
        if sys.argv[1] == "v" or sys.argv[1] == "version":
            from classes.cversion import ver
            print("eduactiv8-%s" % ver)
    else:
        print("Sorry arguments not recognized.")
项目:pytetris    作者:catalinc    | 项目源码 | 文件源码
def process_input(self):
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                sys.exit()
            if event.type == pygame.KEYDOWN:
                if self.state.paused:
                    if event.key == pygame.K_r:
                        self.state.paused = False
                if self.state.game_over:
                    if event.key == pygame.K_r:
                        self.state = State(self.ROWS, self.COLS)
                    if event.key == pygame.K_ESCAPE:
                        sys.exit()
                if self.state.running:
                    if event.key == pygame.K_DOWN:
                        self.state.move_piece(board.DIRECTION_DOWN)
                    if event.key == pygame.K_LEFT:
                        self.state.move_piece(board.DIRECTION_LEFT)
                    if event.key == pygame.K_RIGHT:
                        self.state.move_piece(board.DIRECTION_RIGHT)
                    if event.key == pygame.K_x:
                        self.state.rotate_piece()
                    if event.key == pygame.K_z:
                        self.state.rotate_piece(True)
                    if event.key == pygame.K_SPACE:
                        self.state.drop_piece()
                    if event.key == pygame.K_p:
                        self.state.paused = True
项目:Pygame_Functions    作者:StevePaget    | 项目源码 | 文件源码
def pause(milliseconds, allowEsc=True):
    keys = pygame.key.get_pressed()
    current_time = pygame.time.get_ticks()
    waittime = current_time + milliseconds
    while not (current_time > waittime or (keys[pygame.K_ESCAPE] and allowEsc)):
        pygame.event.clear()
        keys = pygame.key.get_pressed()
        if (keys[pygame.K_ESCAPE] and allowEsc):
            pygame.quit()
            sys.exit()
        current_time = pygame.time.get_ticks()
项目:Pygame_Functions    作者:StevePaget    | 项目源码 | 文件源码
def endWait():
    print("Press ESC to quit")
    keys = pygame.key.get_pressed()
    current_time = pygame.time.get_ticks()
    waittime = 0
    while not keys[pygame.K_ESCAPE]:
        current_time = pygame.time.get_ticks()
        if current_time > waittime:
            pygame.event.clear()
            keys = pygame.key.get_pressed()
            waittime += 20
    pygame.quit()
项目:Pygame_Functions    作者:StevePaget    | 项目源码 | 文件源码
def updateDisplay():
    global bgSurface
    spriteRects = spriteGroup.draw(screen)
    textboxRects = textboxGroup.draw(screen)
    pygame.display.update()
    keys = pygame.key.get_pressed()
    if (keys[pygame.K_ESCAPE]):
        pygame.quit()
        sys.exit()
    spriteGroup.clear(screen, bgSurface)
    textboxGroup.clear(screen, bgSurface)
项目:Pygame_Functions    作者:StevePaget    | 项目源码 | 文件源码
def pause(milliseconds, allowEsc=True):
    keys = pygame.key.get_pressed()
    current_time = pygame.time.get_ticks()
    waittime = current_time + milliseconds
    while not (current_time > waittime or (keys[pygame.K_ESCAPE] and allowEsc)):
        pygame.event.clear()
        keys = pygame.key.get_pressed()
        if (keys[pygame.K_ESCAPE] and allowEsc):
            pygame.quit()
            sys.exit()
        current_time = pygame.time.get_ticks()
项目:Pygame_Functions    作者:StevePaget    | 项目源码 | 文件源码
def updateDisplay():
    global bgSurface
    spriteRects = spriteGroup.draw(screen)
    textboxRects = textboxGroup.draw(screen)
    pygame.display.update()
    keys = pygame.key.get_pressed()
    if (keys[pygame.K_ESCAPE]):
        pygame.quit()
        sys.exit()
    spriteGroup.clear(screen, bgSurface)
    textboxGroup.clear(screen, bgSurface)
项目:solarwolf    作者:pygame    | 项目源码 | 文件源码
def __pygamebox(title, message):
    try:
        import pygame
        pygame.quit() #clean out anything running
        pygame.display.init()
        pygame.font.init()
        screen = pygame.display.set_mode((460, 140))
        pygame.display.set_caption(title)
        font = pygame.font.Font(None, 18)
        foreg, backg, liteg = (0, 0, 0), (180, 180, 180), (210, 210, 210)
        ok = font.render('Ok', 1, foreg, liteg)
        okbox = ok.get_rect().inflate(200, 10)
        okbox.centerx = screen.get_rect().centerx
        okbox.bottom = screen.get_rect().bottom - 10
        screen.fill(backg)
        screen.fill(liteg, okbox)
        screen.blit(ok, okbox.inflate(-200, -10))
        pos = [10, 10]
        for text in message.split('\n'):
            if text:
                msg = font.render(text, 1, foreg, backg)
                screen.blit(msg, pos)
            pos[1] += font.get_height()
        pygame.display.flip()
        stopkeys = pygame.K_ESCAPE, pygame.K_SPACE, pygame.K_RETURN, pygame.K_KP_ENTER
        while 1:
            e = pygame.event.wait()
            if e.type == pygame.QUIT or \
                       (e.type == pygame.KEYDOWN and e.key in stopkeys) or \
                       (e.type == pygame.MOUSEBUTTONDOWN and okbox.collidepoint(e.pos)):
                break
        pygame.quit()
    except pygame.error:
        raise ImportError
项目:solarwolf    作者:pygame    | 项目源码 | 文件源码
def __pygame(title, message):
    try:
        import pygame, pygame.font
        pygame.quit() #clean out anything running
        pygame.display.init()
        pygame.font.init()
        screen = pygame.display.set_mode((460, 140))
        pygame.display.set_caption(title)
        font = pygame.font.Font(None, 18)
        foreg = 0, 0, 0
        backg = 200, 200, 200
        liteg = 255, 255, 255
        ok = font.render('Ok', 1, foreg)
        screen.fill(backg)
        okbox = ok.get_rect().inflate(20, 10)
        okbox.centerx = screen.get_rect().centerx
        okbox.bottom = screen.get_rect().bottom - 10
        screen.fill(liteg, okbox)
        screen.blit(ok, okbox.inflate(-20, -10))
        pos = [20, 20]
        for text in message.split('\n'):
            msg = font.render(text, 1, foreg)
            screen.blit(msg, pos)
            pos[1] += font.get_height()

        pygame.display.flip()
        while 1:
            e = pygame.event.wait()
            if (e.type == pygame.QUIT or e.type == pygame.MOUSEBUTTONDOWN or
                        pygame.KEYDOWN and e.key
                        in (pygame.K_ESCAPE, pygame.K_SPACE, pygame.K_RETURN)):
                break
        pygame.quit()
    except pygame.error:
        raise ImportError
项目:TicTacTio    作者:DevelopForLizardz    | 项目源码 | 文件源码
def main(self):
        """
        Start the game
        :return: None
        """

        logging.info("Starting game")
        self.board.initUI()
        winner = None

        while not self.exit:
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    self.exit = True
                elif not self.gameOver:
                    currentPlayer = self.players[self.turn]
                    move = currentPlayer.getMove()
                    self.turn = 'x' if self.turn == 'o' else 'o'

                    winner = self.board.checkForWin(move)[0]
                    if winner in ['x', 'o', 't']:
                        logging.info("Game has ended with status: {}".format(winner))
                        self.gameOver = True
                        self.board.displayWinner(self.board.checkForWin(move))
                else:
                    if event.type == pygame.KEYDOWN:
                        if event.key in [pygame.K_RETURN, pygame.K_SPACE]:
                            self.gameOver = False
                            self.board.reset()
                            self.board.initUI()
                    elif event.key in [pygame.K_ESCAPE, pygame.K_DELETE, pygame.K_BACKSPACE]:
                        self.exit = True

            pygame.display.flip()
            self.clock.tick(self.fps)

        self.exit = False
        self.gameOver = False
        self.board.reset()
        return winner
项目:pyweek-game-poor-man-medal-of-honor-game    作者:ReekenX    | 项目源码 | 文件源码
def event_loop(self):
        for event in pg.event.get():
            self.keys = pg.key.get_pressed()
            if event.type == pg.QUIT or self.keys[pg.K_ESCAPE]:
                self.done = True
                self.closed = True
            elif event.type == pg.KEYDOWN and self.keys[pg.K_i]:
                #  import pdb
                #  pdb.set_trace()
                print 'Player at: '
                print self.player.rect
                print self.player.rect.x
                print self.player.rect.y
                print 'Camera at: '
                print self.camera.state
                print 'Painting at: '
                print  [(self.mouse[0], self.mouse[1]), (self.player.rect.centerx + abs(self.camera.state.x), self.player.rect.centery + abs(self.camera.state.y))]
                print 'Angle:'
                print self.angle
            elif event.type == pg.KEYDOWN:
                self.player.add_direction(event.key)
            elif event.type == pg.KEYUP:
                self.player.pop_direction(event.key)

            if event.type == pg.MOUSEBUTTONDOWN and event.button == 1:
                if self.player.bullets_left > 0 and self.player.weapon:
                    self.player_bullets.add(Bullet(self.player.rect.center, self.angle))
                    self.player.bullets_left -= 1
            elif event.type == pg.MOUSEMOTION:
                self.get_angle(event.pos)
项目:pool    作者:max-kov    | 项目源码 | 文件源码
def events():
    closed = False
    quit = False

    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            closed = True
        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_ESCAPE:
                quit = True

    return {"quit_to_main_menu": quit,
            "closed": closed,
            "clicked": pygame.mouse.get_pressed()[0],
            "mouse_pos": np.array(pygame.mouse.get_pos())}
项目:team-brisket-pyweek21    作者:AjaxVM    | 项目源码 | 文件源码
def handleEvents(self):
        #do event stuff
        #basic setup that allows quitting

        for event in pygame.event.get():
            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.game.forceQuit()
                    return
项目: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.game.gotoState('main_menu')
                    return
                elif event.key == pygame.K_RETURN:
                    self.doJoinServer()
                    return
                else:
                    self.ip_entry.handleKey(event.key)
项目:OfMagesAndMagic    作者:munnellg    | 项目源码 | 文件源码
def handle_event(self, event):
        if event.type == pygame.KEYDOWN:
            if event.key in [pygame.K_ESCAPE]:
                self.parent.trigger_exit_to_main()
项目:OfMagesAndMagic    作者:munnellg    | 项目源码 | 文件源码
def __init__(self, main_menu):
        self.parent     = main_menu.parent
        self.main_menu  = main_menu
        self.teams      = self.parent.teams

        self.parent.event_handler.register_key_listener(self.handle_keypress)
        self.title = text_renderer.render_title("Teams", colours.COLOUR_WHITE)
        self.title_position = (
            (self.parent.resolution[0] - self.title.get_width())// 2,
            15
        )

        self.directions = {
            pygame.K_RIGHT     : [1],
            pygame.K_LEFT      : [-1],
            pygame.K_ESCAPE    : [3],
            pygame.K_BACKSPACE : [3]
        }

        self.animation = None

        menu_region = (self.parent.resolution[0],
            600
        )
        self.menu = TeamViewer(menu_region, self.teams)
        self.menu.register_finished_callback(self.finished)