当前位置: 首页>>代码示例>>Python>>正文


Python PyMouse.drag方法代码示例

本文整理汇总了Python中pymouse.PyMouse.drag方法的典型用法代码示例。如果您正苦于以下问题:Python PyMouse.drag方法的具体用法?Python PyMouse.drag怎么用?Python PyMouse.drag使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pymouse.PyMouse的用法示例。


在下文中一共展示了PyMouse.drag方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from pymouse import PyMouse [as 别名]
# 或者: from pymouse.PyMouse import drag [as 别名]
class Player:
    def __init__(self):
        self.mouse = PyMouse()

    def click(self, pos):
        self.mouse.click(*pos)

    def shoot(self, target, power, table_offset, cue_ball):
        adj_target = np.add(target, table_offset)
        self.mouse.press(*adj_target)

        adj_cue = np.add(cue_ball.get_pos(), table_offset)
        self.mouse.drag(*adj_cue)
        self.mouse.release(*adj_cue)
开发者ID:go717franciswang,项目名称:8ball,代码行数:16,代码来源:player.py

示例2: drag

# 需要导入模块: from pymouse import PyMouse [as 别名]
# 或者: from pymouse.PyMouse import drag [as 别名]
def drag(p1, p2, t = 0.05):
    m = PyMouse()
    m.press(p1.x, p1.y, 1)

    x = p1.x
    y = p1.y
    step = 5
    while distance(Point(x, y), p2) >= 1 :
        x += (p2.x - x)/step
        y += (p2.y - y)/step
        step -= 1
        m.drag(x, y)
#        time.sleep(0.01)
    m.release(p2.x, p2.y, 1)
    time.sleep(t)
开发者ID:raichu2652,项目名称:gsync-event-auto,代码行数:17,代码来源:prev.py

示例3: Bot

# 需要导入模块: from pymouse import PyMouse [as 别名]
# 或者: from pymouse.PyMouse import drag [as 别名]
class Bot():
    def __init__(self):
        self.mouse = PyMouse()
        self.keyboard = PyKeyboard()
    
    def Delay(self, n):
        time.sleep(n)
    
    """ ====== Mouse Macro ====== """
    def Left_click(self, x, y, n = 1, dl = 0):
        """在屏幕某点左键点击若干次
        """
        self.Delay(dl)
        self.mouse.click(x, y, 1, n)
    
    def Right_click(self, x, y, n = 1, dl = 0):
        """在屏幕某点右键点击若干次
        """
        self.Delay(dl)
        self.mouse.click(x, y, 2, n)
    
    def Double_click(self, x, y, dl = 0):
        """在屏幕的某点双击
        """
        self.Delay(dl)
        self.mouse.click(x, y, 1, n = 2)
    
    def Scroll_up(self, n, dl = 0):
        """鼠标滚轮向上n次
        """
        self.Delay(dl)
        self.mouse.scroll(vertical = n)
    
    def Scroll_down(self, n, dl = 0):
        """鼠标滚轮向下n次
        """
        self.Delay(dl)
        self.mouse.scroll(vertical = -n)
    
    def Move_to(self, x, y, dl = 0):
        """鼠标移动到x, y的坐标处
        """
        self.Delay(dl)
        self.mouse.move(x, y)
    
    def Drag_and_release(self, start, end, dl = 0):
        """从start的坐标处鼠标左键单击拖曳到end的坐标处
        start, end是tuple. 格式是(x, y)
        """
        self.Delay(dl)
        self.mouse.press(start[0], start[1], 1)
        self.mouse.drag(end[0], end[1])
        self.Delay(0.1)
        self.mouse.release(end[0], end[1], 1)
    
    def Screen_size(self):
        width, height = self.mouse.screen_size()
        return width, height
    
    def WhereXY(self):
        x_axis, y_axis = self.mouse.position()
        return x_axis, y_axis
    
    """ ====== Keyboard Macro ====== """
    """COMBINATION组合键"""
    """Ctrl系列"""
    
    def Ctrl_c(self, dl = 0):
        """Ctrl + c 复制
        """
        self.Delay(dl)
        self.keyboard.press_key(self.keyboard.control_key)
        self.keyboard.tap_key("c")
        self.keyboard.release_key(self.keyboard.control_key)
    
    def Ctrl_x(self, dl = 0):
        """Ctrl + x 剪切
        """
        self.Delay(dl)
        self.keyboard.press_key(self.keyboard.control_key)
        self.keyboard.tap_key("x")
        self.keyboard.release_key(self.keyboard.control_key)
        
    def Ctrl_v(self, dl = 0):
        """Ctrl + v 粘贴
        """
        self.Delay(dl)
        self.keyboard.press_key(self.keyboard.control_key)
        self.keyboard.tap_key("v")
        self.keyboard.release_key(self.keyboard.control_key)
    
    def Ctrl_z(self, dl = 0):
        """Ctrl + z 撤销上一次操作
        """
        self.Delay(dl)
        self.keyboard.press_key(self.keyboard.control_key)
        self.keyboard.tap_key("z")
        self.keyboard.release_key(self.keyboard.control_key)
        
    def Ctrl_y(self, dl = 0):
