Esempio n. 1
0
 def drag(self, x1, y1, x2, y2):
     x1 = int(x1)
     y1 = int(y1)
     x2 = int(x2)
     y2 = int(y2)
     mouse.move(x1, y1)
     mouse.drag(x1, y1, x2, y2, duration=self.click_delay)
Esempio n. 2
0
def moveP1ToP2(point1, point2):
    mouse.drag(point1[0],
               point1[1],
               point2[0],
               point2[1],
               absolute=True,
               duration=0.005)
Esempio n. 3
0
def go_scroll_location(scrolls):
    for index in range(0, scrolls):
        __mouse_move(__window_info.width * 0.9,
                     __window_info.height * __random_deviation(0.5))
        mouse.drag(__window_info.width * 0.9,
                   __window_info.height * __random_deviation(0.5),
                   __window_info.width * 0.1,
                   __window_info.height * __random_deviation(0.5),
                   duration=__random_speed())
        sleep(__random_deviation(0.4))
Esempio n. 4
0
def drag_at(h_wnd: int,
            point: Tuple[int, int],
            *,
            dx: int,
            dy: int,
            duration: float = 1):
    x, y = win32gui.ClientToScreen(h_wnd, point)
    with topmost(h_wnd), recover_foreground(), recover_cursor():
        mouse.drag(x, y, x + dx, y + dy, duration=duration)
        move_at(h_wnd, (-1, -1))
        time.sleep(0.05)
Esempio n. 5
0
def start_game(start_img_path):
    while not check_image(start_img_path):
        time.sleep(5)
    click_image(start_img_path)

    while not check_image("rc_items/start_game.png"):
        time.sleep(1)
    sx, sy = find_image("rc_items/start_game.png", screen_grab())
    mpos = mouse.get_position()
    mouse.drag(mpos[0], mpos[1], sx + 2, sy + 2, absolute=True, duration=0)
    mouse.click("left")
    time.sleep(3)
Esempio n. 6
0
def drawStart(relstartX, relstartY, relfinalX, relfinalY):
    startX = int(relstartX) + 5
    startY = int(relstartY) + 150
    xF = int(relfinalX) + 5
    yF = int(relfinalY) + 150

    if (xF < 5):
        xF = 5
    if (yF < 150):
        yF = 150
    if (xF > 965):
        xF = 965
    if (yF > 730):
        yF = 730

    mouse.drag(startX, startY, xF, yF)
Esempio n. 7
0
def draw(xModif, yModif):
    x = mouse.get_position()[0]
    y = mouse.get_position()[1]
    xF = x + int(xModif)
    yF = y + int(yModif)

    if (xF < 5):
        xF = 5
    if (yF < 150):
        yF = 150
    if (xF > 965):
        xF = 965
    if (yF > 730):
        yF = 730

    mouse.drag(x, y, xF, yF)
Esempio n. 8
0
def click_image(img):
    time.sleep(0.1)
    x, y = find_image(img, screen_grab())
    if x is None or y is None:
        return
    mpos = mouse.get_position()

    im = cv2.imread(img)
    trows, tcols = im.shape[:2]

    mouse.drag(mpos[0],
               mpos[1],
               x + tcols * (3 / 5),
               y + trows * (2 / 3),
               absolute=True,
               duration=0)
    time.sleep(0.2)
    mouse.click("left")
Esempio n. 9
0
def make_bet(color, amount):
    mouse.move(coord.bet_amount_right_x - 5, coord.bet_amount_right_y, True,
               0.1)
    time.sleep(0.1)
    mouse.drag(coord.bet_amount_right_x, coord.bet_amount_right_y,
               coord.bet_amount_left_x, coord.bet_amount_left_y, True, 0.5)
    time.sleep(0.5)
    keyboard.write(str(amount), 0.5)
    keyboard.press_and_release('enter')
    time.sleep(0.25)
    if color == "red":
        mouse.move(coord.bet_red_x, coord.bet_red_y, True, 0.2)
        mouse.double_click('left')
        time.sleep(0.5)
        mouse.move(coord.rest_x, coord.rest_y + 50, True, 1)
        time.sleep(4)
    elif color == 'black':
        mouse.move(coord.bet_black_x, coord.bet_black_y, True, 0.2)
        mouse.double_click('left')
        time.sleep(0.5)
        mouse.move(coord.rest_x, coord.rest_y + 50, True, 1)
        time.sleep(4)
Esempio n. 10
0
def desenhar(nome_imagem: str):

    # The directory containing this file
    HERE = os.path.abspath(os.path.dirname(__file__))

    # The text of the README file
    with open(os.path.join(HERE, F"desenhos/{nome_imagem}.txt")) as fid:
        DESENHO = fid.read()

    flag_levantado = True
    for line in DESENHO.splitlines():

        partes_line = line.split()
        if len(partes_line) < 2:
            continue

        if 'Z5' in partes_line[1]:
            flag_levantado = True

        elif 'Z-' in partes_line[1]:
            flag_levantado = False

        if 'X' in partes_line[1]:
            x, y = [
                int(float(coord.replace('X', '').replace('Y', '')))
                for coord in partes_line[1:3]
            ]

            if flag_levantado:
                pyautogui.moveTo(x + 100, y + 100, .2)

            else:
                start_x, start_y = mouse.get_position()
                mouse.drag(start_x,
                           start_y,
                           x + 100,
                           y + 100,
                           absolute=True,
                           duration=float(1 * 10**-250))
Esempio n. 11
0
def scroll_to_end_of_collection():
    raid_screenshot = get_screen()
    height, width, _ = raid_screenshot.shape
    template_pixel = raid_screenshot[height - 2, width - 2]
    template_pixel_tuple = uint8(template_pixel)
    top_rect_collection = 0
    for y in range(height - 2, 0, -1):
        if (raid_screenshot[y, width - 2] != template_pixel).any():
            top_rect_collection = y
            break
    cropped = raid_screenshot[top_rect_collection:height, :]
    mask = cv2.inRange(cropped, template_pixel_tuple, template_pixel_tuple)
    kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (2, 2))
    mask = cv2.morphologyEx(mask, cv2.RETR_TREE, kernel)
    contours, _ = cv2.findContours(mask, cv2.RETR_TREE,
                                   cv2.CHAIN_APPROX_SIMPLE)
    contours = [cv2.boundingRect(cnt) for cnt in contours]
    most_right_cnt = max(contours, key=lambda cnt: cnt[0])
    x, y, w, h = most_right_cnt
    y = y + int(h / 2)
    x = x - 5
    while mask[y, x] == 255:
        x = x - 1
    y = top_rect_collection + int(cropped.shape[0] / 2)
    thr_check = CollectionCheckThread(template_pixel_tuple,
                                      top_rect_collection)
    thr_check.start()
    while thr_check.is_alive():
        mouse.move(__window_info.x + x - 20,
                   __window_info.y + y + __border_height,
                   duration=0.7)
        mouse.drag(__window_info.x + x - 20,
                   __window_info.y + y + __border_height,
                   __window_info.x + 20,
                   __window_info.y + y + __border_height,
                   duration=1.5)
    thr_check.join()
    sleep(0.5)
Esempio n. 12
0
def __click_level():
    global level
    if level > 4:
        mouse.move(__window_info.center()[0],
                   __window_info.y + __window_info.height * 0.6,
                   duration=__random_speed())
        mouse.drag(__window_info.center()[0],
                   __window_info.y + __window_info.height * 0.6,
                   __window_info.center()[0],
                   __window_info.y + __window_info.height * 0.3,
                   duration=__random_speed())
    sleep(__random_speed())
    raid_screenshot = get_screen()
    position = search_module.get_level_position(raid_screenshot, level)
    btn_position = search_module.get_start_btn_from_level(
        raid_screenshot[position.y:position.y + position.height,
                        position.x:position.x + position.width])
    btn_position.x = position.x + btn_position.x
    btn_position.y = position.y + btn_position.y
    mouse.move(__window_info.x + btn_position.center()[0],
               __window_info.y + btn_position.center()[1] + __border_height,
               __random_speed())
    mouse.click()
    sleep(__random_deviation(0.5))
Esempio n. 13
0
import keyboard
import mouse
import time
import os

paint_path = "C:\WINDOWS\system32\mspaint.exe"
os.startfile(paint_path)
# wait for paint to start
time.sleep(2)

mouse.move(-100000, -1000000, absolute=False, duration=0.1)
mouse.move(200, 200, absolute=False, duration=0.1)

