• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python mouse.get_pressed函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中pygame.mouse.get_pressed函数的典型用法代码示例。如果您正苦于以下问题:Python get_pressed函数的具体用法?Python get_pressed怎么用?Python get_pressed使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了get_pressed函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
开发者ID:drtchops,项目名称:iancraft,代码行数:35,代码来源:cameras.py


示例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)
开发者ID:mmagnuski,项目名称:psychopy,代码行数:34,代码来源:event.py


示例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)
开发者ID:ROBOMonkeys,项目名称:tower-defense-game,代码行数:7,代码来源:interfaces.py


示例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
开发者ID:drtchops,项目名称:iancraft,代码行数:26,代码来源:editor.py


示例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
开发者ID:DannyUfonek,项目名称:EarlOfSandwich,代码行数:11,代码来源:menuButton.py


示例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
开发者ID:paddypolson,项目名称:Stasis_Limitation,代码行数:53,代码来源:game_state.py


示例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()
开发者ID:nandakishoremmn,项目名称:ants,代码行数:14,代码来源:controller.py


示例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
开发者ID:tps12,项目名称:Dorftris,代码行数:16,代码来源:scrollbutton.py


示例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]
开发者ID:dwinings,项目名称:Grow,代码行数:17,代码来源:ginput.py


示例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
开发者ID:drtchops,项目名称:iancraft,代码行数:18,代码来源:ingame.py


示例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})
开发者ID:nerokiryu,项目名称:hugo_boss,代码行数:20,代码来源:GetEvent.py


示例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)
开发者ID:geijoenr,项目名称:pyXPS,代码行数:40,代码来源:CDesktop.py


示例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)
开发者ID:YannThorimbert,项目名称:ThorPy-1.0,代码行数:4,代码来源:_shifters.py


示例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()
开发者ID:bobbaluba,项目名称:CaveMaster,代码行数:61,代码来源:cavemaster.py


示例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
#.........这里部分代码省略.........
开发者ID:jc2brown,项目名称:Plink,代码行数:101,代码来源:plink.py


示例16: render_mouse_rect

 def render_mouse_rect(self, camera):
     if mouse.get_pressed()[0] and (self.mouse_rect.w or self.mouse_rect.h):
         pos = Rect(self.mouse_rect.x - camera.rect.x,
             self.mouse_rect.y - camera.rect.y, self.mouse_rect.w,
             self.mouse_rect.h)
         draw.rect(self.resourcemgr.screen, BLUE, pos, 5)
开发者ID:drtchops,项目名称:iancraft,代码行数:6,代码来源:ingame.py


示例17: buttons_down

 def buttons_down(self): return mouse.get_pressed()
 @property
开发者ID:MrGecko,项目名称:pyguane,代码行数:2,代码来源:eventmanager.py


示例18: print

     print("saving screenshot to {}".format(filepath))
     pygame.image.save(screenshot, filepath)
 if event.type == pl.KEYDOWN and event.key == pl.K_F3:
     '''
     debugging function
     '''
     if DEBUG_MODE:
         DEBUG_MODE = False
         CLEAR_DEBUG = True
         allSprites.remove(fpsdisplay)
         print("debug mode off")
     else:
         DEBUG_MODE = True
         allSprites.add(fpsdisplay, layer = DEBUG_LAYER)
         print("debug mode on")
 if event.type == pl.MOUSEBUTTONDOWN and mouse.get_pressed()[0]:
     '''
     This is where the button's destination kicks in
     Unfortunately, we have to check each button separately,
     as the pygame.sprite.Group.update() can't return sprites' .update()
     return values.
     What happens here:
     When the user clicks a button: 
     1. all buttons are checked (one by one) to see which one the mouse is on,
     2. the background is drawn over it (and only it)
     3. the button updates
     4. the button gets put into the buttonToDraw one-sprite-only group
     5. buttonToDraw draws it onto the screen
     6. the display updates only on it
     7. then the destination is checked, and except for two special cases, new buttons are
     loaded from menuCreator (that is, all existing buttons removed, and new ones drawn on screen)
开发者ID:DannyUfonek,项目名称:EarlOfSandwich,代码行数:31,代码来源:__init__.py


示例19: main

def main():
    term = Color()
    init()
    screen = display.set_mode((800, 600))
    finished = False
    sprDimension = 20
    R = 255
    G = 0
    B = 0
    RedKey = 114
    GreenKey = 103
    BlueKey = 98
    UP = 273
    DOWN = 274
    colorFocus = ""

    while not finished:
        for ev in event.get():
            if ev.type == QUIT:
                finished = True
            elif ev.type == MOUSEBUTTONDOWN:
                if mouse.get_pressed()[0] == 1:
                    draw.rect(
                        screen, (R, G, B), (mouse.get_pos()[0], mouse.get_pos()[1], sprDimension, sprDimension), 0
                    )
            elif ev.type == KEYDOWN:
                print ev.key
                if ev.key == RedKey:
                    colorFocus = "r"
                elif ev.key == GreenKey:
                    colorFocus = "g"
                elif ev.key == BlueKey:
                    colorFocus = "b"
                elif ev.key == UP and colorFocus != "":
                    if colorFocus == "r":
                        if R == 255:
                            R = 0
                        else:
                            R += 1

                    if colorFocus == "g":
                        if G == 255:
                            G = 0
                        else:
                            G += 1

                    if colorFocus == "b":
                        if B == 255:
                            B = 0
                        else:
                            B += 1

                elif ev.key == DOWN and colorFocus != -1:
                    print ev.key

                    if colorFocus == "r":
                        if R == 0:
                            R = 255
                        else:
                            R -= 1

                    if colorFocus == "g":
                        if G == 0:
                            G = 255
                        else:
                            G -= 1

                    if colorFocus == "b":
                        if B == 0:
                            B = 255
                        else:
                            B -= 1

        print R, G, B

        draw.rect(screen, (R, G, B), (screen.get_width() - sprDimension, 0, screen.get_width(), sprDimension), 0)
        display.update()
        draw.rect(screen, (0, 0, 0), screen.get_rect(), 0)

        sleep(0.4)
开发者ID:chiforimpola,项目名称:GeneralApps,代码行数:80,代码来源:main.py


示例20: quit_game

while running:
    for event in pygame.event.get():
        if event.type == QUIT:
            running = False
        elif event.type == KEYDOWN:
            if event.key == K_q:
                quit_game()
            if event.key == K_u:
                for t in enums.SPRITES[0].list:
                    t.upgrade()
            if event.key == K_a:
                for t in enums.SPRITES[0].list:
                    t.set_state(3)
        elif event.type == MOUSEBUTTONDOWN:
            b1, b2, b3 = mouse.get_pressed()
            if b1:
                if argv[1] == "ui":
                    clicked += 1
                    bunch_cntr.change_text(":  " + str(clicked), True)
                    heart = hearts[-(clicked % len(hearts))]
                    if heart.get_heart() == Heart.FULL:
                        heart.set_heart(Heart.HALF)
                    elif heart.get_heart() == Heart.HALF:
                        heart.set_heart(Heart.EMPTY)
                    else:
                        heart.set_heart(Heart.FULL)
                    btn.update()
            if b2:
                for t in enums.SPRITES[0]:
                    t.upgrade()
开发者ID:ROBOMonkeys,项目名称:tower-defense-game,代码行数:30,代码来源:main.py



注:本文中的pygame.mouse.get_pressed函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python mouse.set_visible函数代码示例发布时间:2022-05-25
下一篇:
Python mouse.get_pos函数代码示例发布时间:2022-05-25
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap