Beispiel #1
3
def temp():
    pyautogui.alert('This displays some text with an OK button.')
    pyautogui.position()  # current mouse x and y
    pyautogui.onScreen(x, y)  # True if x & y are within the screen.
    pyautogui.PAUSE = 2.5   # Pause 2.5 s
    pyautogui.dragTo(x, y, duration=num_seconds)  # drag mouse to XY
    pyautogui.dragRel(xOffset, yOffset, duration=num_seconds)  # drag mouse relative to its current position
    pyautogui.click(x=moveToX, y=moveToY, clicks=num_of_clicks, interval=secs_between_clicks, button='left') # The button keyword argument can be 'left', 'middle', or 'right'.
    pyautogui.scroll(amount_to_scroll, x=moveToX, y=moveToY)
    pyautogui.mouseDown(x=moveToX, y=moveToY, button='left')
    pyautogui.mouseUp(x=moveToX, y=moveToY, button='left')
    pyautogui.typewrite('Hello world!\n', interval=secs_between_keys)  # useful for entering text, newline is Enter
    pyautogui.typewrite(['a', 'b', 'c', 'left', 'backspace', 'enter', 'f1'], interval=secs_between_keys)
    pyautogui.hotkey('ctrl', 'c')  # ctrl-c to copy
    pyautogui.hotkey('ctrl', 'v')  # ctrl-v to paste
    pyautogui.alert('This displays some text with an OK button.')
    pyautogui.confirm('This displays text and has an OK and Cancel button.')
    pyautogui.prompt('This lets the user type in a string and press OK.')
    pyautogui.screenshot('foo.png')  # returns a Pillow/PIL Image object, and saves it to a file
    pyautogui.locateOnScreen('looksLikeThis.png')
    pyautogui.locateCenterOnScreen('looksLikeThis.png')  # returns center x and y
 def call(self):
     v = self.LOCATIONS['call']
     gui.moveTo(v[0][0] + self.x + 50, v[0][1] + self.y + 10, duration = .3) 
     time.sleep(.3)
     gui.mouseDown()
     time.sleep(.2)
     gui.mouseUp()
Beispiel #3
0
def moveClick(x,y, button=0):#moves to random X,Y of found match of template
    moveTo(x,y)
    RandTime.randTime(0,0,0,0,0,2)
    if button != 0:
        pyautogui.mouseDown(button='left')
        RandTime.randTime(0,1,0,0,2,9)#time between click
        pyautogui.mouseUp(button='left')
Beispiel #4
0
 def down_a_level(self):
     """Holds down and presses alt to jump down"""
     time.sleep(1)
     pyautogui.mouseDown(self.DOWN)
     time.sleep(2.5)
     pyautogui.click(self.ALT)
     pyautogui.mouseUp()
Beispiel #5
0
 def balls_to_the_wall(self, duration):
     """Pushes enemy to end of field with shield.
        Then launches every powerful attack that's not 
        currently cooling down. Loots corner afterwards."""
     logging.info('Starting balls_to_the_wall.')
     tactic_timer = time.time()
     level = 1
     while (time.time() - tactic_timer) < duration:
         self.buffs()
         self.heal()
         #Set them up
         self.shield_charge(random.randrange(10, 18))
         self.gas_explosion(random.randrange(6, 10))
         self.nether_shield()
         self.run('opposite', random.uniform(.5, 1.25))
         self.turn()
         #Knock them down
         attack_timer = time.time()
         self.debuff_enemy(random.uniform(.5, 3.5))
         while (time.time() - attack_timer) < random.randrange(8, 12):
             pyautogui.mouseDown(self.Q)
             self.heal()
             self.nether_shield()
             self.scooby_bats()
         pyautogui.mouseUp()
         #Pick up remains and reposition
         self.loot_corner(self.direction)
         self.run('forward', random.uniform(.5, 1.25))
         self.nether_shield()
         self.level_navigation()
     logging.info('Ending balls_to_the_wall.')
Beispiel #6
0
 def debuff_enemy(self, duration):
     """Break enemy defence, hits many enemies ahead of you"""
     duration = random.uniform(duration - .25, duration + 1.5)
     pyautogui.mouseDown(self.E)
     time.sleep(duration)
     pyautogui.mouseUp()
     self.heal()
Beispiel #7
0
    def send_click_to_square(self, square_id):
        if not self.board_started:
            return

        if self.flipped.get():
            square_to_click = [x for x in self.board_squares if x['reversed_id'] == square_id]
        else:
            square_to_click = [x for x in self.board_squares if x['square_id'] == square_id]

        if square_to_click:
            square_to_click = square_to_click[0]
        else:
            self.msg.set('Unable to find square to click!')
            return

        x, y = square_to_click.get('center')

        try:
            self.msg.set('Trying to click on "{}"'.format(square_to_click['name']))
            time.sleep(0.2)
            pyautogui.mouseDown(x, y)
            time.sleep(0.2)
            pyautogui.mouseUp(x, y)
        except Exception as e:
            self.msg.set(str(e))
Beispiel #8
0
 def up_a_level(self):
     """Presses ALT UP UP for a super vertical jump"""
     time.sleep(0.5)
     pyautogui.click(self.ALT)
     pyautogui.doubleClick(self.UP)
     pyautogui.mouseDown(self.UP) 
     time.sleep(2.5)
     pyautogui.mouseUp()