mouse.drag(0, 0, 600, 0, absolute=False, duration=0.3)
mouse.drag(0, 0, 0, 350, absolute=False, duration=0.3)
mouse.drag(0, 0, -600, 0, absolute=False, duration=0.3)
mouse.drag(0, 0, 0, -350, absolute=False, duration=0.3)
mouse.drag(0, 350 / 3, 600, 0, absolute=False, duration=0.3)
mouse.drag(0, 350 / 3, -600, 0, absolute=False, duration=0.3)
mouse.drag(300, 0, 0, -350 / 3, absolute=False, duration=0.3)
mouse.drag(-350 / 6, 350 / 6, 350 / 3, 0, absolute=False, duration=0.3)

#circle
mouse.move(-100000, -1000000, absolute=False, duration=0.1)
mouse.move(391, 57, absolute=False, duration=0.1)
mouse.click('left')
mouse.drag(50, 260, 350 / 3, 337 / 3, absolute=False, duration=0.2)
#fill
mouse.move(-100000, -1000000, absolute=False, duration=0.1)
mouse.move(252, 67, absolute=False, duration=0.1)
mouse.click('left')
Esempio n. 14
0
mouse.click('right')

# middle click
mouse.click('middle')

# get the position of mouse
print(mouse.get_position())
# In [12]: mouse.get_position()
# Out[12]: (714, 488)

# presses but doesn't release
mouse.hold('left')
# mouse.press('left')

# drag from (0, 0) to (100, 100) relatively with a duration of 0.1s
mouse.drag(0, 0, 100, 100, absolute=False, duration=0.1)

# whether a button is clicked
print(mouse.is_pressed('right'))

# move 100 right & 100 down
mouse.move(100, 100, absolute=False, duration=0.2)

# make a listener when left button is clicked
mouse.on_click(lambda: print("Left Button clicked."))
# make a listener when right button is clicked
mouse.on_right_click(lambda: print("Right Button clicked."))

# remove the listeners when you want
mouse.unhook_all()
Esempio n. 15
0
def zoomin():
  mouse.click(164,407)
  time.sleep(wait)

def zoomin():
  mouse.click(164,446)
  time.sleep(wait)


### main

# down 1-12
# home 13
# up   14-28

# zoomlevel from home to down 12
# home 13
# to up 14

# TODO back level arg
back()
# back()
# back()
# shapes()

# mouse.click(326,512)
# mouse.click(731,447)

mouse.drag(1034,113,1034,719)
def doJob(name, centercoords, mapdir):
    rootdir = os.path.join(os.getcwd() + images + '\\' + majorIncidentPubba + 'jobs\\')
    inProgress = 'NONE' #Determines if we had a job get interrupted, i.e. by reporting a body
    #---------------------------------------------------------------------
    #initialize job-specific variables
    #note that these coordinates are based on running the game at 1920 x 1200 resolution.
    #centercoords is the x,y coordinates returned from determineTaskList's pyscreeze function
    gascanfillemptybuttoncoords = (1500, 1005)#Could use pagui.locateCenter but right now we're fine with coords (faster)
    asteroidscreenupcheckcoords = (546, 1001)#Makes sure the asteroid task window is still open
    ASTEROIDS_REGION = (501, 200, 890, 889)#Bounding region for asteroid window, x,y,width,height
    ELECTRICAL_RED_PULLSWITCH_COLOR = (255, 98, 0)
    ENGINEALIGNMENT_CENTER = (1300, 592)
    ENGINEALIGNMENT_LOCATIONS = [(1371,212),(1329,328),(1297,448),(1284,575),(1285,692),(1295,794),(1328,906),(1353,995),(1376,1062),(1312, 864),(1286, 694)]
    ENGINEALIGNMENT_COLOR = (66,65,66)
    #Left to right
    ELECTRICAL_RED_PULLSWITCH_LOCATIONS = [(583, 870),(688, 872),(798, 872),(905, 870),(1011, 874),(1118, 875),(1224, 875),(1335, 874)]
    LEAFBLOWERSTARTPOS = (693, 137)
    LEAFVENTCENTER = (483, 561)
    LEVERLOCATION = (1302, 467)
    NAVSHIPSTART = (588, 302)#Upper left corner of the navship screen
    GRIDTOWATCH = []#For matching the blue squares, the location where each 
    BUTTONGRID = []
    COLOREDWIRES = [(38,38,255), (255,0,0), (255,0,255), (255,235,4)]#Blue, Red, Pink and Yellow resp.
    WIRELCOORDS = [(518, 302), (522, 509), (522,716), (523,925)]#Top to bottom left destinations.
    WIRERCOORDS = [(1358,298), (1359, 508), (1358 ,720), (1350, 926)]#Top to bottom right destinations
    SHIELDEDGES = [(696,612), (1205,334),(961,193),(702,327),(953,475),(961,469),(1201,617), (953,758), (719,331), (703,613)]
    SPINWHEELPAIRS = [((1265, 251),(0,0,0),(1266,344)),((1265,556),(0,0,0),(1252,645)),((1262, 850),(0,0,0),(1257,927))]
    #^ For the electrical spinning wheels. The middle entry is to detect when the button should be clicked (the bar only lights up at the right time)
    locs = [(705, 937), (837, 947), (962, 936), (1087, 940), (1210, 939)]#Both locs and testLoc are for test tubes
    testLoc = [(704, 650), (832, 647), (961, 648), (1091, 649), (1210, 650)]
    TESTTUBEORIGIN = (1290,1036)#The square button to press
    #For the reactor bluu squares
    REACTMONITOR = (427, 473, 813, 856)
    LASTLIGHT = [(1482,352),(0,192,0)]#First val is xy, second is rgb value
    #--------------------------------------------------------------------
    
    #strip filename to match method
    shorthand = name.removesuffix('.png')
    #Determine and run job
    #Checks at the end of doJob for any issues
    if not inProgress == 'NONE':
        print(inProgress + ' in progress!')
    else:
        inProgress = shorthand
    #
    if shorthand == 'gascan' or shorthand == 'refuel':
        #Pathing is simple, gascan is always in the storage room and the engines never move
        #Only thing would be 'guessing' which engine first. Possibly get angle of yellow arrow?
        print('Committing to gascan / refuel task!')
        m.move(gascanfillemptybuttoncoords[0], gascanfillemptybuttoncoords[1],True,0)
        m.press()
        time.sleep(4)
        m.release()
        k.send('escape')
        time.sleep(1.7)
        return
    if shorthand == 'downloadbtn' or shorthand == 'uploadbtn':
        #Simply clicking the button then waiting 8 seconds.
        print('Committing to upload / download task!')
        m.move(centercoords[0], centercoords[1])
        m.click()
        time.sleep(8)
        k.send('escape')
        time.sleep(1.7)
        return
    if shorthand == '1to10':
        #Finding 1 through ten and clicking them in order
        #We need to get the mouse out of the way to make sure that its not highlighting anything
        print('Committing to the sequence task')
        m.move(centercoords[0],centercoords[1])#The image we have for this task will center the mouse on the top bar, away from the buttons
        sequence = []#sigma male
        for i in range(10):
            #Identify the current number location then save the coordinates
            val = ps5.locateCenterOnScreen(rootdir + str(i+1) + '.png', confidence=0.9)
            print(str(val))
            if not val == None:
                print('Found element ' + str(i) + ' at location ' + str(val) + '.')
                #The array is already ordered, no sorting needs to be done. This is essentially guaranteed unless filenames get changed in \traininig\
                sequence.append((val[0], val[1]))
        for button in sequence:#This array/loop structure is moreso here to animate the mouse on this task and make it look cooler
            #You could easily just move and click inside of the original loop if you don't want to be fancy.
            #Button is a tuple of (i, (x,y))
            m.move(button[0],button[1],True,0.2)
            m.click()
        k.send('escape')
        time.sleep(1.7)
        return
    if shorthand == 'adminswipecard':
        #Swiping the card in admin is actually pretty easy
        print('Committing to swiping the card in admin')
        val = ps5.locateCenterOnScreen(rootdir + 'pocketedcard.png')
        print(str(val))
        if not val == None:
            m.move(val[0],val[1])
            m.press()
            m.move(0, -500, False, 0.7)
            m.release()
            time.sleep(0.7)
        else:
            print('What? cannot find the card?')
        val2 = ps5.locateCenterOnScreen(rootdir + 'id.png')
        print(str(val2))
        if not val2 == None:
            m.move(val2[0]-100, val2[1]-180)
            m.drag(val2[0]-100, val2[1]-180, 1000, 0, False, 0.3)
        else:
            print('Sorry, can\'t find the id picture for some reason?')
        k.send('escape')
        time.sleep(1.7)
        return
    if shorthand == 'centercrosshairs':
        #Moving the crosshairs into the center of the screen
        print('Committing to moving the crosshairs to the middle!')
        print('TODO: Add crosshairmove functionality')
        centercoords = ps5.locateCenterOnScreen(rootdir + 'centercrosshairs.png', grayscale=True, confidence=0.7)
        m.move(centercoords[0],centercoords[1],True,0.4)
        m.drag(centercoords[0],centercoords[1],DESTINATIONCOORDS[0],DESTINATIONCOORDS[1],True,0.6)
        k.send('escape')
        time.sleep(1.7)
        return
    if shorthand == '1_crosshairs':
        #My nemesis, those dang assteroids
        print('Committing to shooting asteroids')
        #Detect motion is probably the best method for this
        #Nah we're looking for colors again
        while True:
            target = pagui.locateOnScreen(rootdir + 'asteroid.png', region=ASTEROIDS_REGION, confidence=0.8)
            if not target == None:
                m.move(target[0], target[1]-5,0.1)
                m.click()
            #pixelMatchesColor is not working in python 3.9
            val = pagui.locateOnScreen(mapdir + '1_crosshairs.png', grayscale=True, confidence=0.8)
            if val == None:
                print('Asteroid task complete')
                break
        k.send('escape')
        count = 0
        time.sleep(1.7)
        return
    if shorthand == 'electricalslidingbars':
        #Slide the red-highlighted slider vertically up
        print('Committing to the red slider task')
        for switch in ELECTRICAL_RED_PULLSWITCH_LOCATIONS:
            m.move(switch[0]-30,switch[1],True,0.3)
            spot = m.get_position()
            pix = ImageGrab.grab().load()[spot[0], spot[1]]
            if pix[0] >= 200:
                m.press()
                m.move(0,-600,False,0.2)
                m.release()
                break
        k.send('escape')
        time.sleep(1.7)
        return
    if shorthand == 'enginealignment':
        #Aligning the engine outline to match the middle line
        #Could check to see when green, green only appears near the middle when lined up.
        print('Comitting to enginealignment')
        for location in ENGINEALIGNMENT_LOCATIONS:
            m.move(location[0], location[1])
            pix = ImageGrab.grab().load()[location[0], location[1]]
            if not pix[0] == ENGINEALIGNMENT_COLOR[0] and pix[1] == ENGINEALIGNMENT_COLOR[1]:
                m.press()
                m.move(ENGINEALIGNMENT_CENTER[0],ENGINEALIGNMENT_CENTER[1],True,0.8)
                m.release()
        k.send('escape')
        time.sleep(1.7)
        return
    if shorthand == 'fusebox':
        #Clicking the middle fuse, wayyyy to complex :)
        m.move(centercoords[0],centercoords[1],True,0.3)
        time.sleep(0.4)
        m.click()
        k.send('escape')
        time.sleep(1.7)
        return
    if shorthand == 'leafvent':
        #Move the leaves into the trash vent
        print('Comitting to leaf vent task')
        #Surprisingly one of the most complex tasks ever
        m.move(LEAFBLOWERSTARTPOS[0],LEAFBLOWERSTARTPOS[1], 0.6)
        for y in range(0, 13):
            m.move(0, 60, False)
            for x in range(0, 15):
                m.move(50, 0, False)
                pix = ImageGrab.grab().load()[m.get_position()[0], m.get_position()[1]]
                if pix[2] < 100:#Only the leaves have a blue value less than 100
                    print('Found a leaf! with ' + str(pix[0]) + ', ' + str(pix[1]) + ', ' + str(pix[2]) + '.')
                    cords = m.get_position()
                    m.press()
                    m.move(LEAFVENTCENTER[0],LEAFVENTCENTER[1],True,0.2)
                    m.release()
                    m.move(cords[0],cords[1], 0.2)
            m.move(-750, 0, False, 0.1)    
        k.send('escape')
        time.sleep(1.7)
        return
    if shorthand == 'leverjob':
        #Pull the lever kronk!
        print('Comitting to lever pulling task')
        m.move(LEVERLOCATION[0], LEVERLOCATION[1])
        m.press()
        m.move(0, 1000, False, 0.4)#Animating here is necessary or the game wont register the lever moving
        time.sleep(3.5)#Have to hold the lever for this timee
        m.release()
        k.send('escape')
        time.sleep(1.7)
        return
    if shorthand == 'navshipup' or shorthand == 'navshipdown':
        #Drag the navigation ship up
        print('Comitting to navship task')
        #Find the locations
        POINTS = []
        m.move(NAVSHIPSTART[0], NAVSHIPSTART[1], 0.1)
        x = NAVSHIPSTART[0]
        y = NAVSHIPSTART[1]
        dist = 0
        ship = []
        #Find the ship
        yy = 302
        inc = 12
        m.move(540, 302, True)
        while yy < 890:
            x, yy = m.get_position()
            pix = ImageGrab.grab().load()[x, yy]
            if pix[0] < 40 and pix[0] > 36:
                print('appending the ship at: ' + str(m.get_position()) + str(pix[0]))
                ship.append((m.get_position()[0],m.get_position()[1]))
                break
            m.move(0, inc, False)
            yy = yy + inc
            if yy >= 890:
                if len(ship) == 0:
                    inc = inc / 2
                    yy = 302
                    m.move(540, 302, True)   
        #this task alone has wasted two nights irl. why do i keep working on this
        print(str(ship))
        m.move(580, 302, True)
        while y < 890:
            while x < 1475:
                m.move(18, 0, False)
                dist = dist + 18
                x = m.get_position()[0]
                pix = ImageGrab.grab().load()[x, y]
                if pix[0] < 50 and pix[2] > 160:
                    print('appending : ' + str(pix[0]) + str(m.get_position()))
                    POINTS.append((x,y))
                    
            m.move(-dist, 69, False)
            x = m.get_position()[0]
            dist = 0
            y = m.get_position()[1]
            pix = ImageGrab.grab().load()[x, y]
        #Move the ship through
        m.move(ship[0][0], ship[0][1], True)#To where the ship was originally found
        x, y = m.get_position()
        m.press()
        POINTS.sort(key=lambda x: x[0])
        print(str(POINTS))
        for location in POINTS:
            m.move(location[0], location[1],True, 0.3)
            x, y = m.get_position()
            time.sleep(0.1)
        m.release()
        k.send('escape')
        time.sleep(1.7)
        return
    if shorthand == 'wires':
        colorOrder = []
        #Criss crossing the wires
        for cable in WIRELCOORDS:
            m.move(cable[0],cable[1],True,0.2)
            pix = ImageGrab.grab().load()[m.get_position()[0], m.get_position()[1]]
            for color in COLOREDWIRES:
                if pix == color:
                    colorOrder.append((pix ,(m.get_position()[0], m.get_position()[1])))
        print('Color order: ' + str(colorOrder))
        #Now we have the colors in order, we need to match them up!
        #colorOrder values: two tuples: ((color-of-pixel),(coordinateX,coordinateY))
        for leftcable in colorOrder:
            for cables in WIRERCOORDS:
                m.move(cables[0],cables[1],True,0.2)
                pix = ImageGrab.grab().load()[m.get_position()[0], m.get_position()[1]]
                if leftcable[0] == pix:#These lines need to connect
                    m.move(leftcable[1][0],leftcable[1][1])
                    m.press()
                    m.move(cables[0],cables[1],True,0.2)
                    m.release()
        #The task loops one additional time so theres no need to exit or wait
        return
    if shorthand == 'spinnywheels':
        #Clicking the button at the right time
        print('Comitting to the spinny wheel task')
        for paris in SPINWHEELPAIRS:
            m.move(paris[0][0],paris[0][1], True, 0.4)
            while True:
                value = ImageGrab.grab().load()[paris[0][0],paris[0][1]]
                if value != paris[1]:
                    m.move(paris[2][0],paris[2][1])
                    m.click()
                    break
        time.sleep(1.7)
        k.send('escape')
        return
    if shorthand == 'testtubes':
        #Testing the tubes
        print("Starting test tube scanner")
        m.move(TESTTUBEORIGIN[0], TESTTUBEORIGIN[1],True,0.1)
        m.click("left")
        time.sleep(62.5)
        for i in range(4):
            x,y = testLoc[i]
            m.move(x,y,True,0.3)
            color = ImageGrab.grab().load()[x,y]
            if ImageGrab.grab().load()[x,y] == (246,134,134):
                x,y = locs[i]
                m.move(x,y,True,0.4)
                m.click("left")
                break
        time.sleep(1.6)
        print("Scan complete")
        return
    if shorthand == 'scanner':
        #Waiting for scanner
        print('Comitting to waiting for the scanner to finish \'task\'')
        time.sleep(11.5)
        return
    if shorthand == 'patternmatcher':
        #Matching blue patterns
        print('Comitting to pattern matching task')
        #Possibly record each step as an image and use that to click?
        #^ this is kind of what i ended up doing
        while True:
            k.send('escape')
            time.sleep(0.5)
            m.move(usebtncoords[0],usebtncoords[1],True,0.1)
            print('click!')
            m.click()
            time.sleep(1.08)
            spotsToClick = []
            while True:
                val = pagui.locateCenterOnScreen(rootdir + 'square.png', region=REACTMONITOR)
                if not val == None:
                    print('blue square at: ' + str(val))
                    spotsToClick.append(val)
                    time.sleep(0.2)
                else:
                    break
            for cliccer in spotsToClick:
                m.move(cliccer[0] + 650 ,cliccer[1],True,0.2)
                m.click()
            m.move(LASTLIGHT[0][0],LASTLIGHT[0][1], True,0.1)
            if ImageGrab.grab().load()[m.get_position()[0],m.get_position()[1]] == LASTLIGHT[1]:
                break
            else:
                print('onto the next stage of the reactor!')    
        print('Finally, done with the blue square reactor')
        k.send('escape')
        time.sleep(1.7)
        return
    if shorthand == 'cleanvent':
        #Cleaning out the sussy vent
        print('Committing to cleaning out the vent')
        m.move(centercoords[0],centercoords[1])
        m.click()
        #We're gonna be reeeal sussy and do this the 'shit' way as they say down south
        x = 512
        y = 205
        m.move(x, y, True, 0.1)
        while y < 983:
            while x < 1412:
                x = x + 70
                m.move(70, 0, False, 0.1)
                m.click()
            m.move(512, y, True, 0.1)
            x = 512
            m.move(0, 90, False, 0.1)
            y = y + 90
            val = pagui.locateOnScreen(rootdir + 'lunchbox.png', grayscale=True)
            if val == None:
                print('Done with the lunchbox!')
                break
        k.send('escape')
        time.sleep(1.7)
        return
    if shorthand == 'shields':
        #Clicking the shield tiles
        print('Comitting to shield task')
        #im still LAUGHING at some of the old methods i tried in the past, including a randomized clicker
        #Some of these index values correspond to the center of the circles. only God knows which..
        for z in range(2):
            #I swear on my yeezys this function went through more iterations than 
            #tyson foods went through chicken poisoners.
            #That single bloody gradient is barely visible WHY WOULD YOU PUT THAT IN THERE???
            #Iteration 47: Moves to each edge, at each edge sees if the color is whiter or more red, if red click
            for i in range(len(SHIELDEDGES)):
                a,b = SHIELDEDGES[i]
                amtWhite = ImageGrab.grab().load()[a,b]
                if amtWhite[1] < 211:
                    m.move(a,b-20,True,0.5)
                    m.click("left")
        k.send('escape')
        time.sleep(1.7)
        return
    #Make sure job didnt get interrupted
    if not pagui.locateOnScreen(os.path.join(os.getcwd() + images + '\\reportedstripes.png')) == None:
        print('Task was interrupted by someone dying')
        return
    else:
        print('Nothing in progress, resetting')
        inProgress = 'NONE'
        return
Esempio n. 17
0
if __name__ == "__main__":
    image = screenshot.get_screenshot()
    #image = Image.open('e0.jpg')
    sp = screen_parser.ScreenParser()
    print(np.array(sp.cells).T)
    ai = AI()
    while 1:
        image = screenshot.get_screenshot()
        image = image.resize((image.size[0]/2, image.size[1]/2))
        image = image.filter(ImageFilter.SMOOTH)
        image = image.resize((image.size[0]*2, image.size[1]*2))
        board = sp.parse(image)
        if random.random() < .5:
            bad_spots = len([x for x in np.array(board).ravel() if x == None or x == 'w'])
            if bad_spots > 30:
                mouse.move_click((490,575))
                time.sleep(.1)
                mouse.move_click((910,298))
                time.sleep(.5)
                print('bad')
        try:
            cell_index, move = ai.think(board)
        except TypeError:
            continue
        from_move = sp.cell_index_to_cell(cell_index)
        to_move = sp.move_offset[move] + from_move
        mouse.drag(from_move, to_move)
        #mouse.hide()
        #time.sleep(.05)
        #time.sleep(.2)
Esempio n. 18
0
end_drag = [1200, 900]
button_ad = [1089, 334]
icon_items = [734, 85]
icon_crates = [1146, 959]
icon_crate = [950, 578]
reset_esc = [965, 712]
count = 0