#.........这里部分代码省略.........
开发者ID:windse7en,项目名称:Angora,代码行数:103,代码来源:macro.py

示例4: run

# 需要导入模块: from pymouse import PyMouse [as 别名]
# 或者: from pymouse.PyMouse import drag [as 别名]
	def run(self):
		global running
		last_time = datetime.datetime.now()
		m=PyMouse()
		measure = str(datetime.datetime.now() - last_time).split(":", 1)[1].split(":", 1)[1]
		data = None
		X,Y,CX,CY,LX,LY,dirX,dirY=0,0,0,0,0,0,0,0
		CXX,CYY,LXX,LYY=0,0,0,0
		max_steps=120
		click_lock=0
		accelX=0
		accelY=0
		
		XX = range(0)
		YY = range(0)
			
		screen_dim = m.screen_size()
		print "Screen Xdim = " + str(screen_dim[0])
		print "Screen Ydim = " + str(screen_dim[1])
		
		while running:
			if not reciever.empty():
				data=reciever.get_nowait()
				print "data = " + str(data)
				reciever.task_done()
				current_pos = m.position()
				last_time = datetime.datetime.now()
				
			if (len(XX)>2 or len(YY)>2) and float(measure)>0.2:
				print "timout..."
				print "measure = " + str(measure)
				print "len XX = " + str(len(XX))
				if len(XX)>0:XX.pop(0)
				if len(YY)>0:YY.pop(0)
				
			if re.match("ROW", str(data)) is not None:
				CY = int(data.split("COL",1)[0].split("ROW",1)[1])
				CX = int(data.split("ROW",1)[1].split("COL",1)[1])
				data=None
				
				if CY is not None and CX is not None and float(measure)<0.125:
					print "\n"
					
					if (CX-LX)>0 and CX!=LX:XX.append(1)
					elif (CX-LX)<0 and CX!=LX:XX.append(-1)
					elif CX!=LX:XX.append(0)

					if (CY-LY)>0 and CY!=LY:YY.append(1)
					elif (CY-LY)<0 and CY!=LY:YY.append(-1)
					elif CY!=LY:YY.append(0)

					dirX=sum(XX)+(self.divider(1,LX))
					dirY=sum(YY)+(self.divider(1,LY))
					
					if float(measure)<0.025:accelX,accelY=4,3
					elif float(measure)>0.025 and float(measure)<0.05:accelX,accelY=3,2
					elif float(measure)>0.05 and float(measure)<0.075:accelX,accelY=2,1.25
					elif float(measure)>0.075 and float(measure)<0.1:accelX,accelX=1,0.75
					else:accelX,accelY=0.75,0.5
						
					targetX=current_pos[0]+(dirX*accelX)
					targetY=current_pos[1]+(dirY*accelY)
					
					if (current_pos[0]>0 and current_pos[0]<screen_dim[0]) and (current_pos[1]>0 and current_pos[1]<screen_dim[1]):
						
						if (targetX<screen_dim[0]) and (targetX>0) and (targetY<screen_dim[1]) and (targetY>0):
							if click_lock==1:m.drag((targetX),targetY)
							else:m.move((targetX),targetY)
							
					elif (current_pos[0]<=0) or (current_pos[1]<=0):
						if dirX>0:
							m.move((1+dirX),current_pos[1])
						elif dirY>0:
							m.move(current_pos[0],(dirY+1))
							
					elif current_pos[0]>=screen_dim[0]:
						if dirX<0:
							m.move(((screen_dim[0]-2)+dirX),(current_pos[1]-2))
					
					if len(XX)>=5 or len(YY)>=5:
						if len(XX)>0:XX.pop(0)
						if len(YY)>0:YY.pop(0)
						
					last_time = datetime.datetime.now()
					LX,LY=CX,CY
					CX,CY=None,None
			
			if re.match("LCLK", str(data)) is not None:
				data=None
				click_lock=0
				print "LEFT CLICK" + str(current_pos)
				m.click(current_pos[0],current_pos[1],1)
				#m.release(current_pos[0],current_pos[0])
				#m.release(current_pos[0],current_pos[0])
				#m.move(current_pos[0],current_pos[1])
				print "LEFT CLICK" + str(current_pos)
				
			if re.match("LPRS", str(data)) is not None:
				data=None
				click_lock=1