Beispiel #9
0
 def scooby_bats(self):
     """Sends small horde of bats to obtain enemy agro"""
     cool_down = 8
     if (time.time() - self.scooby_bat_timer) > cool_down:
         pyautogui.mouseDown(self.D)
         time.sleep(0.35)
         pyautogui.mouseUp()
         cooldown_timer = time.time()
Beispiel #10
0
 def gas_explosion(self, duration):
     """Gas storm damages enemies life steal with exploding AOE finale"""
     cool_down = 12
     if (time.time() - self.gas_explosion_timer) > cool_down:
         duration = random.uniform(duration - 1.5, duration + 1.5)
         pyautogui.mouseDown(self.S)
         time.sleep(duration)
         pyautogui.mouseUp()
         self.heal()
Beispiel #11
0
 def nether_shield(self):
     """Sends homing shields out to attack enemies"""
     cool_down = 6
     if (time.time() - self.nethershield_timer) > cool_down:
         self.nethershield_timer = time.time()
         pyautogui.mouseDown(self.A)
         time.sleep(0.55)
         pyautogui.mouseUp()
         self.heal()
Beispiel #12
0
 def loot_ahead(self):
     """Walk short distance ahead looting on the way"""
     pyautogui.mouseDown(self.Z)
     time.sleep(1)
     for x in range(3):
         pyautogui.mouseDown(self.Z)
         time.sleep(random.uniform(0.5, 1.3))
         self.run('forward', random.uniform(0.1, 0.5))
     pyautogui.mouseUp()
Beispiel #13
0
 def click(self, key, duration):
     """
     Given a key to click and a duration to click it for, this method will
     click the key for the given duration.
     """
     self._moveTo(key)
     pyautogui.mouseDown()
     time.sleep(duration)
     pyautogui.mouseUp()
     time.sleep(0.25)
 def fold(self):
     if self.user_position() is 'BB' and self.bets().max() == self.blinds:
         v = self.LOCATIONS['call']      
     else:  
         v = self.LOCATIONS['fold']
         
     gui.moveTo(v[0][0] + self.x + 50, v[0][1] + self.y + 10, duration = .3) 
     time.sleep(.3)
     gui.mouseDown()
     time.sleep(.2)
     gui.mouseUp()
Beispiel #15
0
 def process(self, directive):
     self.log.debug(" processing <%s> directive", directive)
     self.button, x, y = self.parse(directive)
     self.pointer = Position(x, y)
     try:
         if self.button == "UP":
             ##???pyautogui.mouseUp (button='left')
             pyautogui.moveTo(self.pointer.x, self.pointer.y)
         else:
             ##???pyautogui.mouseDown (button='left')
             pyautogui.mouseDown(button="left", x=self.pointer.x, y=self.pointer.y)
     except Exception as details:
         self.log.warning(" <%s> directive not processed :: %s", directive, details)
Beispiel #16
0
def reset_ui_field_on_android():
    # select all texts in the UI field
    pyautogui.mouseDown();
    time.sleep(2)
    pyautogui.mouseUp()
    # reset the UI field
    pyautogui.press("backspace")
    pyautogui.press("del")
    pyautogui.press("delete")
    # unfocus the UI field
    pyautogui.moveRel(-150, 0, duration)
    pyautogui.click()
    time.sleep(1)
Beispiel #17
0
 def loot(self):
     """Auto loots the area"""
     loot_directions = [self.LEFT, self.RIGHT]
     for direction in loot_directions:
         for x in range(5):
             pyautogui.mouseDown(direction)
             time.sleep(0.1)
             pyautogui.mouseUp()
             pyautogui.mouseDown(self.Z)
             time.sleep(1)
             pyautogui.mouseUp()
         if direction is self.LEFT:
             self.run('right', 1)
         elif direction is self.RIGHT:
             self.run('left', 1)
Beispiel #18
0
 def run(self, direction, duration):
     """Character runs for duration heading toward direction"""
     if direction is 'right':
         pyautogui.mouseDown(self.RIGHT)
         self.direction = 'right'
     elif direction is 'left':
         pyautogui.mouseDown(self.LEFT)
         self.direction = 'left'
     elif direction is 'opposite':
         if self.direction is 'left':
             self.run('right', duration)
         elif self.direction is 'right':
             self.run('left', duration)
     elif direction is 'forward':
         self.run(self.direction, duration)
     time.sleep(duration)
     pyautogui.mouseUp()
Beispiel #19
0
def comm(inp, ser):
    print inp

    if "RELOAD" in inp:
        pyautogui.press('R')
        inp =  ser.readline()
        while "RELOAD" in inp:
           inp =  ser.readline()
           pyautogui.press('R')
        print "R"

    elif "LR" in inp:
        pyautogui.mouseDown(button='left')
        pyautogui.mouseDown(button='right')
        inp =  ser.readline()
        while "LR" in inp:
            inp =  ser.readline()

        pyautogui.mouseUp(button='left')
        pyautogui.mouseUp(button='right')
        
    elif "LEFT" in inp:
        pyautogui.mouseDown(button='left')

        inp =  ser.readline()
        while "LEFT" in inp:
            inp =  ser.readline()
        pyautogui.mouseUp(button='left')

    elif "RIGHT" in inp:
        pyautogui.mouseDown(button='right')

        inp =  ser.readline()
        while "RIGHT" in inp:
            inp =  ser.readline()

        pyautogui.mouseUp(button='right')

    elif "TOGGLE" in inp:
           inp =  ser.readline()
           #close_action()
           Toggle()
           
    elif "CLOSE" in inp:
           inp =  ser.readline()
           close_action()
           #Toggle()
            
    else:
        inp =  ser.readline()
    
    return inp
Beispiel #20
0
def execute(order):
    args = order.split(',');
    mess = args[0];
    if mess.startswith('key'):
        key = args[1]
        if mess.endswith('Down'):
            pyautogui.keyDown(key);
        else:
            pyautogui.keyUp(key);
    elif mess.startswith('mouse'):
        x = int(args[1])
        y = int(args[2])
        if mess.endswith('Down'):
            pyautogui.mouseDown(x, y);
        elif mess.endswith('Up'):
            pyautogui.mouseUp(x, y);
        else:
            pyautogui.moveTo(x, y);
    else:
        print("Error:mess=", args);
Beispiel #21
0
 def loot_corner(self, direction):
     """Auto loots corner of area which you are facing"""
     for x in range(2):
         pyautogui.mouseDown(self.Z)
         time.sleep(0.5)
         pyautogui.mouseUp()
         if direction is 'left':
             pyautogui.mouseDown(self.LEFT)
         elif direction is 'right':
             pyautogui.mouseDown(self.RIGHT)
         time.sleep(0.2)
         pyautogui.mouseUp()
         pyautogui.mouseDown(self.Z)
         time.sleep(2.5)
         pyautogui.mouseUp()
         self.heal()
     self.turn()
     pyautogui.mouseDown(self.Z)
     time.sleep(2)
     pyautogui.mouseUp()
Beispiel #22
0
def scrollMonsterBarRightToLeft(numOfTimes,allConfigs,direction = 'left'):
    for i in xrange(0,numOfTimes):
        screenshot = functions_screenshot.screenshotOpencv(allConfigs)
        monster_select = checkPicture(screenshot,'monster_select.png', allConfigs['tolerance'] ,allConfigs['directories'],allConfigs, multiple = True)

        most_left_monster = find_min_max(monster_select,'x','min')
        most_right_monster = find_min_max(monster_select,'x','max')

        if direction == 'left':
            pyautogui.moveTo(most_right_monster['points'][0]['top_left'][0],most_right_monster['points'][0]['bottom_right'][1])
            pyautogui.mouseDown()
            pyautogui.moveTo(most_left_monster['points'][0]['top_left'][0]+int(allConfigs['error_correction']['monster_scroll']),most_left_monster['points'][0]['bottom_right'][1],allConfigs['wait_times']['scroll_speed'])
            pyautogui.mouseUp()
            functions_general.randomWait( allConfigs['wait_times']['between_scrolls'],0 )
        else:
            pyautogui.moveTo(most_left_monster['points'][0]['top_left'][0],most_left_monster['points'][0]['bottom_right'][1])
            pyautogui.mouseDown()
            pyautogui.moveTo(most_right_monster['points'][0]['top_left'][0]+int(allConfigs['error_correction']['monster_scroll']),most_right_monster['points'][0]['bottom_right'][1],allConfigs['wait_times']['scroll_speed'])
            pyautogui.mouseUp()
            functions_general.randomWait( allConfigs['wait_times']['between_scrolls'],0 )
    return    
def copyVerCode():
	pyautogui.click(1275,730)
	time.sleep(1)
	pyautogui.click(820,370)
	time.sleep(1)
	pyautogui.click(500,150)
	time.sleep(1)
	pyautogui.mouseDown(500, 150, button='left')
	time.sleep(1.5)
	pyautogui.mouseUp(500, 150, button='left')
	time.sleep(1)
	pyautogui.click(500,390)
	time.sleep(1)
	pyautogui.click(500,680)
	time.sleep(1)
	pyautogui.hotkey('ctrl', 'v')
	time.sleep(1)
	pyautogui.doubleClick(500,680)
	time.sleep(1)
	pyautogui.click(520,710)
	pyautogui.dragTo(540, 715, duration=0.5)
Beispiel #24
0
def ioThread():
    OOO="       "
    printer.p(OOO+"ioThread === checking in...")
    global req
    global alive
    l=0
    r=0
    while alive:
        if myID==IDcheck:
            #if time.time()-start>20: alive=False #autorestart
            try:
                response=requests.post('http://'+ip+'/zerog/getgui.php', params={"mode":"r"})
                j=response.json()
          
                req=int(j['req'])
                if req==-1: alive=False
                if req!=1: continue
                o_l=l
                o_r=r
                x=int(j['x'])
                y=int(j['y'])
                l=int(j['l'])
                k=int(j['k'])
                r=int(j['r'])
                
                printer.p(OOO+"ioThread === xyzlr:"+str(x)+","+str(y)+","+str(l)+","+str(r)+",  k:"+str(k)+",  req:"+str(req))
                
                pyautogui.moveTo(x,y,0)
                if l==1 and o_l!=1: pyautogui.mouseDown();
                elif l==0 and o_l!=0: pyautogui.mouseUp();
                
                if r==1 and o_r!=1: pyautogui.mouseDown(button='right');
                elif r==0 and o_r!=0: pyautogui.mouseUp(button='right');
                
                time.sleep(1)
            except:
                pass
        else: time.sleep(5)
        
    printer.p(OOO+"ioThread === ...checking out")
Beispiel #25
0
 def do_it(self):
     while True:
         try:
             try:
                 body = self.INPUT_Q.get_nowait()
             except:
                 body = None
             if body != None:
                 head = body[:4]
                 body = body[4:]
                 if head == 'MOUS' and self.mous_press == False:
                     mxy = body.split('|')
                     self.mous.move(int(mxy[0]),int(mxy[1]))
                     #pyautogui.moveTo(int(mxy[0]),int(mxy[1]))
                 elif head == 'MCLK' or self.mous_press == True:
                     mxy = body.split('|')
                     if mxy[2] == 'DOWN':
                         if mxy[3] == '1':
                             pyautogui.mouseDown(int(mxy[0]),int(mxy[1]),button='left')
                         elif mxy[3] == '3':
                             pyautogui.mouseDown(int(mxy[0]),int(mxy[1]),button='right')
                         else:
                             pyautogui.scroll(5,x=int(mxy[0]),y=int(mxy[1]))
                     else:
                         self.mous_press = False
                         if mxy[3] == '1':
                             pyautogui.mouseUp(int(mxy[0]),int(mxy[1]),button='left')
                         elif mxy[3] == '3':
                             pyautogui.mouseUp(int(mxy[0]),int(mxy[1]),button='right')
                         else:
                             pyautogui.scroll(-5,x=int(mxy[0]),y=int(mxy[1]))
                 elif head == "KCLK":
                     key_ev = body.split('|')
                     if key_ev[0] == 'DOWN':
                         pyautogui.keyDown(key_ev[1])
                     elif key_ev[0] == "UP":
                         pyautogui.keyUp(key_ev[1])
         except Exception as e:
             print "INPUT CONTROL ERROR",e
Beispiel #26
0
def OnKeyDownEvent(event):
	global hookOn
	if event.KeyID == 27: #Escape to quit
		sys.exit()
	elif event.KeyID == 145: #Scroll lock to enable/disable key control
		ChangeHook()
	elif hookOn == True: #If control is enabled, Then...
		if event.KeyID == 19: #Display key list
			ButtonList()
		elif event.Key in keyList:
			if event.Key in debouncedKeyList and keyPairs[event.Key] == False:
				pyautogui.mouseDown(x = xCoords[event.Key], y = yCoords[event.Key])
				keyPairs[event.Key] = True
			elif event.Key in commandKeyList:
				pyautogui.click(xCoords[event.Key],yCoords[event.Key])
			elif event.Key in speedKeyList:
				ModifySpeed(event)
			
# return True to pass the event to other handlers, i.e. OS
	if hookOn == True:
		return (event.Key not in keyList)
	else:
		return True
Beispiel #27
0
 def spam_attack(self, duration):
     """All action non-stop attack rampage super killer mode"""
     logging.info('Starting spam_attack.')
     tactic_timer = time.time()
     turn_timer = time.time()
     level = 0
     while (time.time() - tactic_timer) < duration:
         self.heal()
         self.buffs()
         self.nether_shield()
         self.shield_charge(random.randrange(9, 18))
         self.nether_shield()
         self.gas_explosion(random.randrange(3, 9))
         self.nether_shield()
         self.debuff_enemy(random.randrange(7, 16))
         self.heal()
         self.scooby_bats()
         spam_timer = time.time()
         while (time.time() - spam_timer) < random.randrange(3, 8):
             pyautogui.mouseDown(self.Q)
         pyautogui.mouseUp()
         self.loot_ahead()
         self.level_navigation()
     logging.info('Ending spam_attack.')
Beispiel #28
0
def main():
    #time.sleep(3.5)
    demonBot = DemonAvenger()
    while True:
        for x in range(4):
            demonBot.buffs()
            demonBot.heal()
            demonBot.random_ability(random.uniform(6, 25))
            #Loot 
            for x in range(10):
                if demonBot.direction is 'left':
                    pyautogui.mouseDown(demonBot.LEFT)
                elif demonBot.direction is 'right':
                    pyautogui.mouseDown(demonBot.RIGHT)
                time.sleep(0.1)
                pyautogui.click(demonBot.Z)
                pyautogui.mouseUp()
            #demonBot.run('forward', random.uniform(0.3, 1.75))
            #pyautogui.mouseDown(demonBot.Z)
            #time.sleep(random.uniform(1.0, 2.5))        #demonBot.random_tactics()
            #pyautogui.mouseUp()
        demonBot.level_navigation()
        demonBot.turn()
        logging.info('DemonAvenger main loop cycling')
Beispiel #29
0
 def across_platform(self):
     """Fly across to adjacent platform"""
     time.sleep(2)
     self.run('opposite', 1.2)
     self.turn()
     #Keep direction pressed down as we click alt
     if self.direction is 'left':
         pyautogui.mouseDown(self.LEFT)
     elif self.direction is 'right':
         pyautogui.mouseDown(self.RIGHT)
     time.sleep(1)
     pyautogui.click(self.ALT)
     pyautogui.mouseDown(self.ALT)
     time.sleep(1.5)
     pyautogui.mouseUp()
Beispiel #30
0
    def parse_face_pic(self, url_pic):
        #调用get_access_token获取access_token
        access_token = self.get_access_token()
        url_fi = "https://aip.baidubce.com/rest/2.0/face/v3/detect?access_token=" + access_token
        #调用identify_faces,获取人脸列表
        json_faces = self.identify_faces(url_pic, url_fi)
        return json_faces


if __name__ == "__main__":

    while True:
        print('>>>> 调用程序时间:%s <<<<' %
              datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'))
        mouse_dclick(1620, 687)
        pag.mouseDown(x=1620, y=790, button='left')
        pag.mouseUp(x=1620, y=300, button='left')
        print(">> 切换抖音用户视频页面成功")

        # 截图
        mouse_click(1881, 247)
        sleep(3)
        paths = "H:\myshares\Screenshots"
        for root, dirs, files in os.walk(paths):
            filename = files[0]
            print(">> 截图成功,截图文件名:%s," % filename)
            file_dir = paths + "\\" + filename

        #file_dir="H:\myshares\Screenshots\Screenshot_2018-08-19-17-49-24.png

        # 分辨率整体缩小到原来的 0.3 ,可以加快上传速度
def startMining():
    p.mouseDown()
def simulateDoubleClick():
    pyautogui.mouseDown()
    pyautogui.mouseDown(button="right")
    time.sleep(0.001)
    pyautogui.mouseUp()
    pyautogui.mouseUp(button="right")
Beispiel #33
0
def click():
    ag.mouseDown()
    time.sleep(0.1)
    ag.mouseUp()
def click(wt=0.1):
    pyautogui.mouseDown()
    time.sleep(wt + uniform(0, 1))
    pyautogui.mouseUp()
    return
Beispiel #35
0
from lib.window import Window
mouse = HumanClicker()
status = Status_Bar()

t = Crafting(button='media/box-titles/create.png')
source = Window(title='media/box-titles/source.png')
inventory = Window(title='media/box-titles/inventory.png')
target = Window(title='media/box-titles/target.png')

while True:
    if status.stamin:
        t.continue_()
        # Get resources
        s_s = source.find_item(item="media/items/stone_shards.png")
        mouse.move((s_s[0][0], s_s[0][1]), 2)
        pyautogui.mouseDown()
        inventory_workspace = inventory.get_workspace()
        mouse.move(
            (inventory_workspace['left'],
             inventory_workspace["top"] + inventory_workspace["height"]), 2)
        pyautogui.mouseUp()
        time.sleep(random() * 2.5)
        pyautogui.press('enter')

        # Add resources to Crafting window and combine it
        s_b = inventory.find_item(item="media/items/stone_shards.png")
        mouse.move((s_b[0][0], s_b[0][1]), 2)
        pyautogui.mouseDown()
        r_p = t.get_resource_position()
        mouse.move(r_p, 2)
        pyautogui.mouseUp()
Beispiel #36
0
 def mouseDownAction( self, button='left' ):
     print( "----------> HOLDING DOWN MOUSE " + button )
     pyautogui.mouseDown( button=button )
Beispiel #37
0
def start_mouse():

    with open("range.pickle", "rb") as f:

        t = pickle.load(f)

    cam = cv2.VideoCapture(1)

    if cam.read()[0] == False:

        cam = cv2.VideoCapture(0)

    lower = np.array([t[0], t[1], t[2]])  # HSV green lower

    upper = np.array([t[3], t[4], t[5]])  # HSV green upper

    screen_width, screen_height = gui.size()

    frame_width, frame_height = 640, 480

    cam.set(cv2.CAP_PROP_FRAME_WIDTH, frame_width)

    cam.set(cv2.CAP_PROP_FRAME_HEIGHT, frame_height)

    center, old_center = [[0, 0]] * 2, [[
        0, 0
    ]] * 2  # center of 2 fingers together or 2 fingers separate

    area1 = area2 = 0

    damping = 0.5

    sx, sy = (screen_width / frame_width) / damping, (screen_height /
                                                      frame_height) / damping

    is_mouse_down = False

    # flags for 0 fingers, 1 finger and 2 finger

    flags = [True, False, False]

    # frame count for 0 fingers, 1 finger and 2 fingers

    finger_frame_count = [0, 0, 0]

    while True:

        _, img = cam.read()

        img = cv2.flip(img, 1)

        imgHSV = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)

        mask = cv2.inRange(imgHSV, lower, upper)

        blur = cv2.medianBlur(mask, 15)

        blur = cv2.GaussianBlur(blur, (5, 5), 0)

        thresh = cv2.threshold(blur, 0, 255,
                               cv2.THRESH_BINARY + cv2.THRESH_OTSU)[1]

        contours = cv2.findContours(thresh.copy(), cv2.RETR_TREE,
                                    cv2.CHAIN_APPROX_NONE)[1]

        mposx, mposy = gui.position()

        #print(flags)

        if len(contours) >= 2:

            old_center[0] = center[0]

            if is_mouse_down:

                Thread(target=gui.mouseUp, args=()).start()

                is_mouse_down = False

            # if left click was done

            if flags[1] == True:

                is_mouse_down = False

                # do a right click if the fingers were together for 10-20 frames and then released

                if finger_frame_count[1] >= 10 and finger_frame_count[1] <= 20:

                    gui.rightClick()

                # else if fingers were together for less than 10 frames then do a left click

                elif finger_frame_count[1] < 10:

                    gui.click()

                finger_frame_count[1] = 0

            finger_frame_count[2] += 1

            c1, c2 = top(contours, cv2.contourArea, 2)

            rect1 = cv2.minAreaRect(c1)

            (w, h) = rect1[1]

            area1 = w * h

            center1 = np.int0(rect1[0])

            box = cv2.boxPoints(rect1)

            box = np.int0(box)

            cv2.drawContours(img, [box], 0, (0, 0, 255), 2)

            rect2 = cv2.minAreaRect(c2)

            (w, h) = rect2[1]

            area2 = w * h

            center2 = np.int0(rect2[0])

            box = cv2.boxPoints(rect2)

            box = np.int0(box)

            cv2.drawContours(img, [box], 0, (0, 0, 255), 2)

            center[0] = np.int0((center1 + center2) / 2)

            cv2.line(img, tuple(center1), tuple(center2), (255, 0, 0), 2)

            cv2.circle(img, tuple(center[0]), 2, (255, 0, 0), 3)

            if not flags[0]:

                if np.any(abs(center[0] - old_center[0]) > 5):

                    Thread(target=gui.moveTo, args=(mposx+(center[0][0]-old_center[0][0])*sx, mposy + (center[0][1]-old_center[0][1])*sy,\

                     0.1, gui.easeInOutQuad)).start()

            flags = [False, False, True]

        elif len(contours) >= 1:

            old_center[1] = center[1]

            c1 = max(contours, key=cv2.contourArea)

            rect1 = cv2.minAreaRect(c1)

            (w, h) = rect1[1]

            area3 = w * h

            center[1] = np.array(rect1[0])

            box = cv2.boxPoints(rect1)

            box = np.int0(box)

            cv2.drawContours(img, [box], 0, (0, 0, 255), 2)

            error = abs((area1 + area2 - area3) / area3 * 100)

            if (error < 40):

                finger_frame_count[1] += 1

                # do a left click and hold if the fingers were together for more than 20 frames

                if finger_frame_count[1] > 20:

                    if not is_mouse_down:

                        gui.mouseDown()

                        is_mouse_down = True

                    if np.any(abs(center[1] - old_center[1]) > 5):

                        Thread(target=gui.moveTo, args=(mposx+(center[1][0]-old_center[1][0])*sx, mposy + (center[1][1]-old_center[1][1])*sy, \

                            0.1, gui.easeInOutQuad)).start()

                flags = [False, True, False]

            else:

                flags = [True, False, False]

        else:

            if is_mouse_down:

                Thread(target=gui.mouseUp, args=()).start()

                thread.start_new_thread(gui.mouseUp, ())

                is_mouse_down = False

            flags = [True, False, False]

        cv2.imshow("Virtual Mouse", img)

        if cv2.waitKey(1) == ord('q'):

            break

    cam.release()

    cv2.destroyAllWindows()

    gui.mouseUp()
                 pyautogui.press('enter')
                 time.sleep(15)
                 hwnd = win32gui.FindWindow(None, '魔兽世界')
                 if hwnd:
                     aw = win32gui.GetForegroundWindow()
                     if aw != hwnd:
                         try:
                             win32gui.SetForegroundWindow(hwnd)
                             time.sleep(2)
                         except Exception as e:
                             print(e)
                     img = ImageGrab.grab()
                     center = get_coordinate(paths[2], img)
                     if center:
                         pyautogui.mouseDown(center[0],
                                             center[1],
                                             button='left')
                         pyautogui.mouseUp(button='left')
                         time.sleep(20)
         else:
             print('请运行战网')
 else:
     if hwnd_battle:
         aw = win32gui.GetForegroundWindow()
         if aw != hwnd_battle:
             try:
                 win32gui.SetForegroundWindow(hwnd_battle)
                 time.sleep(2)
             except Exception as e:
                 print(e)
         pyautogui.press('enter')
Beispiel #39
0
def arraste_coordenada(xi, yi, xf, yf):
    # Objetivo: Realizar um evento de arraste com o mouse
    # Parametro: passar as coordenadas iniciais e as finais
    pyautogui.mouseDown(x=xi, y=yi, button='left')
    pyautogui.dragTo(x=xf, y=yf, duration=0)
Beispiel #40
0
def close_menu():
    location = page.locateCenterOnScreen('resources/close_all.png',
                                         confidence=0.9)
    page.moveTo(location)
    page.mouseDown()
    page.mouseUp()
def click_right(delay=.1):
    auto.mouseDown(button='right')
    time.sleep(delay)
    auto.mouseUp(button='right')
Beispiel #42
0
 def do_stabilize_steering(self):
     pyautogui.moveTo(960, 540)
     sleep(.1)
     pyautogui.mouseDown()
     pyautogui.mouseUp()
Beispiel #43
0
def click_in_crowfall():
    reset_location = (1742, 1116)
    page.moveTo(reset_location)
    page.mouseDown()
    page.mouseUp()
Beispiel #44
0
 def do_refuel_station(self):
     pyautogui.moveTo(1470, 890)
     pyautogui.mouseDown()
     sleep(3.1)
     pyautogui.mouseUp()
Beispiel #45
0
def drag_ball_to(x, y):
    pg.mouseDown()
    autopy.mouse.smooth_move(x, y)
    # Small cooldown to avoid ball slide away
    sleep(0.2)
    pg.mouseUp()
Beispiel #46
0
 def do_fuel_engines(self):
     pyautogui.moveTo(1470, 890)
     pyautogui.mouseDown()
     sleep(3.1)
     pyautogui.mouseUp()
Beispiel #47
0
def performAction( yp, rc, bc, action, drag, perform):
    if perform:
        cursor[0] = 4*(yp[0]-110)
        cursor[1] = 4*(yp[1]-120)
        if action == 'move':

            if yp[0]>110 and yp[0]<590 and yp[1]>120 and yp[1]<390:
                pyautogui.moveTo(cursor[0],cursor[1])
            elif yp[0]<110 and yp[1]>120 and yp[1]<390:
                pyautogui.moveTo( 8 , cursor[1])
            elif yp[0]>590 and yp[1]>120 and yp[1]<390:
                pyautogui.moveTo(1912, cursor[1])
            elif yp[0]>110 and yp[0]<590 and yp[1]<120:
                pyautogui.moveTo(cursor[0] , 8)
            elif yp[0]>110 and yp[0]<590 and yp[1]>390:
                pyautogui.moveTo(cursor[0] , 1072)
            elif yp[0]<110 and yp[1]<120:
                pyautogui.moveTo(8, 8)
            elif yp[0]<110 and yp[1]>390:
                pyautogui.moveTo(8, 1072)
            elif yp[0]>590 and yp[1]>390:
                pyautogui.moveTo(1912, 1072)
            else:
                pyautogui.moveTo(1912, 8)

        elif action == 'left':
            pyautogui.click(button = 'left')

        elif action == 'right':
            pyautogui.click(button = 'right')
            time.sleep(0.3) 

        elif action == 'up':
            pyautogui.scroll(5)
#           time.sleep(0.3)

        elif action == 'down':
            pyautogui.scroll(-5)            
#           time.sleep(0.3)

        elif action == 'drag' and drag == 'true':
            global y_pos
            drag = 'false'
            pyautogui.mouseDown()
        
            while(1):

                k = cv2.waitKey(10) & 0xFF
                changeStatus(k)

                _, frameinv = cap.read()
                # flip horizontaly to get mirror image in camera
                frame = cv2.flip( frameinv, 1)

                hsv = cv2.cvtColor( frame, cv2.COLOR_BGR2HSV)

                b_mask = makeMask( hsv, blue_range)
                r_mask = makeMask( hsv, red_range)
                y_mask = makeMask( hsv, yellow_range)

                py_pos = y_pos 

                b_cen = drawCentroid( frame, b_area, b_mask, showCentroid)
                r_cen = drawCentroid( frame, r_area, r_mask, showCentroid)  
                y_cen = drawCentroid( frame, y_area, y_mask, showCentroid)
            
                if  py_pos[0]!=-1 and y_cen[0]!=-1:
                    y_pos = setCursorPos(y_cen, py_pos)

                performAction(y_pos, r_cen, b_cen, 'move', drag, perform)                   
                cv2.imshow('Frame', frame)

                if distance(y_pos,r_cen)>60 or distance(y_pos,b_cen)>60 or distance(r_cen,b_cen)>60:
                    break

            pyautogui.mouseUp()
Beispiel #48
0
 def do_measure_weather(self):
     pyautogui.moveTo(1220, 852)
     pyautogui.mouseDown()
     pyautogui.mouseUp()
Beispiel #49
0
 def click_mouse_at_loc(x, y):
     pyautogui.moveTo(x, y, duration=0.3)
     pyautogui.mouseDown()
     time.sleep(0.2)
     pyautogui.mouseUp()
Beispiel #50
0
    def do_buy_beverage(self):
        x_locs = (480, 680, 880, 1080)
        y_locs = (270, 650, 990)

        beverage = (None, None)

        for drawing in os.listdir(self.main_path +
                                  "\\task_images\\buy_beverage\\drawings"):

            if self.debug:
                print(drawing)

            pos = imagesearch(self.main_path +
                              "\\task_images\\buy_beverage\\drawings\\" +
                              drawing,
                              precision=.6)

            if pos[0] != -1:
                beverage = (pos, drawing)

        beverage_to_get = [
            imagesearch_loop(
                self.main_path + "\\task_images\\buy_beverage\\beverages\\" +
                beverage[1], 0), 0, 0
        ]

        if self.debug:
            print(f"need to get {beverage}")
            print(beverage_to_get)

        letters = [(1240, 400), (1350, 400), (1480, 400)]
        numbers = [(1240, 520), (1350, 520), (1480, 520), (1350, 640)]

        if beverage_to_get[0][0] < x_locs[0]:
            beverage_to_get[1] = 0

        elif beverage_to_get[0][0] < x_locs[1]:
            beverage_to_get[1] = 1

        elif beverage_to_get[0][0] < x_locs[2]:
            beverage_to_get[1] = 2

        elif beverage_to_get[0][0] < x_locs[3]:
            beverage_to_get[1] = 3

        if beverage_to_get[0][1] < y_locs[0]:
            beverage_to_get[2] = 0

        elif beverage_to_get[0][1] < y_locs[1]:
            beverage_to_get[2] = 1

        elif beverage_to_get[0][1] < y_locs[2]:
            beverage_to_get[2] = 2

        pyautogui.moveTo(letters[beverage_to_get[2]][0],
                         letters[beverage_to_get[2]][1])
        pyautogui.mouseDown()
        pyautogui.mouseUp()

        pyautogui.moveTo(numbers[beverage_to_get[1]][0],
                         numbers[beverage_to_get[1]][1])
        pyautogui.mouseDown()
        pyautogui.mouseUp()

        pyautogui.moveTo(1475, 645)
        pyautogui.mouseDown()
        pyautogui.mouseUp()
