Python pygame.KEYUP Examples

The following are 30 code examples of pygame.KEYUP(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module pygame , or try the search function .
Example #1
Source File: Input.py    From three.py with MIT License 7 votes vote down vote up
def update(self):
        self.keyDownList = []
        self.keyUpList   = []
        self.mouseButtonDown = False
        self.mouseButtonUp   = False
        self.windowResize    = False
        for event in pygame.event.get(): # checks input events (discrete)
            if event.type == pygame.KEYDOWN:
                self.keyDownList.append( event.key )
                self.keyPressedList.append( event.key )
            elif event.type == pygame.KEYUP:
                self.keyPressedList.remove( event.key )
                self.keyUpList.append( event.key )
            elif event.type == pygame.MOUSEBUTTONDOWN:
                self.mouseButtonDown = True
                self.mouseButtonPressed = True
            elif event.type == pygame.MOUSEBUTTONUP:
                self.mouseButtonPressed = False
                self.mouseButtonUp = True
            elif event.type == pygame.QUIT:
                self.quitStatus = True
            elif event.type == pygame.VIDEORESIZE:
                self.windowResize = True
                self.windowWidth = event.w
                self.windowHeight = event.h 
Example #2
Source File: shmup-14.py    From pygame_tutorials with MIT License 6 votes vote down vote up
def show_go_screen():
    screen.blit(background, background_rect)
    draw_text(screen, "SHMUP!", 64, WIDTH / 2, HEIGHT / 4)
    draw_text(screen, "Arrow keys move, Space to fire", 22,
              WIDTH / 2, HEIGHT / 2)
    draw_text(screen, "Press a key to begin", 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:
                pygame.quit()
            if event.type == pygame.KEYUP:
                waiting = False

# Load all game graphics 
Example #3
Source File: shmup.py    From pygame_tutorials with MIT License 6 votes vote down vote up
def show_go_screen():
    screen.blit(background, background_rect)
    draw_text(screen, "SHMUP!", 64, WIDTH / 2, HEIGHT / 4)
    draw_text(screen, "Arrow keys move, Space to fire", 22,
              WIDTH / 2, HEIGHT / 2)
    draw_text(screen, "Press a key to begin", 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:
                pygame.quit()
            if event.type == pygame.KEYUP:
                waiting = False

# Load all game graphics 
Example #4
Source File: ConfigMenu.py    From PyMenu with GNU General Public License v3.0 6 votes vote down vote up
def handleEvents(self, events):
        if(self.subComponent != None):
            self.subComponent.handleEvents(events)          
            return

        if(self.overlay != None):
            self.overlay.handleEvents(events)           
            return

        for event in events:    
            if event.type == pygame.KEYDOWN:
                if event.key == Keys.DINGOO_BUTTON_Y:                  
                    self.toggleSidebar(True)
            if event.type == pygame.KEYUP:         
                if event.key == Keys.DINGOO_BUTTON_START:  
                    self.originalTarget.update(self.optionTarget)

                    self.callback(self.originalTarget)
                    RenderControl.setDirty()
                  

        if(self.overlay == None and self.subComponent == None):
            AbstractList.AbstractList.handleEvents(self,events) 
Example #5
Source File: SelectionList.py    From PyMenu with GNU General Public License v3.0 6 votes vote down vote up
def handleEvents(self, events):
        if(self.subComponent != None):
            self.subComponent.handleEvents(events)          
            return


        if(self.overlay != None):
            self.overlay.handleEvents(events)            
            return

        for event in events:    
            if event.type == pygame.KEYDOWN:  
                if event.key == Keys.DINGOO_BUTTON_SELECT:
                    pass
               
            if event.type == pygame.KEYUP:         
                if event.key == Keys.DINGOO_BUTTON_START:
                   self.callback(self.data)
                   return

        if(self.overlay is None):
            AbstractList.AbstractList.handleEvents(self, events) 
Example #6
Source File: graphics.py    From highway-env with MIT License 6 votes vote down vote up
def handle_continuous_action_event(cls, action_type: ContinuousAction, event: pygame.event.EventType) -> None:
        action = action_type.last_action.copy()
        steering_index = action_type.space().shape[0] - 1
        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_RIGHT and action_type.lateral:
                action[steering_index] = 0.7
            if event.key == pygame.K_LEFT and action_type.lateral:
                action[steering_index] = -0.7
            if event.key == pygame.K_DOWN and action_type.longitudinal:
                action[0] = -0.7
            if event.key == pygame.K_UP and action_type.longitudinal:
                action[0] = 0.7
        elif event.type == pygame.KEYUP:
            if event.key == pygame.K_RIGHT and action_type.lateral:
                action[steering_index] = 0
            if event.key == pygame.K_LEFT and action_type.lateral:
                action[steering_index] = 0
            if event.key == pygame.K_DOWN and action_type.longitudinal:
                action[0] = 0
            if event.key == pygame.K_UP and action_type.longitudinal:
                action[0] = 0
        action_type.act(action) 
Example #7
Source File: io_keyboard.py    From foos with GNU General Public License v3.0 6 votes vote down vote up
def reader_thread(self):
        # Only allow keyboard events
        pygame.event.set_allowed(None)
        pygame.event.set_allowed([pygame.KEYDOWN, pygame.KEYUP])

        while True:
            e = pygame.event.wait()
            code = e.scancode

            if code in self.key_map:
                btn = self.key_map[code]
                state = "down" if e.type == pygame.KEYDOWN else "up"
                event_data = {'source': 'keyboard', 'btn': btn, 'state': state}
                self.bus.notify('button_event', event_data)

            if code in self.goal_map and e.type == pygame.KEYDOWN:
                team = self.goal_map[code]
                self.bus.notify('goal_event', {'source': 'keyboard', 'team': team})

            if code == 60:  # PERIOD
                self.bus.notify('quit')
                return 
Example #8
Source File: carla08interface.py    From coiltraine with MIT License 6 votes vote down vote up
def parse_events(self, world, clock):
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                return True
            elif event.type == pygame.KEYUP:
                if self._is_quit_shortcut(event.key):
                    return True
                elif event.key == K_BACKSPACE:
                    world.restart()
                elif event.key == K_F1:
                    world.hud.toggle_info()
                elif event.key == K_h or (
                        event.key == K_SLASH and pygame.key.get_mods() & KMOD_SHIFT):
                    world.hud.help.toggle()
                elif event.key == K_LEFT:
                    self._command_cache = 3.0
                elif event.key == K_RIGHT:
                    self._command_cache = 4.0
                elif event.key == K_DOWN:
                    self._command_cache = 2.0
                elif event.key == K_UP:
                    self._command_cache = 5.0

        world._command_cache = self._command_cache 
Example #9
Source File: carla09interface.py    From coiltraine with MIT License 6 votes vote down vote up
def parse_events(self, world, clock):
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                return True
            elif event.type == pygame.KEYUP:
                if self._is_quit_shortcut(event.key):
                    return True
                elif event.key == K_BACKSPACE:
                    world.restart()
                elif event.key == K_F1:
                    world.hud.toggle_info()
                elif event.key == K_h or (
                        event.key == K_SLASH and pygame.key.get_mods() & KMOD_SHIFT):
                    world.hud.help.toggle()
                elif event.key == K_LEFT:
                    self._command_cache = 3.0
                elif event.key == K_RIGHT:
                    self._command_cache = 4.0
                elif event.key == K_DOWN:
                    self._command_cache = 2.0
                elif event.key == K_UP:
                    self._command_cache = 5.0

        world._command_cache = self._command_cache 
Example #10
Source File: utils.py    From pygame-menu with MIT License 6 votes vote down vote up
def check_key_pressed_valid(event):
    """
    Checks if the pressed key is valid.
    :param event: Key press event
    :type event: :py:class:`pygame.event.Event`
    :return: True if a key is pressed
    :rtype: bool
    """
    # If the system detects that any key event has been pressed but
    # there's not any key pressed then this method raises a KEYUP
    # flag
    bad_event = not (True in pygame.key.get_pressed())
    if bad_event:
        if 'test' in event.dict and event.dict['test']:
            return True
        ev = pygame.event.Event(pygame.KEYUP, {'key': event.key})
        pygame.event.post(ev)
    return not bad_event 
Example #11
Source File: game_functions.py    From alien-invasion-game with MIT License 6 votes vote down vote up
def check_events(ai_settings: Settings, stats: GameStats, game_items: GameItems):
    """Respond to keypresses and mouse events."""

    # Watch for keyboard and mouse events.
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            quit_game(stats)

        elif event.type == pygame.KEYDOWN:
            check_keydown_events(event, ai_settings, stats, game_items)

        elif event.type == pygame.KEYUP:
            check_keyup_events(event, game_items.ship)

        elif event.type == pygame.MOUSEBUTTONDOWN:
            check_mousedown_events(ai_settings, stats, game_items) 
Example #12
Source File: game.py    From wasabi2d with GNU Lesser General Public License v3.0 6 votes vote down vote up
def dispatch_event(self, event):
        if event.type == pygame.QUIT:
            sys.exit(0)
        if event.type == pygame.KEYDOWN:
            self.keyboard._press(event.key)
            if event.key == pygame.K_q and event.mod & self.CTRL_ALT:
                sys.exit(0)
            elif event.key == pygame.K_F12:
                video = event.mod & self.SHIFT
                event = ScreenShotEvent(ScreenShotEvent, video)
        elif event.type == pygame.KEYUP:
            self.keyboard._release(event.key)

        handler = self.handlers.get(event.type)
        if handler:
            handler(event)
            return True
        return False 
Example #13
Source File: player.py    From Tutoriales_juegos_Python with GNU General Public License v3.0 6 votes vote down vote up
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') 
Example #14
Source File: fiveinrow-v-final.py    From pygame-development with MIT License 6 votes vote down vote up
def show_go_screen(surf, winner=None):
    note_height = 10
    if winner is not None:
        draw_text(surf, 'You {0} !'.format('win!' if winner == USER else 'lose!'),
                  64, WIDTH // 2, note_height, RED)
    else:
        screen.blit(background, back_rect)

    draw_text(surf, 'Five in row', 64, WIDTH // 2, note_height + HEIGHT // 4, BLACK)
    draw_text(surf, 'Press any key to start', 22, WIDTH // 2, note_height + HEIGHT // 2,
              BLUE)
    pygame.display.flip()
    waiting = True

    while waiting:
        clock.tick(FPS)
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()
            elif event.type == pygame.KEYUP:
                waiting = False 
Example #15
Source File: debugConsole.py    From universalSmashSystem with GNU General Public License v3.0 6 votes vote down vote up
def readline(self):
        clock = pygame.time.Clock()
        inputObj = pygcurse.PygcurseInput(self.pyg_surface)
        self.pyg_surface.inputcursor = inputObj.startx, inputObj.starty

        while True: # the event loop
            self.pyg_surface._inputcursormode = inputObj.insertMode and 'insert' or 'underline'

            for event in pygame.event.get((pygame.KEYDOWN, pygame.KEYUP, pygame.QUIT)): # TODO - handle holding down the keys
                if event.type == pygame.QUIT:
                    sys.exit()
                elif event.type in (pygame.KEYDOWN, pygame.KEYUP):
                    inputObj.sendkeyevent(event)
                    if inputObj.done:
                        return ''.join(inputObj.buffer)

            inputObj.update()
            self.display()

            clock.tick(60) 
Example #16
Source File: panel.py    From universalSmashSystem with GNU General Public License v3.0 6 votes vote down vote up
def preFocus(self, _event):
        if _event.type in [pygame.KEYUP, pygame.KEYDOWN]:
            focus_index = self.children.index(self.focused)
            if _event.type == pygame.KEYUP and _event.key == pygame.key.K_RETURN:
                focus_index = (focus_index+1)%len(self.children)
            elif _event.type == pygame.KEYDOWN and _event.key == pygame.key.K_UP:
                if focus_index > 0: focus_index -= 1
            elif _event.type == pygame.KEYDOWN and _event.key == pygame.key.K_DOWN:
                if focus_index <= len(self.children): focus_index += 1
            elif _event.type == pygame.KEYDOWN and _event.key == pygame.key.K_PAGEUP:
                focus_index = min(0, focus_index-5)
            elif _event.type == pygame.KEYDOWN and _event.key == pygame.key.K_PAGEDOWN:
                focus_index = max(focus_index+5, len(self.children)-1)
            elif _event.type == pygame.KEYDOWN and _event.key == pygame.key.K_HOME:
                focus_index = 0
            elif _event.type == pygame.KEYDOWN and _event.key == pygame.key.K_END:
                focus_index = len(self.children)-1
            elif _event.type == pygame.KEYDOWN and _event.key == pygame.key.K_ESCAPE:
                self.focused = None
                return False
            self.focused = self.children[focus_index]
            return True
        else: return panel.preFocus(self, _event) 
Example #17
Source File: utils.py    From pylot with Apache License 2.0 6 votes vote down vote up
def run_visualizer_control_loop(control_display_stream):
    """Runs a pygame loop that waits for user commands.

    The user commands are send on the control_display_stream
    to control the pygame visualization window.
    """
    import erdos
    import pygame
    clock = pygame.time.Clock()
    from pygame.locals import K_n
    while True:
        clock.tick_busy_loop(60)
        events = pygame.event.get()
        for event in events:
            if event.type == pygame.KEYUP:
                if event.key == K_n:
                    control_display_stream.send(
                        erdos.Message(erdos.Timestamp(coordinates=[0]),
                                      event.key)) 
Example #18
Source File: main.py    From python-examples with MIT License 6 votes vote down vote up
def handle_event(self, event):
        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_LEFT:
                self.turn_left = True
            elif event.key == pygame.K_RIGHT:
                self.turn_right = True
            elif event.key == pygame.K_UP:
                self.move_forward = True
            elif event.key == pygame.K_DOWN:
                self.move_backward = True
            
        elif event.type == pygame.KEYUP:
            if event.key == pygame.K_LEFT:
                self.turn_left = False
            elif event.key == pygame.K_RIGHT:
                self.turn_right = False
            elif event.key == pygame.K_UP:
                self.move_forward = False
            elif event.key == pygame.K_DOWN:
                self.move_backward = False 
Example #19
Source File: example-2.py    From python-examples with MIT License 6 votes vote down vote up
def handle_event(self, event):

        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_LEFT:
                self.move_x -= self.speed
            elif event.key == pygame.K_RIGHT:
                self.move_x += self.speed
            elif event.key == pygame.K_UP:
                self.move_y -= self.speed
            elif event.key == pygame.K_DOWN:
                self.move_y += self.speed
            
        elif event.type == pygame.KEYUP:
            if event.key == pygame.K_LEFT:
                self.move_x += self.speed
            elif event.key == pygame.K_RIGHT:
                self.move_x -= self.speed
            elif event.key == pygame.K_UP:
                self.move_y += self.speed
            elif event.key == pygame.K_DOWN:
                self.move_y -= self.speed 
Example #20
Source File: example-1.py    From python-examples with MIT License 6 votes vote down vote up
def handle_event(self, event):

        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_LEFT:
                self.move_x -= self.speed
            elif event.key == pygame.K_RIGHT:
                self.move_x += self.speed
            elif event.key == pygame.K_UP:
                self.move_y -= self.speed
            elif event.key == pygame.K_DOWN:
                self.move_y += self.speed
            
        elif event.type == pygame.KEYUP:
            if event.key == pygame.K_LEFT:
                self.move_x += self.speed
            elif event.key == pygame.K_RIGHT:
                self.move_x -= self.speed
            elif event.key == pygame.K_UP:
                self.move_y += self.speed
            elif event.key == pygame.K_DOWN:
                self.move_y -= self.speed 
Example #21
Source File: main_1.py    From python-examples with MIT License 6 votes vote down vote up
def event_handler(self, event):
        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_LEFT:
                self.move_x -= self.speed_x
            elif event.key == pygame.K_RIGHT:
                self.move_x += self.speed_x
            elif event.key == pygame.K_UP:
                self.move_y -= self.speed_y
            elif event.key == pygame.K_DOWN:
                self.move_y += self.speed_y

        elif event.type == pygame.KEYUP:
            if event.key == pygame.K_LEFT:
                self.move_x += self.speed_x
            elif event.key == pygame.K_RIGHT:
                self.move_x -= self.speed_x
            elif event.key == pygame.K_UP:
                self.move_y += self.speed_y
            elif event.key == pygame.K_DOWN:
                self.move_y -= self.speed_y 
Example #22
Source File: main_3.py    From python-examples with MIT License 6 votes vote down vote up
def event_handler(self, event):
        if self.keyboard:
            if event.type == pygame.KEYDOWN:
                if event.key == self.keyboard['left']:
                    self.move_x -= self.speed_x
                elif event.key == self.keyboard['right']:
                    self.move_x += self.speed_x
                elif event.key == self.keyboard['up']:
                    self.move_y -= self.speed_y
                elif event.key == self.keyboard['down']:
                    self.move_y += self.speed_y
     
            elif event.type == pygame.KEYUP:
                if event.key == self.keyboard['left']:
                    self.move_x += self.speed_x
                elif event.key == self.keyboard['right']:
                    self.move_x -= self.speed_x
                elif event.key == self.keyboard['up']:
                    self.move_y += self.speed_y
                elif event.key == self.keyboard['down']:
                    self.move_y -= self.speed_y 
Example #23
Source File: main_2.py    From python-examples with MIT License 6 votes vote down vote up
def event_handler(self, event):
        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_LEFT:
                self.move_x -= self.speed_x
            elif event.key == pygame.K_RIGHT:
                self.move_x += self.speed_x
            elif event.key == pygame.K_UP:
                self.move_y -= self.speed_y
            elif event.key == pygame.K_DOWN:
                self.move_y += self.speed_y
 
        elif event.type == pygame.KEYUP:
            if event.key == pygame.K_LEFT:
                self.move_x += self.speed_x
            elif event.key == pygame.K_RIGHT:
                self.move_x -= self.speed_x
            elif event.key == pygame.K_UP:
                self.move_y += self.speed_y
            elif event.key == pygame.K_DOWN:
                self.move_y -= self.speed_y 
Example #24
Source File: tank.py    From Jtyoui with MIT License 5 votes vote down vote up
def get_event(self):
        global SCREEN_WIDTH, SCREEN_HEIGHT
        event_list = pygame.event.get()
        for event in event_list:
            if event.type == pygame.VIDEORESIZE:
                SCREEN_WIDTH, SCREEN_HEIGHT = event.size
                self.window = self.display.set_mode([SCREEN_WIDTH, SCREEN_HEIGHT], pygame.RESIZABLE, 32)

            if event.type == pygame.QUIT:
                self.end_game()
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_w:
                    self.my_tank.direction = U
                elif event.key == pygame.K_s:
                    self.my_tank.direction = D
                elif event.key == pygame.K_a:
                    self.my_tank.direction = L
                elif event.key == pygame.K_d:
                    self.my_tank.direction = R
                else:
                    return None
                self.my_tank.move_stop = False
            elif event.type == pygame.MOUSEBUTTONDOWN:
                if len(TankGame.my_bullet_list) < 3:
                    bullet = self.my_tank.fire()
                    load_music('fire')
                    TankGame.my_bullet_list.append(bullet)
            elif event.type == pygame.KEYUP:
                self.my_tank.move_stop = True 
Example #25
Source File: main.py    From pygame_tutorials with MIT License 5 votes vote down vote up
def wait_for_key(self):
        waiting = True
        while waiting:
            self.clock.tick(FPS)
            for event in pg.event.get():
                if event.type == pg.QUIT:
                    waiting = False
                    self.running = False
                if event.type == pg.KEYUP:
                    waiting = False 
Example #26
Source File: main.py    From pygame_tutorials with MIT License 5 votes vote down vote up
def events(self):
        # Game Loop - events
        for event in pg.event.get():
            # check for closing window
            if event.type == pg.QUIT:
                if self.playing:
                    self.playing = False
                self.running = False
            if event.type == pg.KEYDOWN:
                if event.key == pg.K_SPACE:
                    self.player.jump()
            if event.type == pg.KEYUP:
                if event.key == pg.K_SPACE:
                    self.player.jump_cut() 
Example #27
Source File: main.py    From pygame_tutorials with MIT License 5 votes vote down vote up
def wait_for_key(self):
        waiting = True
        while waiting:
            self.clock.tick(FPS)
            for event in pg.event.get():
                if event.type == pg.QUIT:
                    waiting = False
                    self.running = False
                if event.type == pg.KEYUP:
                    waiting = False 
Example #28
Source File: main.py    From pygame_tutorials with MIT License 5 votes vote down vote up
def events(self):
        # Game Loop - events
        for event in pg.event.get():
            # check for closing window
            if event.type == pg.QUIT:
                if self.playing:
                    self.playing = False
                self.running = False
            if event.type == pg.KEYDOWN:
                if event.key == pg.K_SPACE:
                    self.player.jump()
            if event.type == pg.KEYUP:
                if event.key == pg.K_SPACE:
                    self.player.jump_cut() 
Example #29
Source File: main.py    From pygame_tutorials with MIT License 5 votes vote down vote up
def wait_for_key(self):
        waiting = True
        while waiting:
            self.clock.tick(FPS)
            for event in pg.event.get():
                if event.type == pg.QUIT:
                    waiting = False
                    self.running = False
                if event.type == pg.KEYUP:
                    waiting = False 
Example #30
Source File: main.py    From pygame_tutorials with MIT License 5 votes vote down vote up
def wait_for_key(self):
        waiting = True
        while waiting:
            self.clock.tick(FPS)
            for event in pg.event.get():
                if event.type == pg.QUIT:
                    waiting = False
                    self.running = False
                if event.type == pg.KEYUP:
                    waiting = False