while True:
    count += 1

    #click dell'icona della pagina principale e attesa che la pubblicità finisca
    mouse.move(icon_market)
    mouse.click()
    time.wait(1)
    mouse.drag(start_drag, end_drag, duration=1)
    mouse.move(button_ad)
    mouse.click()
    time.wait(60)

    #visione della pubblicità e ritorno alla schermata iniziale
    for i in range(5):
        keyboard.press_and_release('esc')
        time.wait(1)
    mouse.move(reset_esc)
    mouse.click()
    time.wait(1)

    #apertura del forziere
    mouse.move(icon_items)
    mouse.click()
Esempio n. 19
0
    def imagesearch(self,
                    im,
                    precision=0.8,
                    offset=(0, 0, 0, 0),
                    click='',
                    moveback=True):
        """

        :param im: file path of image to search (needle)
        :param precision: precision factor for when it considers the image to be found
        :param offset: a tuple (left, top, right, bottom) for how much to offset the search area.
                offset crops the panel search area so you can control better where you want to find the pixel,
                in case it finds pixels before that are not intended.
        :param click: whether to 'click', 'double' click, 'move', or if default '', return the position.
        :param moveback: whether to move the mouse back after completion
        """

        p = self
        origx, origy = mouse.get_position()
        #Lets set our haystack bounding box to be searched
        hx1, hy1 = p.rectangle().left + offset[0], p.rectangle(
        ).top + offset[1]
        hx2, hy2 = p.rectangle().right - offset[2], p.rectangle(
        ).bottom - offset[3]

        #save it as np array
        img_rgb = np.array(getRectAsImage((hx1, hy1, hx2, hy2)))

        #cv2.matchTemplate only accepts grayscale, so transform it from BGR to grayscale
        img_gray = cv2.cvtColor(img_rgb, cv2.COLOR_BGR2GRAY)

        template = cv2.imread(im, 0)
        height, width = template.shape

        #do the search itself
        res = cv2.matchTemplate(img_gray, template, cv2.TM_CCOEFF_NORMED)
        min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(res)

        loc = np.where(res >= precision)
        coord = list(zip(*loc[::-1]))

        # image not found!
        if max_val < precision:
            print('Image not found')
            return [-1, -1]

        #returns first image found. could also change it to get other images found.
        foundcoord = (coord[0][0], coord[0][1])

        # get the absolute position
        x, y = self.abspos_from_rel(foundcoord, offset=offset)

        # and lets change that position to the middle of the image found, just because it looks nicer instead of
        # the topleft pixel.
        absx = int(x + width / 2)
        absy = int(y + height / 2)

        print(f'Image found at {absx}, {absy}')

        if click == '':
            return absx, absy
        if click == 'single':
            mouse.move(absx, absy)
            mouse.click()
        elif click == 'double':
            mouse.move(absx, absy)
            mouse.double_click()
        elif click == 'move':
            mouse.move(absx, absy)
        if moveback:
            mouse.move(origx, origy)
        if click == 'drag':
            mouse.drag(absx, absy, origx, origy, duration=MOUSEDELAY)
Esempio n. 20
0
duration = 0.05
print("Now running!")
# loop that reads from serial port
while True:
    #setup
    data = ser.readline()[:-2]  # the last bit gets rid of the new-line chars
    params = data.split()
    if (len(params) == 0):
        break
    #parses string from into words, stores them in their respective variables
    #String format: mouseX, mouseY, mouse1_clicked, mouse2_clicked
    mouseX = (int(params[0].decode('utf-8')) - 516) / sensitivity
    mouseY = ((int(params[1].decode('utf-8')) - 516) / sensitivity) * -1
    print(mouseX)
    print(mouseY)
    mouse1_clicked = params[2].decode('utf-8')
    mouse2_clicked = params[3].decode('utf-8')
    print(mouse2_clicked)
    if mouse.is_pressed():
        mouse.drag(0, 0, mouseX, mouseY, absolute=False, duration=duration)
    else:
        #if statements time
        if (mouse1_clicked == "M1_PRESSED"):
            mouse.press('left')
        elif (mouse2_clicked == "M2_PRESSED"):
            mouse.click('right')
        else:
            mouse.release('left')
            print("Released")
        mouse.move(mouseX, mouseY, absolute=False, duration=duration)
print("Device disconnected ")