Beispiel #51
0
import pyautogui
import random

while True:
    i = random.randint(0, 2000)
    ii = random.randint(0, 2000)
    pyautogui.mouseDown(i, ii)
def click_left(delay=.1):
    auto.mouseDown()
    time.sleep(delay)
    auto.mouseUp()
Beispiel #53
0
def showall():
    pyautogui.moveTo(1329, 298)
    pyautogui.mouseDown()
    time.sleep(1)
    pyautogui.mouseUp()
Beispiel #54
0
def sellBoardUnit(champ,boardChamps,completeBoard):
    pyautogui.mouseDown(x=completeBoard[champ[1]][0],y=completeBoard[champ[1]][1], button='left')
    pyautogui.mouseUp(x=completeBoard[champ[1]][0],y=completeBoard[champ[1]][1], button='left')
    pyautogui.dragTo(940, 1000, 0.13, button='left')
    boardChamps.remove(champ)
    return boardChamps
Beispiel #55
0
def assemble():
    # Click Assemble
    assemble_loc = page.locateCenterOnScreen('resources/assemble.png',
                                             confidence=0.9)
    page.moveTo(assemble_loc)
    page.mouseDown(button='left')
    page.mouseUp(button='left')
    time.sleep(1)

    # Click Next
    next_loc = page.locateCenterOnScreen('resources/next.png', confidence=0.9)
    if next_loc:
        page.moveTo(next_loc)
        page.mouseDown(button='left')
        page.mouseUp(button='left')
        time.sleep(1)

    # Click Make Item
    make_loc = page.locateCenterOnScreen('resources/make_item.png',
                                         confidence=0.9)
    if make_loc:
        page.moveTo(make_loc)
        page.mouseDown(button='left')
        page.mouseUp(button='left')
        time.sleep(1)
    else:
        make_loc = page.locateCenterOnScreen('resources/make_item_2.png',
                                             confidence=0.9)
        if make_loc:
            page.moveTo(make_loc)
            page.mouseDown(button='left')
            page.mouseUp(button='left')
            time.sleep(1)
        else:
            return False

    # Click Take Item
    take_loc = page.locateCenterOnScreen('resources/take.png', confidence=0.9)
    if take_loc:
        page.moveTo(take_loc)
        page.mouseDown(button='left')
        page.mouseUp(button='left')
        time.sleep(1)
    else:
        take_loc = page.locateCenterOnScreen('resources/take2.png',
                                             confidence=0.9)
        if take_loc:
            page.moveTo(take_loc)
            page.mouseDown(button='left')
            page.mouseUp(button='left')
            time.sleep(1)
        else:
            return False

    return True
Beispiel #56
0
def testBoard(boardArray):
    for position in boardArray:
        pyautogui.dragTo(position[0], position[1], 0.13, button='left')
        pyautogui.mouseDown(x=position[0],y=position[1], button='left')
        pyautogui.mouseUp(x=position[0],y=position[1], button='left')
Beispiel #57
0
 def execute(self):
     pyautogui.mouseDown(self.lever_start)
     pyautogui.move(*self.lever_len, self.lever_time)
     time.sleep(self.lever_hold)
     pyautogui.mouseUp()
Beispiel #58
0
def mouse_down(button='left'):
    pyautogui.mouseDown(button=button)
Beispiel #59
0
    )
    time.sleep(10)

    print(
        "The mouse starts to draw from now. Incase you find problems here, move the cursor to the left-top corner of the screen. The program will exit with an error."
    )
    timer1 = time.time()

    for i in range(0, len(vdata)):
        xdisplace = 100
        ydisplace = 200
        k = vdata[i]
        y = k[0]
        x = k[1]
        if (y == 'S' and i != 0):
            pag.mouseDown()
        if (y == 'E'):
            pag.mouseUp()
        if (y != 'S' and y != 'E'):
            x = (resizex) * x + xdisplace
            y = (resizey) * y + ydisplace
            pag.moveTo(x, y)

    print("Drawing finished.")
    timer2 = time.time()

    totaltime = timer2 - timer1

    totalhours = int(totaltime / 3600)
    totalmins = int(totaltime / 60)
Beispiel #60
-30
 def shield_charge(self, duration):
     """Shield Charge moves player forward and knocks back the enemies"""
     duration = random.uniform(duration - 1.5, duration + 1.5)
     pyautogui.mouseDown(self.F)
     time.sleep(duration)
     pyautogui.mouseUp()
     self.heal()