Example #1
0
 def move_span(self):
     if not self.check_login_ok():
         return
     pyautogui.hscroll(-100)
     sleep(0.3)
     # print('hsroll')
     sleep(1)
     rect = pyautogui.locateOnScreen('./images/span.png',
                                     region=(1242, 321, 465, 404),
                                     confidence=0.8)
     x = int((rect[0] * 2 + rect[2]) / 2)
     y = int((rect[1] * 2 + rect[3]) / 2)
     pyautogui.moveTo(x, y, 0.5, pyautogui.easeInOutCirc)
     pyautogui.mouseDown(button='left', duration=uniform(0.05, 0.1))
     pyautogui.moveTo(x + 240, y + randint(-10, 10), uniform(0.5, 1.3),
                      pyautogui.easeOutQuad)
     pyautogui.mouseUp(button='left', duration=uniform(0.05, 0.1))
     sleep(1)
     logging.info('拉动滑块结束,店铺:{}'.format(self.shopname))
     #  检测是否成功
     if not self.check_move_span_ok():
         logging.warning('拉动滑块失败,店铺:{}'.format(self.shopname))
         pyautogui.click(x, y)
         sleep(0.3)
         self.click_span_refresh()
         raise Exception
     sleep(1)
     logging.info('拉动滑块成功,店铺:{}'.format(self.shopname))
async def control(websocket, path):
    try:
        async for message in websocket:
            data = json.loads(message)
            logging.debug(data)

            if data['action'] == 'onmouseup':
                pyautogui.mouseDown(**extractMouseParameter(data))
            elif data['action'] == 'onmousedown':
                pyautogui.mouseDown(**extractMouseParameter(data))
            elif data['action'] == 'onmousemove':
                pyautogui.moveTo(duration=0,
                                 **extractMouseParameter(data, button=False))
            elif data['action'] == 'onmousewheel':
                deltax = convertScroll(data['parameter']['deltaX'])
                deltay = convertScroll(data['parameter']['deltaY'])
                if deltax != 0:
                    pyautogui.hscroll(
                        deltax, **extractMouseParameter(data, button=False))
                if deltay != 0:
                    pyautogui.vscroll(
                        deltay, **extractMouseParameter(data, button=False))
            elif data['action'] == 'onclick':
                pyautogui.click(**extractMouseParameter(data))
            elif data['action'] == 'onkeyup':
                key = extractKey(data)
                pyautogui.keyUp(key)
            elif data['action'] == 'onkeydown':
                key = extractKey(data)
                pyautogui.keyDown(key)
            else:
                logging.error("unsupported event: {}", data)
    finally:
        pass
Example #3
0
def scrollto(p):
    """
    这里的x,y是相对于整个卷帘区域,需要滚动屏幕以保证x,y,w都在屏幕可操作范围内
    """
    global Px, Py, Pw, Ph  #在这个范围内的内容是可见区域
    (x, y, force, w) = convert(p)

    (mx, my, mw, mh) = frame(scpt.call('whereami'))
    (targetx, targety) = (mx + x, my + mh - y)
    #首先保证X方向上可见,也就是需要保证 targetx>=Px and targetx+w < Px+Pw
    #如果目标X在可见区域左侧 将目标移动到可见位置即可
    while targetx + XUnit < Px:
        pyautogui.hscroll(10)
        (mx, my, mw, mh) = frame(scpt.call('whereami'))
        (targetx, targety) = (mx + x, my + mh - y)
    #如果targetx+w在可见区域右侧,将targetx+w移动到可见区域即可
    while targetx + w + XUnit > Px + Pw:
        pyautogui.hscroll(-10)
        (mx, my, mw, mh) = frame(scpt.call('whereami'))
        (targetx, targety) = (mx + x, my + mh - y)

    #然后保证Y方向上可见,也是一样的原理 也就是需要保证 targety>=Py and targety+YUnit < Py+Ph
    #如果目标Y在可见区域上方 将目标移动到可见位置即可
    while targety < Py:
        pyautogui.scroll(10)
        (mx, my, mw, mh) = frame(scpt.call('whereami'))
        (targetx, targety) = (mx + x, my + mh - y)
    #如果targety+1在可见区域右侧,将targety+1移动到可见区域即可
    while targety + YUnit > Py + Ph:
        pyautogui.scroll(-10)
        (mx, my, mw, mh) = frame(scpt.call('whereami'))
        (targetx, targety) = (mx + x, my + mh - y)
    return (targetx, targety, w, force)
