本文整理汇总了Python中pygame.KEYUP属性的典型用法代码示例。如果您正苦于以下问题:Python pygame.KEYUP属性的具体用法?Python pygame.KEYUP怎么用?Python pygame.KEYUP使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类pygame
的用法示例。
在下文中一共展示了pygame.KEYUP属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: show_go_screen
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import KEYUP [as 别名]
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
示例2: handleEvents
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import KEYUP [as 别名]
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)
示例3: handleEvents
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import KEYUP [as 别名]
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)
示例4: handle_continuous_action_event
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import KEYUP [as 别名]
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)
示例5: reader_thread
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import KEYUP [as 别名]
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
示例6: parse_events
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import KEYUP [as 别名]
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
示例7: check_key_pressed_valid
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import KEYUP [as 别名]
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
示例8: check_events
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import KEYUP [as 别名]
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)
示例9: dispatch_event
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import KEYUP [as 别名]
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
示例10: handle_event
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import KEYUP [as 别名]
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')
示例11: show_go_screen
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import KEYUP [as 别名]
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
示例12: update
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import KEYUP [as 别名]
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
示例13: readline
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import KEYUP [as 别名]
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)
示例14: preFocus
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import KEYUP [as 别名]
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)
示例15: run_visualizer_control_loop
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import KEYUP [as 别名]
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))