#.........这里部分代码省略.........
开发者ID:audiossis,项目名称:RemoteKbM,代码行数:103,代码来源:RemoteKbM.v.0.5.py

示例5:

# 需要导入模块: from pymouse import PyMouse [as 别名]
# 或者: from pymouse.PyMouse import drag [as 别名]
			# click value
			click=data[1] # if it is 7 mouse down else if it is 4 it is mouse up 
			# get the coordinates
			xcor,ycor,dec_x_binary,dec_y_binary=data[4],data[6],data[3],data[5]
			screen_xcor,screen_ycor=transform_board_screen(xcor,ycor,dec_x_binary,dec_y_binary)
			#print "%d, %d"%(xcor_dec,ycor_dec)
			#print "%d, %d"%(screen_xcor,screen_ycor)
			# check if it is valid event
			if xcor!=0 and ycor!=0 and debug==False:
				# move mouse	
				if click==7:
					# mean mouse down event
					if mouse_down_event:
						# drag event
						# draw a line from previous coordinates
						m.drag(screen_xcor, screen_ycor)
					else:
						# first button press event
						m.click(screen_xcor, screen_ycor, 1)
					mouse_down_event=True
				else:
					# mouse up event
					# set event type in mouse_down_event
					# first button press and drag
					mouse_down_event=False
		except usb.core.USBError as e:
			data = None
			if e.args == ('Operation timed out',):
				continue  
finally:
	# release the device
开发者ID:abhigenie92,项目名称:pyusbwhiteboard,代码行数:33,代码来源:pyusbwhiteboard.py

示例6: Bot

# 需要导入模块: from pymouse import PyMouse [as 别名]
# 或者: from pymouse.PyMouse import drag [as 别名]

#.........这里部分代码省略.........
    def scroll_right(self, n, pre_dl=None, post_dl=None):
        """Scroll right ``n`` times.

        **中文文档**

        鼠标滚轮向右滚动n次(如果可能的话)。
        """
        self.delay(pre_dl)
        self.m.scroll(horizontal=n)
        self.delay(post_dl)

    def scroll_left(self, n, pre_dl=None, post_dl=None):
        """Scroll left ``n`` times.

        **中文文档**

        鼠标滚轮向左滚动n次(如果可能的话)。
        """
        self.delay(pre_dl)
        self.m.scroll(horizontal=-n)
        self.delay(post_dl)

    def move_to(self, x, y, pre_dl=None, post_dl=None):
        """Move mouse to (x, y)

        **中文文档**

        移动鼠标到 (x, y) 的坐标处。
        """
        self.delay(pre_dl)
        self.m.move(x, y)
        self.delay(post_dl)

    def drag_and_release(self, start_x, start_y, end_x, end_y, pre_dl=None, post_dl=None):
        """Drag something from (start_x, start_y) to (end_x, endy)

        **中文文档**

        从start的坐标处鼠标左键单击拖曳到end的坐标处
        start, end是tuple. 格式是(x, y)
        """
        self.delay(pre_dl)
        self.m.press(start_x, start_y, 1)
        self.m.drag(end_x, end_y)
        self.m.release(end_x, end_y, 1)
        self.delay(post_dl)

    #--- Keyboard Single Key ---
    def tap_key(self, key_name, n=1, interval=0, pre_dl=None, post_dl=None):
        """Tap a key on keyboard for ``n`` times, with ``interval`` seconds of
        interval. Key is declared by it's name

        Example::

            bot.tap_key("a")
            bot.tap_key(1)
            bot.tap_key("up")
            bot.tap_key("space")
            bot.tap_key("enter")
            bot.tap_key("tab")

        **中文文档**

        以 ``interval`` 中定义的频率按下某个按键 ``n`` 次。接受按键名作为输入。
        """
        key = self._parse_key(key_name)
开发者ID:MacHu-GWU,项目名称:macro-project,代码行数:70,代码来源:bot.py

示例7: mk

# 需要导入模块: from pymouse import PyMouse [as 别名]
# 或者: from pymouse.PyMouse import drag [as 别名]
class mk(object):
    def getMousePosition(self):
        mouseposition = self.mouse.position()
        return np.array([mouseposition[0], mouseposition[1]])

    def __init__(self):
        self.mouse = PyMouse()
        self.keyboard = PyKeyboard()
        self.multikey_mapping = {"cmdd": (["cmd"], "d"), "shiftd": (["shift"], "d")}
        self.boundary = [
            0,
            0,
            AppKit.NSScreen.mainScreen().frame().origin.x + AppKit.NSScreen.mainScreen().frame().size.width,
            AppKit.NSScreen.mainScreen().frame().origin.y + AppKit.NSScreen.mainScreen().frame().size.height,
        ]

    def nKeysSameTime(self, list_of_mod, tap_key):
        for key in list_of_mod:
            self.keyboard.press_key(key)
        sleep(0.1)
        self.keyboard.tap_key(tap_key)
        for key in list_of_mod:
            self.keyboard.release_key(key)

    def decompMultiKey(self, key):
        (mod, tap_key) = self.multikey_mapping[key]
        return (mod, tap_key)

    def nKeysSequential(self, list_of_keys):
        for key in list_of_keys:
            try:
                self.keyboard.tap_key(key)
            except RuntimeError:
                try:
                    decomp = self.decompMultiKey(key)
                except:
                    raise RuntimeError("Key %s not implemented" % key)
                self.nKeysSameTime(decomp[0], decomp[1])
            sleep(0.15)

    def mouseEvent(self, thetype, pos_vec):
        posx = pos_vec[0]
        posy = pos_vec[1]
        theEvent = CGEventCreateMouseEvent(None, thetype, (posx, posy), kCGMouseButtonLeft)
        CGEventPost(kCGHIDEventTap, theEvent)

    def mouseMove(self, pos_vec):
        if pos_vec[0] < self.boundary[0]:
            posx = self.boundary[0]
        elif pos_vec[0] > self.boundary[2]:
            posx = self.boundary[2]
        else:
            posx = pos_vec[0]

        if pos_vec[1] < self.boundary[1]:
            posy = self.boundary[1]
        elif pos_vec[1] > self.boundary[3]:
            posy = self.boundary[3]
        else:
            posy = pos_vec[1]

        self.mouse.move(posx, posy)
        # self.mouseEvent(kCGEventMouseMoved, posx, posy)

    def mouseClick(self, pos_vec):
        posx = pos_vec[0]
        posy = pos_vec[1]
        self.mouse.press(posx, posy, button=1)
        self.mouse.release(posx, posy, button=1)

        # self.mouseEvent(kCGEventLeftMouseDown, posx, posy)
        # self.mouseEvent(kCGEventLeftMouseUp, posx, posy)

    def mouseDrag(self, posx, posy):
        self.mouse.press(self.mouse.position()[0], self.mouse.position()[1])
        self.mouse.drag(posx, posy)
        self.mouse.release(posx, posy)
开发者ID:jayhack,项目名称:NIPy,代码行数:79,代码来源:Controller.py

示例8: run