Example #4
0
def mourseScroll():
    """
    scroll函数控制鼠标滚轮的滚动,amount_to_scroll参数表示滚动的格数。
    正数则页面向上滚动,负数则向下滚动:
    pyautogui.scroll(clicks=amount_to_scroll, x=moveToX, y=moveToY)
    每个按键按下和松开两个事件可以分开处理:
    
    :return: 
    """
    moveToX = 100
    moveToY = 100
    pyautogui.mouseDown(x=moveToX, y=moveToY, button='left')
    pyautogui.mouseUp(x=moveToX, y=moveToY, button='left')

    # 鼠标滚轮滚动可以用scroll()函数和clicks次数参数来模拟。
    # 不同平台上的clicks次数不太一样。还有x和y参数可以在滚动之前定位到(x, y)位置。
    # 例如:
    #  向上滚动10格
    pyautogui.scroll(10)
    #  向下滚动10格
    pyautogui.scroll(-10)
    #  移动到(100, 100)位置再向上滚动10格
    pyautogui.scroll(10, x=100, y=100)

    # 在OS X和Linux平台上,PyAutoGUI还可以用hscroll()实现水平滚动。例如:
    #  向右滚动10格
    pyautogui.hscroll(10)
    #  向左滚动10格
    pyautogui.hscroll(-10)
 def recieve_gesture(self, gesture: Gesture):
     if gesture == Gesture.SwipingLeft:
         pyautogui.hotkey('ctrl', 'right')
     elif gesture == Gesture.SwipingRight:
         pyautogui.hotkey('ctrl', 'left')
     elif gesture == Gesture.SwipingUp:
         pyautogui.hotkey('ctrl', 'up')
     elif gesture == Gesture.SwipingDown:
         pyautogui.hotkey('ctrl', 'down')
     elif gesture == Gesture.SlidingTwoFingersUp:
         for i in range(10):
             pyautogui.scroll(-1)
     elif gesture == Gesture.SlidingTwoFingersDown:
         for i in range(10):
             pyautogui.scroll(1)
     elif gesture == Gesture.SlidingTwoFingersRight:
         for i in range(10):
             pyautogui.hscroll(-1)
     elif gesture == Gesture.SlidingTwoFingersLeft:
         for i in range(10):
             pyautogui.hscroll(1)
     elif gesture == Gesture.ZoomingInWithFullHand:
         pyautogui.hotkey('command', '+')
     elif gesture == Gesture.ZoomingOutWithFullHand:
         pyautogui.hotkey('command', '-')
     elif gesture == Gesture.PushingHandAway:
         pyautogui.hotkey('f11')
     elif gesture == Gesture.PullingHandIn:
         pyautogui.hotkey('f12')
Example #6
0
def insertP(p, idx):
    global lastw, lastforce
    (px, py, pw, force) = scrollto(p)

    # add point
    pyautogui.keyDown('command')
    pyautogui.moveTo(px, py + YUnit / 3)
    pyautogui.click()
    pyautogui.keyUp('command')

    if idx != scpt.call('itemcount'):
        print 'insert fail!'
        sys.exit(1)

    if lastw != pw:
        # fix length
        global Px, Py, Pw, Ph  #在这个范围内的内容是可见区域
        (x, y, w, h) = frame(scpt.call('lastchild'))
        if abs(w - pw) > 5:
            while x + w > Px + Pw:
                pyautogui.hscroll(-10)
                (x, y, w, h) = frame(scpt.call('lastchild'))
            pyautogui.moveTo(x + w - 1, y + h / 2)
            pyautogui.dragTo(x + pw - 1, y + h / 2, button='left')

    if lastforce != force:
        scpt.call('setforce', force)

    lastforce = force
    lastw = pw
Example #7
0
def api():
    global is_mouse_down
    if not is_login():
        abort( 401, 'Must login first')
    if request.values[ 'evt'] == 'click':
        if is_mouse_down:
            pyautogui.mouseUp()
            is_mouse_down = False
        else:
            pyautogui.click()
    elif request.values[ 'evt'] == 'dbclick':
        pyautogui.rightClick()
    elif request.values[ 'evt'] == 'drag':
        if is_mouse_down:
            pyautogui.mouseUp()
            is_mouse_down = False
        else:
            pyautogui.mouseDown()
            is_mouse_down = True
    elif request.values[ 'evt'] == 'move':
        x, y = int( request.values[ 'x']), int( request.values[ 'y'])
        l2 = x**2 + y**2
        k = l2/20000.0 + 1.05
        pyautogui.moveRel( x*k, y*k, 0.02)
    elif request.values[ 'evt'] == 'scroll':
        x, y = int( request.values[ 'x']), int( request.values[ 'y'])
        pyautogui.scroll( -y)
        pyautogui.hscroll( -x)
    elif request.values[ 'evt'] == 'key':
        # print( 'KEY: ', request.values[ 'keys'].split( '|'))
        pyautogui.hotkey( *tuple( request.values[ 'keys'].split( '|')))
    return 'OK'
