本文整理汇总了Python中pygame.mouse.get_pressed函数的典型用法代码示例。如果您正苦于以下问题:Python get_pressed函数的具体用法?Python get_pressed怎么用?Python get_pressed使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_pressed函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: input
def input(self, event):
self.x_speed = 0.0
self.y_speed = 0.0
x, y = mouse.get_pos()
if event.type == MOUSEBUTTONDOWN and event.button == MOUSE.MIDDLE:
self.x_first = x
self.y_first = y
elif event.type == MOUSEBUTTONUP and event.button == MOUSE.MIDDLE:
self.x_first = None
self.y_first = None
elif event.type == MOUSEMOTION and mouse.get_pressed()[1] and \
self.x_first and self.y_first:
self.x_delta = x - self.x_first
self.y_delta = y - self.y_first
else:
if mouse.get_focused():
if x > self.w - self.scroll_width and x < self.w:
self.x_speed = self.speed
elif x < self.scroll_width:
self.x_speed = -self.speed
if y > self.h - self.scroll_width:
self.y_speed = self.speed
elif y < self.scroll_width:
self.y_speed = -self.speed
if key.get_focused():
if key.get_pressed()[K_RIGHT]:
self.x_speed = self.speed
elif key.get_pressed()[K_LEFT]:
self.x_speed = -self.speed
if key.get_pressed()[K_DOWN]:
self.y_speed = self.speed
elif key.get_pressed()[K_UP]:
self.y_speed = -self.speed
示例2: getPressed
def getPressed(self, getTime=False):
"""Returns a 3-item list indicating whether or not buttons 0,1,2
are currently pressed.
If `getTime=True` (False by default) then `getPressed` will
return all buttons that have been pressed since the last call
to `mouse.clickReset` as well as their time stamps::
buttons = mouse.getPressed()
buttons, times = mouse.getPressed(getTime=True)
Typically you want to call :ref:`mouse.clickReset()` at stimulus
onset, then after the button is pressed in reaction to it, the
total time elapsed from the last reset to click is in mouseTimes.
This is the actual RT, regardless of when the call to `getPressed()`
was made.
"""
global mouseButtons, mouseTimes
if usePygame:
return mouse.get_pressed()
else:
# False: # havePyglet: # like in getKeys - pump the events
# for each (pyglet) window, dispatch its events before checking
# event buffer
defDisplay = pyglet.window.get_platform().get_default_display()
for win in defDisplay.get_windows():
win.dispatch_events() # pump events on pyglet windows
# else:
if not getTime:
return copy.copy(mouseButtons)
else:
return copy.copy(mouseButtons), copy.copy(mouseTimes)
示例3: update
def update(self):
"""
function that checks if the button was clicked and draws the button
"""
if mouse.get_pressed()[0]:
self.click()
self.draw(util.enums.SCREEN)
示例4: input
def input(self, event, next_state):
next_state = super(Editor, self).input(event, next_state)
self.camera.input(event)
if event.type == KEYDOWN:
if event.key == K_ESCAPE:
self.tilemgr.save_tiles("map1.map")
next_state = set_next_state(next_state, STATES.MENU)
elif event.type == MOUSEBUTTONDOWN:
if event.button == MOUSE.LEFT:
self.set_tile()
elif event.button == MOUSE.RIGHT:
self.get_tile()
elif event.button == MOUSE.WHEELUP:
self.current_tile -= 1
if self.current_tile < 0:
self.current_tile = self.tilemgr.total_tile_kinds - 1
elif event.button == MOUSE.WHEELDOWN:
self.current_tile += 1
if self.current_tile > self.tilemgr.total_tile_kinds - 1:
self.current_tile = 0
elif event.type == MOUSEMOTION and mouse.get_pressed()[0]:
self.set_tile()
return next_state
示例5: update
def update(self, event):
MouseOver = self.getMouseOver()
if MouseOver == True:
if event.type == pl.MOUSEBUTTONDOWN and mouse.get_pressed()[0]:
self.image = self.button_frame[3]
else:
self.image = self.button_frame[1]
else:
self.image = self.button_frame[0]
return MouseOver
示例6: handle_input
def handle_input(self, game, event):
mouse_buttons = mouse.get_pressed()
if event.type == QUIT:
# Exit if the quit button is pressed
game.exit()
if event.type == KEYUP:
# Check for a keyboard button coming up
if event.key == K_ESCAPE:
# The escape key
self.game.state = MenuState(self.game, self.ui_config)
if event.type == MOUSEMOTION:
# Check for mouse movement
# Check the right button on moused pressed
if mouse_buttons[2]:
self.game_map.move_surface(event)
self.mouse_movement(event)
if event.type == MOUSEBUTTONUP:
# Check for a mouse click
moused_butt = self.interface.get_moused_button()
if moused_butt:
moused_butt.left_clicked()
if event.type == MOUSEBUTTONDOWN:
# Check for mouse button down
if event.button == 4:
# Mouse wheel up
self.game_map.zoom_in()
self.game_map.render()
if event.button == 5:
# Mouse wheel down
self.game_map.zoom_out()
print self.game_map.zoom
self.game_map.render()
return False
示例7: handle_mouse_events
def handle_mouse_events(self):
"""
- Creates obstacles on left clicks
- Removes obstacles on right clicks
"""
pressed = mouse.get_pressed()
x, y = mouse.get_pos()
size = self.settings["cell_size"]
cell = self.world[(x/size, y/size)]
if pressed[0]:
cell.make_obstacle()
elif pressed[2]:
if cell.is_obstacle():
cell.remove_obstacle()
示例8: poll
def poll(self, pos):
if self._images[0].get_rect().collidepoint(pos):
event.get()
pressed = mouse.get_pressed()[0]
else:
pressed = False
changed = False
if self._pressed != pressed:
self._pressed = pressed
changed = True
if self._pressed:
self._down()
return changed
示例9: updateControls
def updateControls(self):
bools = key.get_pressed()
self.up = bools[pygame.K_UP] or bools[pygame.K_w]
self.down = bools[pygame.K_DOWN] or bools[pygame.K_s]
self.left = bools[pygame.K_LEFT] or bools[pygame.K_a]
self.right = bools[pygame.K_RIGHT] or bools[pygame.K_d]
self.w = bools[pygame.K_w]
self.s = bools[pygame.K_s]
self.a = bools[pygame.K_a]
self.d = bools[pygame.K_d]
self.f = bools[pygame.K_f]
self.p[0] = bools[pygame.K_p]
m = mouse.get_pressed()
self.mClicked = m[0]
self.mloc = mouse.get_pos()
self.space = bools[pygame.K_SPACE] or bools[pygame.K_RETURN]
self.one[0] = bools[pygame.K_1]
示例10: input_mouse
def input_mouse(self, event):
x, y = mouse.get_pos()
x += self.camera.rect.x
y += self.camera.rect.y
if event.type == MOUSEMOTION and mouse.get_pressed()[0]:
self.mouse_rect.x = min(self.x_first, x)
self.mouse_rect.w = abs(self.x_first - x)
self.mouse_rect.y = min(self.y_first, y)
self.mouse_rect.h = abs(self.y_first - y)
if event.type == MOUSEBUTTONDOWN and event.button == MOUSE.LEFT:
self.mouse_rect.x = x
self.mouse_rect.y = y
self.mouse_rect.w = 0
self.mouse_rect.h = 0
self.x_first = x
self.y_first = y
示例11: _foo
def _foo(e):
global _Clic,_Ticks,_Inactiv,_ButtonTick
if e.type==NOEVENT:
_Inactiv+=_NoEvent_Clock.tick()
if _Inactiv>=ButtonDelay and _Inactiv>=_ButtonTick:
_ButtonTick+=ButtonRepeat
e.dict.update({'inactiv':_Inactiv,'repeat_buttons':mouse.get_pressed(),'mouse_pos':mouse.get_pos()})
else:
e.dict.update({'inactiv':_Inactiv,'repeat_buttons':[0,0,0,0,0],'mouse_pos':mouse.get_pos()})
else:
_Inactiv = 0
_ButtonTick = ButtonDelay
if e.type==MOUSEBUTTONDOWN:
if _Ticks[e.button].tick()>LAPS or e.button!=_Clic[0]: _Clic=[e.button,0,0,0,0,0]
elif e.type==MOUSEBUTTONUP:
if _Ticks[e.button].tick()>LAPS: _Clic=[e.button,0,0,0,0,0]
else:
_Clic[e.button]+=1
e.dict.update({'click':_Clic})
示例12: update
def update(self):
"""
Get User input and propagate to childs
"""
mousebut = mouse.get_pressed()
mouse.b1, mouse.b2, mouse.b3 = mousebut
# If focused, run mouse callbacks
topmost = self.findTopMost(mouse.get_pos())
if topmost == self:
if self.onMouseMove:
self.onMouseMove(mouse.get_pos(), mousebut)
if mousebut[0] and not self.mousedown[0] and self.onMouseDown:
self.onMouseDown(mouse.get_pos(), 1)
elif not mousebut[1] and self.mousedown[0] and self.onClick:
self.onClick(mouse.get_pos(), mousebut)
self.mousedown[0] = mousebut[0]
if mousebut[1] and not self.mousedown[1] and self.onMouseDown:
self.onMouseDown(mouse.get_pos(), 2)
self.mousedown[1] = mousebut[1]
if mousebut[2] and not self.mousedown[2] and self.onMouseDown:
self.onMouseDown(mouse.get_pos(), 3)
self.mousedown[2] = mousebut[2]
# Change focus onClick
if mousebut[0]:
if self.focused and self.focused != self:
if topmost != self.focused.parent:
if hasattr(self.focused, 'lostFocus'):
self.focused.lostFocus()
self.focused = topmost
else:
self.focused = topmost
topmost = None
CContainer.update(self, topmost)
示例13: _reaction_time
def _reaction_time(self):
if self.current_state_key == STATE_PRESSED:
if get_pressed()[0]:
self.father._drag_element.shift(-parameters.CLICK_LIFT_REPEAT)
示例14: main
def main():
makeCave()
map(spawnEnemy(), range(5))
player.setPos((5,5))
player.movement=PathMove(player, [])
player.setColor((0,255,0))
while True:
for event in pygame.event.get():
if event.type == QUIT:
return
elif event.type == KEYDOWN:
if event.key == K_ESCAPE:
return
elif event.key == K_SPACE:
world.randomize()
elif event.key == K_RETURN:
world.reset()
# elif event.key == K_LEFT:
# player.move(LEFT)
# elif event.key == K_RIGHT:
# player.move(RIGHT)
# elif event.key == K_UP:
# player.move(UP)
# elif event.key == K_DOWN:
# player.move(DOWN)
elif event.type == MOUSEBUTTONDOWN:
if event.button==LEFT:
1
elif event.button==RIGHT:
target=camera.getWorld(pygame.mouse.get_pos())
path=aStarPath(player.getPos(), target)
player.movement.setPath(path)
# elif event.type == MOUSEBUTTONUP:
#screen.blit(background, (0, 0))
if mouse.get_pressed()[2]:
world.getTile(camera.getWorld(pygame.mouse.get_pos())).setType("Ground")
if mouse.get_pressed()[0]:
mousepos=camera.getWorld(pygame.mouse.get_pos())
world.digFour(mousepos[0], mousepos[1])
key=pygame.key.get_pressed()
updateGameObjects()
camera.set(player.getPos())
#drawing here
world.render()
renderGameObjects()
pygame.display.flip()
clock.tick(60)
pygame.display.quit()
pygame.quit()
示例15: go
def go():
# START
# Fairly obvious, initialize the pygame library
pygame.init()
# Create the world in which all physical things reside. It is our coordinate system and universe.
world = World(vector((20.0, 20.0, 2000.0)), vector((-10.0, 0.0, 10.0)))
# Create startup cameras and make the world visible to them
eyecam = Camera()
eyecam.registerObject(world)
scopecam = Camera()
scopecam.registerObject(world)
# Setup the program window (just a special case of a View)
screen = Screen(eyecam, vector((1000,800,0)), -1.0)
screen.display = pygame.display.set_mode((1000, 800))
# Setup the display surfaces to be drawn to screen and list them
main_dim = vector((1000,800,0.0))
scope_dim = vector((240,240,0.0))
mainview = View(eyecam, main_dim, zero_vector, 1.0)
scopeview = Scope(scopecam, scope_dim, (main_dim - scope_dim) / 2.0, 4.0)
views = [ mainview, scopeview ]
# Hide the cursor
mouse.set_visible(False)
# Let's set up some useful variables
now = pygame.time.get_ticks() # The current program time
shot_fired = False #
chase_bullet = False
hide_scope = True
lock_mouse = False
power = 100.0
#mainview.reposition(eyecam)
scopeview.setPower(power)
timescale = 1.0
tot_mag = 0.0
tot_dur = 0.0
frames = 0
if lock_mouse:
mouse.set_pos((scope_dim / 2.0).xy())
while 1:
last_t = now
now = pygame.time.get_ticks()
t_length = float(now - last_t)
if world.has_hit:
shot_end = now
#break
if world.bullet.position.z() > world.target.position.z() + 1000.0:
#world.bullet.position = vector((world.bullet.position.x(), world.bullet.position.y(), world.target.position.z() - 0.01))
shot_end = now
break
#pass
for event in pygame.event.get():
if event.type == pygame.MOUSEBUTTONDOWN:
if event.dict['button'] == 4:
power += 1.0
if event.dict['button'] == 5:
power -= 1.0
power = scopeview.setPower(power)
print power
if event.type == pygame.QUIT:
sys.exit()
sx, sy = (0.5 * mainview.dimensions).xy()
if lock_mouse:
mx, my = mouse.get_rel()
mouse.set_pos(sx, sy)
r = (1.0 / (10000 * power))* (vector((sx - mx, sy - my, 0)))
scopecam.rotation += r
eyecam.rotation += r
else:
mx, my = mouse.get_pos()
r = (1.0 / (1000 * power))* (vector((sx - mx, sy - my, 0)))
scopecam.rotation = r
eyecam.rotation = r
world.bullet.rotation = scopecam.rotation
scopeview.reposition(scopeview.camera)
mainview.reposition(mainview.camera)
b1, b2, b3 = mouse.get_pressed()
if b1 and not shot_fired:
shot_fired = True
#.........这里部分代码省略.........