# 需要导入模块: from pymouse import PyMouse [as 别名]
# 或者: from pymouse.PyMouse import drag [as 别名]
	def run(self):
		global running
		last_time = datetime.datetime.now()
		m=PyMouse()
		
		self.settings()
		
		measure = str(datetime.datetime.now() - last_time).split(":", 1)[1].split(":", 1)[1]
		data = None
		X,Y,CX,CY,LX,LY,dirX,dirY=0,0,0,0,0,0,0,0
		CXX,CYY,LXX,LYY=0,0,0,0
		max_steps=120
		click_lock=0
		accelX=0
		accelY=0
		print "Started " + str(self)

		XX = range(0)
		YY = range(0)

		screen_dim = m.screen_size()
		print "Screen Xdim = " + str(screen_dim[0])
		print "Screen Ydim = " + str(screen_dim[1])
		current_pos = m.position()

		while running:
			if not reciever.empty():
				data=str(reciever.get_nowait()).split("\n",1)[0]
				#print "Data received: " + str(data)
				reciever.task_done()
				current_pos = m.position()
				last_time = datetime.datetime.now()

			if (len(XX)>2 or len(YY)>2) and float(measure)>0.2:
				if len(XX)>0:XX.pop(0)
				if len(YY)>0:YY.pop(0)

			if re.match(".*ROW", str(data)) is not None:
				CY = int(data.split("  TPRow",1)[0].split("ROW",1)[1])
				CX = LX
				#print "Row data: " + str(CY)
				#print "Col data: " + str(CX)
				data=None
			if re.match(".*COL", str(data)) is not None:
				CX = int(data.split("  TPCol",1)[0].split("COL",1)[1])
				CY = LY
				#print "Row data: " + str(CY)
				#print "Col data: " + str(CX)
				data=None

			if (CY is not None and CX is not None) and float(measure)<0.125:
				if (CX-LX)>0 and CX!=LX:XX.append(1)
				elif (CX-LX)<0 and CX!=LX:XX.append(-1)
				elif CX!=LX:XX.append(0)

				if (CY-LY)>0 and CY!=LY:YY.append(1)
				elif (CY-LY)<0 and CY!=LY:YY.append(-1)
				elif CY!=LY:YY.append(0)

				dirX=sum(XX)+(self.divider(1,LX))
				dirY=sum(YY)+(self.divider(1,LY))
				
				if float(measure)<0.025 and float(measure)>0.0175:
					#print str(measure)
					accelX,accelY=6,5
				elif float(measure)>0.025 and float(measure)<0.05:accelX,accelY=4,3
				elif float(measure)>0.05 and float(measure)<0.075:accelX,accelY=3,2
				elif float(measure)>0.075 and float(measure)<0.1:accelX,accelX=2,1
				else:accelX,accelY=1,1
				
				if int(dirX)==0:
					accelX=0
				if int(dirY)==0:
					accelY=0
					
				targetX=current_pos[0]+(dirX*accelX)
				targetY=current_pos[1]+(dirY*accelY)
				
				if (current_pos[0]>0 and current_pos[0]<screen_dim[0]) and (current_pos[1]>0 and current_pos[1]<screen_dim[1]):
					if (targetX<screen_dim[0]) and (targetX>0) and (targetY<screen_dim[1]) and (targetY>0):
						if click_lock==1:m.drag((targetX),targetY)
						else:m.move((targetX),targetY)
				elif (current_pos[0]<=0) or (current_pos[1]<=0):
					if dirX>0:
						m.move((1+dirX),current_pos[1])
					elif dirY>0:
						m.move(current_pos[0],(dirY+1))
				elif current_pos[0]>=screen_dim[0]:
					if dirX<0:
						m.move(((screen_dim[0]-2)+dirX),(current_pos[1]-2))
				
				if len(XX)>=5 or len(YY)>=5:
					if len(XX)>0:XX.pop(0)
					if len(YY)>0:YY.pop(0)
				
				last_time = datetime.datetime.now()
				LX,LY=CX,CY
			CX,CY=None,None

			if re.match(".*LCLK.*LCLK", str(data)) is not None and click_lock is not 1:
#.........这里部分代码省略.........
开发者ID:audiossis,项目名称:RemoteKbM,代码行数:103,代码来源:RemoteKbM.v.0.6.py


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