Example #8
0
def loop(
    joysticks: typing.Iterable[xinput.XInputJoystick],
    mouse_movements: typing.Iterable[MouseMovement],
    mouse_presses: Presses,
    keyboard_presses: Presses
) -> None:
    while True:
        # Dispatch all events.
        for joystick in joysticks:
            joystick.dispatch_events()
        # Mix all controllers together.
        combined = MouseMovement.combine(mouse_movements)
        # Do the mouse movement.
        pyautogui.move(*attr.astuple(combined.position_speed))
        # Do the mouse scrolling.
        pyautogui.hscroll(int(combined.scroll_speed.x))
        pyautogui.vscroll(int(combined.scroll_speed.y))
        # Do the mouse button presses.
        down, up = mouse_presses.process_queue()
        for button in down:
            pyautogui.mouseDown(button=button)
        for button in up:
            pyautogui.mouseUp(button=button)
        # Do the keyboard key presses.
        down, up = keyboard_presses.process_queue()
        for key in down:
            pyautogui.keyDown(key)
        for key in up:
            pyautogui.keyUp(key)
        # Sleep.
        try:
            time.sleep(0.017)
        except KeyboardInterrupt:
            break
 def test_scroll(self):
     # TODO - currently this just checks that scrolling doesn't result in an error.
     pyautogui.scroll(1)
     pyautogui.scroll(-1)
     pyautogui.hscroll(1)
     pyautogui.hscroll(-1)
     pyautogui.vscroll(1)
     pyautogui.vscroll(-1)
def mouse_scroll(log_list, log_number):					# Scrolls the mouse Vertically and Horizontally.
	line = log_list[log_number]
	try:
		(x, y) = (str(line.split(" _|_ ")[2])[1:-1]).split(", ")			# Getting Mouse Location
		pyautogui.hscroll(int(x))										# For Horizontal Scroll. Only linux and OSX support Horizontal Scroll
		pyautogui.scroll(int(y))										# For normal Scroll.
	except AttributeError:
		pass
Example #11
0
 def test_scroll(self):
     # TODO - currently this just checks that scrolling doesn't result in an error.
     pyautogui.scroll(1)
     pyautogui.scroll(-1)
     pyautogui.hscroll(1)
     pyautogui.hscroll(-1)
     pyautogui.vscroll(1)
     pyautogui.vscroll(-1)
Example #12
0
    def handle_mouse_scroll_right_intent(self, message):
        if platform.system().lower().startswith('lin'):
            self.speak('scrolling right now')
            scroll = message.data.get('Scroll')
            scroll_right = int(scroll)
	    pyautogui.hscroll(scroll_right)
        else:
            self.speak('Sorry, I cannot scroll right on your current operating system')
def scroll_fun(text):
    if text == 'down':
        auto.scroll(-6)
    elif text == 'up':
        auto.scroll(6)
    elif text == 'right':
        auto.hscroll(6)
    elif text == 'left':
        auto.hscroll(-6)
	def _handleScroll(self, data):
		move_type = data[:1]
		x = intFromBytes(data[1:5])
		y = intFromBytes(data[5:9])
		# Prevent bug with pyautogui library where x < 10 causes opposite horizontal scrolling behavior
		# https://github.com/asweigart/pyautogui/issues/154
		if not (-9 <= x and x <= -1):
			pyautogui.hscroll(x)
		if y:
			pyautogui.vscroll(y)
Example #15
0
 def check_login_btn(self):
     pyautogui.hscroll(-100)
     sleep(0.5)
     rect = pyautogui.locateOnScreen('./images/login_btn.png',
                                     region=(1242, 321, 465, 404),
                                     confidence=0.8)
     if rect:
         logging.error('等待3S后登录按钮仍然在页面上,将结束本次登录,店铺:{}'.format(
             self.shopname))
         raise Exception
Example #16
0
def scroll_fun(text):
    if text == 'down':
        auto.scroll(-6)
    elif text == 'up':
        auto.scroll(6)
    elif text == 'right':
        auto.hscroll(6)
    elif text == 'left':
        auto.hscroll(-6)
    else:
        print('scroll has no function like that')
        office(text)
Example #17
0
    def perform(self):
        x, y = self.position[0], self.position[1]
        if not self.window == None:
            x, y = ((((1.0 - variance) + random.random() *
                      (2 * variance)) * self.position[0] *
                     self.window.dimension[0]) + self.window.position[0],
                    (((1.0 - variance) + random.random() *
                      (2 * variance)) * self.position[1] *
                     self.window.dimension[1]) + self.window.position[1])

            x = max(self.window.position[0],
                    min(x, self.window.position[0] + self.window.dimension[0]))
            y = max(self.window.position[1],
                    min(y, self.window.position[1] + self.window.dimension[1]))
        pyautogui.hscroll(self.velocity_x, x=x, y=y)
        pyautogui.scroll(self.velocity_y, x=x, y=y)
Example #18
0
def moveto_scoll(img, scrollnum):
    check_image(img)
    image_path = img_path(img)
    pyautogui.moveTo(pyautogui.locateOnScreen(image_path))
    print("已移动到%s区域,开始滚动" % image_path)
    if scrollnum.__contains__('F'):
        scrollnum = scrollnum.split('F')[1]
        for i in range(scrollnum):
            time.sleep(1)
            pyautogui.hscroll(10)
            print("向上滚动第%d次" % int(i + 1))
    else:
        for i in range(int(scrollnum)):
            time.sleep(1)
            pyautogui.hscroll(-10)
            print("向下滚动第%d次" % int(i + 1))
def automate_video_changes():
	import webbrowser
	import pyautogui
	import os
	import time
	editbutton=(484,386)
	description=(330,448)
	tags=(317,621)
	endscreen=(1300,423)
	videocombo=(346,332)
	save1=(1094,186)
	discard=(986,187)
	save2=(1245,202)
	webbrowser.open_new_tab(f"https://studio.youtube.com/video/{videoid}/edit/basic")
	time.sleep(15)
	i=True
	pyautogui.click(description[0],description[1])
	with open("ytdescription.txt","r") as f:
		descriptiontxt=f.read().format(title)
	pyautogui.typewrite(descriptiontxt,interval=0.05)
	located=True
	while located:
		pyautogui.hscroll(-100)
		if pyautogui.locateOnScreen("tags.png"):
			located=False
	pyautogui.click("tags.png")
	tagstxt=""
	for tag in videotags:
		tagstxt+=tag+","
	tagstxt+=title+","
	for word in title.split(" "):
		tagstxt+=word+","
	pyautogui.typewrite(tagstxt,interval=0.05)
	located=True
	while located:
		pyautogui.hscroll(100)
		if pyautogui.locateOnScreen("endscreen.png"):
			located=False
	pyautogui.click("endscreen.png")
	time.sleep(5)
	pyautogui.click(videocombo[0],videocombo[1])
	time.sleep(5)
	pyautogui.click(save1[0],save1[1])
	time.sleep(5)
	pyautogui.click(discard[0],discard[1])
	time.sleep(5)
	pyautogui.click(save2[0],save2[1])
Example #20
0
def on_imu(data):
    """
    Process the IMU data to move the mouse around the screen.
    :param data: a dictionary containing information from the IMU sensor
    :return: Nothing
    """

    # Declare some variables for ease of reading
    pitch = float(data['IMU_PITCH_FILTERED'])  # Translate in a displacement on Y axis
    roll = float(data['IMU_ROLL_FILTERED'])  # Translate in a displacement on X axis

    x = 60 * (roll / 180)
    y = 60 * (pitch / 180)

    # Move the mouse on the screen
    pyautogui.scroll(x)
    pyautogui.hscroll(y)
Example #21
0
def find_share_name(y_point):
    xyp2("namu_app_name", "click", "False", 0.95)
    sell_img_drag()
    pya.move(0, 50)
    # pya.scroll(70)
    xyp2("avg_img", "move", "False", 0.95)
    # pya.move(0, 469)
    pya.hscroll(-70)
    # sell_img_scroll()
    # xyp2("namu_app_name", "click", "False", 0.95)
    xyp2("share_lists", "move", "False", 0.95)
    pya.move(80, y_point)
    x, y = pya.position()
    pya.screenshot('img/var/stock_name.png',
                   region=((x*2)-100, (y*2)-30, 150, 50))
    pya.screenshot('img/var/stock_info.png',
                   region=((x*2)+150, (y*2)-100, 500, 120))
    return x, y
def guiThread():
    global stackIn, stackOut
    while True:
        try:
            if not stackOut:
                while stackIn:
                    stackOut.append(stackIn.pop())
            # read
            mouseBias = [0, 0]
            mouseClick = False
            str = None
            while stackOut:
                query = stackOut.pop()
                args = query.split()
                if args[0] == "m":
                    dx, dy = map(int, args[1:])
                    mouseBias[0] += dx
                    mouseBias[1] += dy
                elif args[0] == "c":
                    mouseClick = True
                elif args[0] == "t":
                    str = " ".join(args[1:])
                elif args[0] == "h":
                    gui.hotkey(*tuple(args[1:]))
                elif args[0] == "sv":
                    gui.vscroll(int(args[1]))
                elif args[0] == "sh":
                    gui.hscroll(int(args[1]))
                elif args[0] == "ss":
                    gui.screenshot("screenshot.png")
                else:
                    print("What is '{}'".format(query))
            # excute
            gui.move(mouseBias[0], mouseBias[1])
            if mouseClick:
                gui.mouseDown()
                time.sleep(0.01)
                gui.mouseUp()
                mouseClick = False
            if str != None:
                gui.typewrite(str)
        except Exception as e:
            print(e)
            continue
Example #23
0
def execute(]str):


	if str == 'left_mouse click':
		pyautogui.click( button = 'left' )
		print('kam hoise')
	elif str == 'right_mouse click':
		pyautogui.click( button = 'right' )
	elif str == 'middle_mouse click':
		pyautogui.click( button = 'middle' )
	elif str == 'scroll_up':
		pyautogui.scroll(10)
	elif str == 'scroll_down':
		pyautogui.scroll(-10)
	elif str == 'scroll_right':
		pyautogui.hscroll(10)
	elif str == 'scroll_left':
		pyautogui.hscroll(-10)
	elif str == 'page_up':
		pyautogui.press('pgup')
	elif str == 'page_down':
		pyautogui.press('pgdn')
	elif str == 'zoom_out':
		pyautogui.keydown('shift')
		pyautogui.press('+')
		pyautogui.keyup('shift')
	elif str == 'zoom_in':
		pyautogui.keydown('shift')
		pyautogui.press('-')
		pyautogui.keyup('shift')
	elif str == 'refresh':
		pyautogui.press('f5')
	elif str == 'screenshot':
		pyautogui.screenshot()
	elif str == 'volume_up':
		pyautogui.press('volumeup')
	elif str == 'volume_down':
		pyautogui.press('volumedown')
	elif str == 'next_track':
		pyautogui.press('nexttrack')
	elif str == 'prev_track':
		pyautogui.press('prevtrack')
	elif str == 'play/pause':
		pyautogui.press('playpause')
Example #24
0
def oneTouchTracker(message, received_coords):
    """
    Process one finger mouse tracking network requests.
    """
    if message == "C":
        pyautogui.click()
        received_coords[0][1] = False  # flag reset to prepare for next call
    elif message == "RC":
        pyautogui.click(button='right')
        received_coords[0][1] = False
    elif message == "SU":
        pyautogui.scroll(30)
        received_coords[0][1] = False
    elif message == "SD":
        pyautogui.scroll(-30)
        received_coords[0][1] = False
    elif message == "SL":  # left scrolling is supported only in Linux and Mac OSX
        pyautogui.hscroll(-30)
        received_coords[0][1] = False
    elif message == "SR": # right scrolling is supported only in Linux and Mac OSX
        pyautogui.hscroll(30)
        received_coords[0][1] = False
    else:
        coords = message.split(",")
        new_x = int(coords[0].strip())
        new_y = int(coords[1].strip())

        if not received_coords[0][1]:
            received_coords[0][0][0] = new_x
            received_coords[0][0][1] = new_y
            received_coords[0][1] = True
        elif not received_coords[1]:
            curr_x, curr_y = pyautogui.position()
            trans_x = (new_x - received_coords[0][0][0])
            trans_y = (new_y - received_coords[0][0][1])
            if abs(trans_x) > leap_bound or abs(trans_y) > leap_bound:
                received_coords[0][1] = False
                return received_coords
            trans_x *= sensitivity_factor
            trans_y *= sensitivity_factor
            pyautogui.moveTo(curr_x + trans_x , curr_y + trans_y)
            received_coords[0][1] = False

    return received_coords
def event_filter():
    """Filters commands sent by the handler and executes them"""
    while 1:
        data = sock.recv(1024)
        data = data.decode()
        if "right" in data and "pressed" in data:
            pyautogui.mouseDown(button='right')

        elif "right" in data and "released" in data:
            pyautogui.mouseUp(button='right')

        elif "left" in data and "pressed" in data:
            pyautogui.mouseDown(button='left')

        elif "left" in data and "released" in data:
            pyautogui.mouseUp(button='left')

        elif "up" in data:
            pyautogui.scroll(175)
        elif "down" in data:
            pyautogui.scroll(-175)
        elif "rig2" in data:
            pyautogui.hscroll(175)
        elif "lef2" in data:
            pyautogui.hscroll(-175)
        elif "change_lang" in data:
            pyautogui.hotkey('shift', 'altleft')
        elif "press:" in data:
            if 'Key' in data:
                pyautogui.keyDown(data[data.find('.') + 1:])
            else:
                pyautogui.keyDown(data[data.find(':') + 3])
        elif "release:" in data:
            if 'Key' in data:
                pyautogui.keyUp(data[data.find('.') + 1:])
            else:
                pyautogui.keyUp(data[data.find(':') + 3])
        else:
            x, y = data.split(' ')
            x = int(x)
            y = int(y)
            pyautogui.moveTo(x, y)
Example #26
0
    def act(self, inputs):  #0 <= action <= 1
        select = np.argmax(inputs[0])
        # x = inputs[1][0] % self.size[0]
        x = inputs[1][0] % self.size[0]
        y = inputs[1][1] % self.size[1]

        z = int(self.size[1] - (inputs[1][2] % self.size[1]) )

        # if x == 0 and y == 0:   #(0,0)좌표를 넣으면 오류를 내서 꼼수로 해결
        #     x = 0.1

        print("act :", select, "x :", x, "y :", y, "z :", z)
        # Hscroll(s) ,Scroll(s), Move(x, y), Drag(x, y) * 3, Click(x, y) * 3, DoubleClick(x, y)
        if select == 0:
            print(x, y, z)
            pyautogui.hscroll(z, x=x, y=y)
        elif select == 1:
            print(x, y, z)
            pyautogui.scroll(z, x=x, y=y)
        elif select == 2:
            pyautogui.moveTo(x, y)
        elif select == 3:
            pyautogui.dragTo(x, y, button='left')
        elif select == 4:
            pyautogui.dragTo(x, y, button='right')
        elif select == 5:
            pyautogui.dragTo(x, y, button='middle')
        elif select == 6:
            pyautogui.click(x, y, button='left')
        elif select == 7:
            pyautogui.click(x, y, button='right')
        elif select == 8:
            pyautogui.click(x, y, button='middle')
        elif select == 9:
            pyautogui.doubleClick(x, y, button='left')

        print("done.")

        im = pyautogui.screenshot()
        im = im.transpose((0, 2, 1, 3))
        return im
Example #27
0
    def event_filter(self):
        """Filters commands sent by the handler and executes them"""
        while self.main_con:
            data = pickle.loads(self.socket.recv(1024))
            if "right" in data and "pressed" in data:
                pyautogui.mouseDown(button='right')

            elif "right" in data and "released" in data:
                pyautogui.mouseUp(button='right')

            elif "left" in data and "pressed" in data:
                pyautogui.mouseDown(button='left')

            elif "left" in data and "released" in data:
                pyautogui.mouseUp(button='left')

            elif "up" in data:
                pyautogui.scroll(175)
            elif "down" in data:
                pyautogui.scroll(-175)
            elif "rig2" in data:
                pyautogui.hscroll(175)
            elif "lef2" in data:
                pyautogui.hscroll(-175)
            elif "change_lang" in data:
                pyautogui.hotkey('shift', 'altleft')
            elif "press:" in data:
                if 'Key' in data:
                    pyautogui.keyDown(data[data.find('.') + 1:])
                else:
                    pyautogui.keyDown(data[data.find(':') + 3])
            elif "release:" in data:
                if 'Key' in data:
                    pyautogui.keyUp(data[data.find('.') + 1:])
                else:
                    pyautogui.keyUp(data[data.find(':') + 3])
            else:
                pyautogui.moveTo(data)
Example #28
0
def scrollH(cap, network, device, size, confidence):
    if network == "normal":
        print("loading yolo...")
        yolo = YOLO("models/cross-hands.cfg", "models/cross-hands.weights",
                    ["hand"])
    elif network == "prn":
        print("loading yolo-tiny-prn...")
        yolo = YOLO("models/cross-hands-tiny-prn.cfg",
                    "models/cross-hands-tiny-prn.weights", ["hand"])
    else:
        print("loading yolo-tiny...")
        yolo = YOLO("models/cross-hands-tiny.cfg",
                    "models/cross-hands-tiny.weights", ["hand"])

    yolo.size = size
    yolo.confidence = confidence

    cnt = 0
    curr = 0
    prev = 0
    exit = 0

    rval, frame = cap.read()

    while True:
        width, height, inference_time, results = yolo.inference(frame)

        if len(results) == 1:
            exit = 0
            cnt += 1

            id, name, confidence, x, y, w, h = results[0]
            cx = x + (w // 2)
            cy = y + (h // 2)

            if cnt <= 5:
                curr = cx

            color = (0, 255, 255)
            cv2.circle(frame, (cx, cy), 10, color, -1)
            #print("Cy: ", cy)

            if cnt % 10 == 0 and cnt > 5:
                prev = curr
                curr = cx
                #print("Prev: ",prev)
                #print("Curr: ", curr)
                clicks = prev - curr
                #print(clicks)
                #if clicks>30 and clicks<170:
                #clicks = clicks//2

                if abs(clicks) > 10:
                    pyautogui.hscroll(clicks)

        else:
            exit += 1
            if exit > 50:
                print(exit)
                break

        cv2.imshow("preview", frame)
        rval, frame = cap.read()

        key = cv2.waitKey(20)
        if key == 27:  # exit on ESC
            break

    cv2.destroyWindow("preview")
Example #29
0
import webbrowser
import pyautogui
import random
from PIL import Image

#uri for your browser
chrome_app = 'C:/Program Files (x86)/Google/Chrome/Application/chrome.exe %s'
urlFile = "urls.txt"

with open(urlFile) as fp:
    url = fp.readline()
    while url:
        webbrowser.get(chrome_app).open(url)

        pyautogui.moveTo(x=200, y=200, duration=4.0)
        pyautogui.hscroll(-1500)
        pyautogui.moveTo(x=300, y=300, duration=1.5)

        k = 0
        ok = 0
        while ok == 0 and k != 6:
            screenshot = pyautogui.screenshot()
            graySS = screenshot.convert("L")  #screenshot turned to greyscale
            bwSS = graySS.point(
                lambda x: 0 if x < 255 else 255, '1'
            )  #greyscale turned to black and white image, threshold applied
            #bwSS.save("an"+str(k)+".png" # uncomment this to check image if doubts
            k += 1
            pattern = Image.open("clapThresholded.png")

            box = pyautogui.locate(pattern, bwSS, confidence=0.5)
Example #30
0
#pyautogui.tripleClick()
pyautogui.tripleClick(x=None, y=None, interval=0.0, button='left', duration=0.0, tween=pyautogui.linear)

#右击
pyautogui.rightClick()

#中击
pyautogui.middleClick()

#  用缓动/渐变函数让鼠标2秒后移动到(500,500)位置
#  use tweening/easing function to move mouse over 2 seconds.
pyautogui.moveTo(x=500, y=500, duration=2, tween=pyautogui.easeInOutQuad)

#鼠标拖拽
pyautogui.dragTo(x=427, y=535, duration=3,button='left')

#鼠标相对拖拽
pyautogui.dragRel(xOffset=100,yOffset=100,duration=,button='left',mouseDownUp=False)

#鼠标移动到x=1796, y=778位置按下
pyautogui.mouseDown(x=1796, y=778, button='left')

#鼠标移动到x=2745, y=778位置松开(与mouseDown组合使用选中)
pyautogui.mouseUp(x=2745, y=778, button='left',duration=5)

#鼠标当前位置滚轮滚动
pyautogui.scroll()
#鼠标水平滚动(Linux)
pyautogui.hscroll()
#鼠标左右滚动(Linux)
pyautogui.vscroll()
        pyautogui.hotkey('win', 'd')
    if sheet.range(instrCell).value == "WiggleMouse":
        pyautogui.scroll(10)  # scroll up 10 "clicks"
        pyautogui.scroll(-10)  # scroll down 10 "clicks"
    if sheet.range(instrCell).value == "MaximizeApplications":
        pyautogui.hotkey('win', 'up')
    if sheet.range(instrCell).value == "copy":
        pyautogui.hotkey('win', 'c')
    if sheet.range(instrCell).value == "MoveMouse":
        param1 = "C" + str(x)
        XCoordinate = sheet.range(param1).value
        param2 = "D" + str(x)
        YCoordinate = sheet.range(param2).value
        pyautogui.moveTo(XCoordinate, YCoordinate, 2, pyautogui.easeInQuad)
    if sheet.range(instrCell).value == "DragMouse":
        param1 = "C" + str(x)
        XCoordinate = sheet.range(param1).value
        param2 = "D" + str(x)
        YCoordinate = sheet.range(param2).value
        pyautogui.dragTo(XCoordinate, YCoordinate, 2, pyautogui.easeInQuad)
    if sheet.range(instrCell).value == "VerticalScroll":
        param1 = "C" + str(x)
        ScrollAmount = sheet.range(param1).value
        pyautogui.scroll(ScrollAmount)
    if sheet.range(instrCell).value == "HorizontalScroll":
        param1 = "C" + str(x)
        ScrollAmount = sheet.range(param1).value
        pyautogui.hscroll(ScrollAmount)

    wb.save('C:\\Users\\craig\\Documents\\CS3398-Vulcans-S2020\\example.xlsm')
#wb.save(sys.argv[1])
def Automate(name, loc):
    new =2;
    query = name 
    query1 = loc 
    quer=query+" "+query1;
    appended = quer.replace(' ','+');
    url="https://www.google.com/search?tbm=isch&sxsrf=ALeKk00cEaZtWu-EG6Ew0-1EpCxZm6sgTQ%3A1596206679952&source=hp&ei=Vy4kX7-MONHw9QPesIa4Bg&q=";
    url+=appended;
    browser = webdriver.Chrome('chromedriver') 
  
    for i in range(1): 
     matched_elements = browser.get(url);

     time.sleep(3);
     pyautogui.moveTo(250, 250);
     for k in range(50):
         pyautogui.scroll(-20);
         time.sleep(1);
     time.sleep(3);
     browser.close();

     uurl="https://www.facebook.com/";
     browser = webdriver.Chrome('chromedriver') 
  
    for i in range(1): 
         matched_elements = browser.get(uurl);
         
         pyautogui.write('*****@*****.**');
         pyautogui.press('tab');
         pyautogui.write('sih_2020');
         pyautogui.press('tab');
         pyautogui.press('enter');
         pyautogui.click(x=392, y=184);
         time.sleep(10);
         pyautogui.click();
         pyautogui.click(x=70, y=156);
         pyautogui.write(quer);
         pyautogui.press('enter');
         time.sleep(5);
         pyautogui.click(x=480,y=358);
         time.sleep(2);
         pyautogui.click();
         time.sleep(5);
         pyautogui.click(x=259, y=303);
         time.sleep(7);
         for k in range(8):
             pyautogui.scroll(-200);
             time.sleep(3);
         time.sleep(5);
         browser.close();
    """ [email protected] sih_2020
    appended = query.replace(' ','%20');
    prl ="https://www.linkedin.com/search/results/all/?keywords=";
    tail="&origin=GLOBAL_SEARCH_HEADER";
    prl+=appended+tail;"""

    uurl="https://www.linkedin.com/home";
    browser = webdriver.Chrome('chromedriver') 
  
    for i in range(1): 
         matched_elements = browser.get(uurl);
         pyautogui.click(x=283, y=475);
         pyautogui.write('*****@*****.**');
         pyautogui.press('tab');
         pyautogui.write('his_2020');
         pyautogui.press('tab');
         pyautogui.press('tab');
         pyautogui.press('tab');
         pyautogui.press('enter');
         time.sleep(5);
         pyautogui.click(x=726, y=619);
         time.sleep(15);
         pyautogui.click(x=431,y=597);
         time.sleep(3);
         pyautogui.click();
         time.sleep(1);    


         pyautogui.click(x=909, y=171)
         pyautogui.click(x=137, y=159);
         pyautogui.write(query);
         time.sleep(6);
         pyautogui.press('enter');
         pyautogui.keyDown('ctrl');
         pyautogui.press('+');
         pyautogui.press('+');
         pyautogui.press('+');
         pyautogui.press('+');
         pyautogui.press('+');
         pyautogui.press('+');
         pyautogui.keyUp('ctrl');
         pyautogui.hscroll(1000);
         pyautogui.scroll(900);
         time.sleep(1);
         for k in range(8):
             pyautogui.scroll(-200);
             time.sleep(3);
         time.sleep(5);
         browser.close();
    uurl="https://www.instagram.com/";
    browser = webdriver.Chrome('chromedriver') 
    for i in range(1):
         matched_elements = browser.get(uurl);
         time.sleep(3);    
         pyautogui.press('tab');
         pyautogui.press('enter');
         pyautogui.write("*****@*****.**");
         pyautogui.press('tab');
         pyautogui.write('sih_2020');
         pyautogui.press('tab');
         pyautogui.press('tab');
         pyautogui.press('enter');
         time.sleep(3);
         pyautogui.press('tab');
         pyautogui.press('tab');
         pyautogui.press('enter');
         
         pyautogui.click(x=652,y=700);
         time.sleep(3);
         pyautogui.click(x=656,y=756);
         time.sleep(4);
         v=0;dl=80;
         for v in range(6):
             pyautogui.click(x=647,y=198);
             pyautogui.write(query);
             time.sleep(1);  
             pyautogui.click(x=543,y=275+dl);
             time.sleep(2);
             for k in range(2):
                 pyautogui.scroll(-200);
                 time.sleep(3);
             time.sleep(1);
             pyautogui.click(x=47,y=99);
             dl+=80;
         browser.close();
    
    appended = query.replace(' ','%20');
    pprl ="https://in.pinterest.com/search/pins/?q=";
    tail="&rs=typed";
    pprl+=appended+tail;
    browser = webdriver.Chrome('chromedriver') 
    for i in range(1): 
         matched_elements = browser.get(pprl);
         pyautogui.moveTo(250, 250);
         for k in range(1):
             pyautogui.scroll(-800);
             time.sleep(3);
    time.sleep(3);
    browser.close();
Example #33
0
    def dataReceived(self, data):
        #fetch commands from data
        cmds = data.split(';');
        
        #exec each command
        for cmd in cmds:
            
            # cmd = object : action < :param < :param < :param ... >>>
            # each cmd contains atleast 'object' & 'action'
            splitted = cmd.split(':');
            
            #invalid cmd?
            if (len(splitted)<2):
                continue
            
            #number of params
            params   = len(splitted)-2

            obj = splitted[0]
            act = splitted[1]
            
            if obj == "mouse":   
                
                if act == "click":
                    if params == 0:
                        pyautogui.click()
                    
                    #click provided a parameter: number of clicks!
                    elif params == 1:
                        clicks = int(float(splitted[2]))
                        pyautogui.click(clicks=clicks)
            
                elif act == "doubleclick":
                    pyautogui.doubleClick()

                elif act == "tripleclick":
                    pyautogui.tripleClick()
                                    
                elif act == "rightclick":
                    pyautogui.rightClick()
                
                elif act == "scroll":
                    if params == 2:
                        x = int(float(splitted[2]))
                        y = int(float(splitted[3]))
                        pyautogui.hscroll(x);
                        pyautogui.vscroll(y);
                                    
                elif act == "drag":
                    if params == 1:
                        # indicate that dragging is activated, but not yet started
                        if splitted[2] == "start":
                            self.dragActive = True
                        # indicate that dragging in disactivated
                        elif splitted[2] == "end":
                            self.dragActive = False
                            #stop dragging when active
                            if self.dragStarted:
                                self.dragStarted = False
                                pyautogui.mouseUp()
                        else:
                            print "Unknown value for 'drag':" + splitted[2]

                    elif params == 2:
                        #are we already dragging?
                        if not self.dragStarted:
                            self.dragStarted = True
                            pyautogui.mouseDown()
                        
                        #fetch x/y movement
                        x = int(float(splitted[2]))
                        y = int(float(splitted[3]))
                        pyautogui.dragRel(x,y, mouseDownUp=False)
 
                                    
                elif act == "move":
                    if params == 2:
                        #fetch x/y movement
                        x = int(float(splitted[2]))
                        y = int(float(splitted[3]))
                        
                        #are we dragging?
                        pyautogui.moveRel(x,y)
                            

            elif obj == "key":
                key = splitted[2]
                print("keypress:" + act + " key:" + key)
                if (act == "press"):
                    pyautogui.press(key)
                elif (act == "down"):
                    pyautogui.keyDown(key)
                elif (act == "up"):
                    pyautogui.keyUp(key)