Example #1
0
def main(column_midpoints, left_mouse_click_on_rgb_values, precision, dy,
         keyboard_interrupt):
    """This is the entry point of the program."""
    while not keyboard.is_pressed(keyboard_interrupt):
        # This line is for debugging purposes.
        # Start measuring the program runtime.
        # runtime = time.time()

        # PyAutoGUI can throw an OSError because of a currently unknown reason (26/02/2021).
        # This block is for debugging purposes.
        try:
            left_mouse_click(
                column_midpoints[0] * check_rgb_match(
                    pyautogui.pixel(column_midpoints[0], column_midpoints[1]),
                    left_mouse_click_on_rgb_values, precision),
                column_midpoints[1] + DY)
            left_mouse_click(
                column_midpoints[2] * check_rgb_match(
                    pyautogui.pixel(column_midpoints[2], column_midpoints[3]),
                    left_mouse_click_on_rgb_values, precision),
                column_midpoints[3] + DY)
            left_mouse_click(
                column_midpoints[4] * check_rgb_match(
                    pyautogui.pixel(column_midpoints[4], column_midpoints[5]),
                    left_mouse_click_on_rgb_values, precision),
                column_midpoints[5] + DY)
            left_mouse_click(
                column_midpoints[6] * check_rgb_match(
                    pyautogui.pixel(column_midpoints[6], column_midpoints[7]),
                    left_mouse_click_on_rgb_values, precision),
                column_midpoints[7] + DY)
        except OSError:
            pass
Example #2
0
def create_color_board(board_of_pixels, size_of_board):
    dict_of_colors = {
        (0, 0, 255): 'b',
        (255, 0, 0): 'r',
        (0, 128, 0): 'g',
        (238, 238, 0): 'y',
        (255, 127, 0): 'o',
        (255, 0, 255): 'p',
        (128, 0, 120): 'z',
        (0, 255, 255): 'c',
        (0, 128, 128): 't',
        (0, 0, 139): 'd',
        (166, 166, 166): 'q',
        (189, 183, 107): 's',
        (0, 255, 0): 'l',
        (165, 42, 42): 'm',
        (255, 255, 255): 'w'
    }

    board_of_colors = numpy.zeros((size_of_board, size_of_board), dtype=str)
    for i in range(size_of_board):
        for j in range(size_of_board):
            if (pyautogui.pixel(
                    board_of_pixels[i, j][0],
                    board_of_pixels[i, j][1])) in dict_of_colors.keys():
                board_of_colors[i][j] = dict_of_colors[pyautogui.pixel(
                    board_of_pixels[i, j][0], board_of_pixels[i, j][1])]
            else:
                board_of_colors[i][j] = '0'
    return (board_of_colors)
Example #3
0
def cursorPositionMonitor():
    pos = pg.position()
    x, y = pos
    pos_msg = "X=" + str(x) + " Y=" + str(y)

    rgb = pg.pixel(x, y)
    color_msg = str(rgb[0]) + ", " + str(rgb[1]) + ", " + str(rgb[2])

    out_text = "\r" + "Posi: (" + pos_msg + ") RGB: (" + color_msg + ")       "
    print(out_text, end='')
    old_pos = pos

    while True:
        pos = pg.position()
        if pos != old_pos:
            x, y = pos
            pos_msg = "X=" + str(x) + " Y=" + str(y)

            rgb = pg.pixel(x, y)
            color_msg = str(rgb[0]) + ", " + str(rgb[1]) + ", " + str(rgb[2])

            out_text = "\r" + "Posi: (" + pos_msg + ") RGB: (" + color_msg + ")      "

            print(out_text, end='')
            old_pos = pos

        time.sleep(0.1)
Example #4
0
def orderIngredient(ingredient):
    global ordered, inventory
    if ingredient in ordered:
        print('Just bought ' + ingredient)
        return
    print('Ordering more ' + ingredient + '. Current inventory ')
    print(inventory)
    pyautogui.click(restock['phone'])
    if ingredient == 'rice':
        pyautogui.click(restock[ingredient], interval=0.1)
        pixel = pyautogui.pixel(restock[ingredient][0], restock[ingredient][1])
        #check if we can afford the ingredient by matching gray pixel
        if pixel == (118, 83, 85):
            print('Can\'t afford ' + ingredient)
            pyautogui.click(restock['endCall'])
            return
        else:
            pyautogui.click(restock[ingredient], interval=0.1)
    else:
        pyautogui.click(restock['topping'], interval=0.1)
        pixel = pyautogui.pixel(restock[ingredient][0], restock[ingredient][1])
        #check if we can afford the ingredient by matching gray pixel
        if pixel == (109, 123, 127):
            print('Can\'t afford ' + ingredient)
            pyautogui.click(restock['endCall'])
            return
        pyautogui.click(restock[ingredient], interval=0.1)
    pyautogui.click(restock['free'], interval=0.1)
    ordered.append(ingredient)
    # takes 6 seconds for item to be delivered
    timer = threading.Timer(6, delivered, args=[ingredient])
    timer.start()
Example #5
0
def GetWireColors(x1,x2,y,diff):
    wires = []
    for i in range(0, 4):
        leftColor =(pyautogui.pixel(x1, y + diff * i))
        rightColor =(pyautogui.pixel(x2, y + diff * i))
        wires.append(((x1, y + diff * i), leftColor))
        wires.append(((x2, y + diff * i), rightColor))
    return wires
Example #6
0
def isplayersturn():
    pixel1 = pyautogui.pixel(screenx + 157, screeny + 130)
    pixel2 = pyautogui.pixel(screenx + 291, screeny + 118)
    if pixel1[0] == pixel2[0] and pixel1[1] == pixel2[1] and pixel1[2] == pixel2[2] and pixel1[0] == 218 and pixel1[
        1] == 165 and pixel1[2] == 32:
        return True
    else:
        return False
Example #7
0
def checkColor():
    if pyautogui.pixel(400, 400)[0] == 0:
        doClick(400, 400)
    if pyautogui.pixel(480, 400)[0] == 0:
        doClick(480, 400)
    if pyautogui.pixel(550, 400)[0] == 0:
        doClick(550, 400)
    if pyautogui.pixel(620, 400)[0] == 0:
        doClick(620, 400)
Example #8
0
def Jump():
    #pq.screenshot('C:\\Users\\Professional\\PycharmProjects\\app1\\screen.png')
    #f = Image.open('C:\\Users\\Professional\\PycharmProjects\\app1\\screen.png')
    #g=f.load()
    x=pq.position().x
    y=pq.position().y
    z=pq.pixel(x, y)
    if z[0]<90 or pq.pixel(x-20, y)[0]<90 or pq.pixel(x-40, y)[0]<90 or pq.pixel(x-30, y-40)[0]<90:
        pq.keyDown('space')
Example #9
0
 def run(self):
     while True:
         if pyautogui.pixel(*self.critical_hp_position
                            ) == self.critical_missing_hp_color:
             #print("Attempting to run...")
             self.teleporter.do_teleport()
         if pyautogui.pixel(*self.hp_position) == self.missing_hp_color:
             self.do_heal()
         time.sleep(Constants.global_refresh_time)
Example #10
0
def isElectricOpen():
    isElec = Point(965, 130)  # blue
    isElec2 = Point(950, 130)

    # check the left cable in the top and the middle one
    if (pyautogui.pixel(isElec.x, isElec.y)[0] == 16 and pyautogui.pixel(isElec.x, isElec.y)[1] == 28 and pyautogui.pixel(isElec.x, isElec.y)[2] == 115) \
    and (pyautogui.pixel(isElec2.x, isElec2.y)[0] == 115 and pyautogui.pixel(isElec2.x, isElec2.y)[1] == 0 and pyautogui.pixel(isElec2.x, isElec2.y)[2] == 0):
        return True
    return False
Example #11
0
def get_pixel():
        x,y=pyautogui.position()
        rgb=pyautogui.pixel(x,y)
        print(("position= {}, pixel={}").format((x,y),rgb))
        while True:
            if rgb != pyautogui.pixel(x,y):
                #print("Yee")
                #ctypes.windll.user32.keybd_event(0x20,0,0,0)#key,none, type if 0 keyDown, 0x0002 - keyDown
                #ctypes.windll.user32.keybd_event(0x20,0,0x0002,0)
                pyautogui.press(' ')
Example #12
0
def danger():
    try:
        if pg.pixel(1235, 1025)[0] >= 190 and not done():
            t.sleep(0.5)
            if pg.pixel(1235, 1025)[0] >= 190 and not done():
                print(pg.pixel(1235, 1023))
                prind('-leska at time after start: H:{} M:{} S:{}'.format(
                    int((t.time() - time1) // 3600),
                    int((t.time() - time1) // 60),
                    round((t.time() - time1) % 60, 1)))
                ext()
        if pg.pixel(1370, 1025)[0] >= 190 and not done():
            t.sleep(0.5)
            if pg.pixel(1370, 1025)[0] >= 190 and not done():
                print(pg.pixel(1369, 1023))
                prind('HOT! at time after start: H:{} M:{} S:{}'.format(
                    int((t.time() - time1) // 3600),
                    int((t.time() - time1) // 60),
                    round((t.time() - time1) % 60, 1)))
                ext()
        if pg.pixel(1270, 1025)[0] >= 190 and not done():
            t.sleep(0.5)
            if pg.pixel(1270, 1025)[0] >= 190 and not done():
                print(pg.pixel(1270, 1023))
                prind('Хрясь at time after start: H:{} M:{} S:{}'.format(
                    int((t.time() - time1) // 3600),
                    int((t.time() - time1) // 60),
                    round((t.time() - time1) % 60, 1)))
                ext()
    except:
        return danger()
    else:
        t.sleep(1)
 def getColourWindow(self, pos):
     window_pos = [[], []]
     window_pos[0] = int(self.x_frame + pos[0] * (100/self.wpercent))
     window_pos[1] = int(self.y_frame + pos[1] * (100/self.hpercent))
     color = (int(pyautogui.pixel(*window_pos)[2]),  # RGB to BGR
              int(pyautogui.pixel(*window_pos)[1]),
              int(pyautogui.pixel(*window_pos)[0]))
     '''
     pyautogui
     RGB to BGR (255,255,255)
     '''
     return color
Example #14
0
def main_loop_script(tilecolor):

    print("Waiting for detection... ")
    while keyboard.is_pressed("f") == False:
        if pyautogui.pixel(740, ypixelpos)[0] == int(tilecolor):
            mouse_event(740, ypixelpos)
        if pyautogui.pixel(864, ypixelpos)[0] == int(tilecolor):
            mouse_event(864, ypixelpos)
        if pyautogui.pixel(1014, ypixelpos)[0] == int(tilecolor):
            mouse_event(1014, ypixelpos)
        if pyautogui.pixel(1151, ypixelpos)[0] == int(tilecolor):
            mouse_event(1151, ypixelpos)
Example #15
0
def on_press(key):
    if key == Key.space or key == Key.down or repr(key) == "'c'":
        if repr(key) == "'c'":
            # print('Pressed C')
            c_pressed = True
        else:
            c_pressed = False

        piece_color = pyautogui.pixel(624, 232)[1]
        while piece_color == 0 and wait:
            piece_color = pyautogui.pixel(624, 232)[1]

        update(piece_color)
Example #16
0
def check_pxl(img1):
    img2 = pyautogui.pixel(x + 290, y + 365)
    t1 = time.time()
    # print(img1==img2)
    while img1 != img2:
        print('waiting...')
        time.sleep(0.2)
        img2 = pyautogui.pixel(x + 290, y + 365)
        t2 = time.time()
        if t2 - t1 > 10:
            pyautogui.press('enter')
            print(
                "The window was blocked for more than 1 min...pressed 'Enter button'"
            )
            t1 = t2
Example #17
0
    def execute(self):
        self.window_title = ".*" + ".*"

        window = lybwin.LYBWin('.*check.py.*')
        window.find_window_wildcard(self.window_title)
        if len(window.handle_list) < 1:
            print('Not found window:', self.window_title)
            sys.exit()

        # print(window.my_handle)

        # window.set_invisible(window.my_handle)
        # window.set_foreground_console(window.handle_list[0])
        window.set_foreground_console(window.handle_list[0])
        adj_x, adj_y = window.get_player_adjust(window.handle_list[0])
        self.anchor_x, self.anchor_y, self.bx, self.by = win32gui.GetWindowRect(window.handle_list[0])
        self.anchor_x += adj_x
        self.anchor_y += adj_y

        while True:
            x, y = pyautogui.position()
            position_str = 'X: ' + str(x).rjust(4) + ' Y: ' + str(y).rjust(4) + \
                           ' ' + str(pyautogui.pixel(x, y)).rjust(16) + \
                           '      ' + 'R-X: ' + str(x - self.anchor_x).rjust(4) + ' R-Y: ' + str(
                y - self.anchor_y).rjust(4)
            print(position_str, end='')
            print('\b' * len(position_str), end='', flush=True)

            time.sleep(0.5)
Example #18
0
def wiring_task():
    x_right = 930
    x_left = 402
    heights = [192, 324, 457, 590]
    rightcolordict = {
        "(255, 0, 0)": heights[0],
        "(38, 38, 255)": heights[1],
        "(255, 235, 4)": heights[2],
        "(255, 0, 255)": heights[3]
    }
    print("Starting Wiring Task")
    start_time = timeit.default_timer()
    # colordict["location"] = pixel color
    # to print 272,462,647,833 could be faster probably not
    for x in range(4):
        # 1905
        pyautogui.moveTo(x_left, heights[x])
        try:
            pyautogui.dragTo(x_right,
                             rightcolordict[str(
                                 pyautogui.pixel(x_left, heights[x]))],
                             .50,
                             button='left')
            sleep(.05)
        except IndexError:
            print("no index try again")
        except KeyError:
            print("invalid key try again")
    print("Time to complete Wiring Task: " +
          str(round(timeit.default_timer() - start_time, 2)) + " seconds")
Example #19
0
def check_end_game_page(BLACK_PIXEL=15):
    print('check end game page')
    pix = pyautogui.pixel(END_X, END_Y)
    if pix[0] <= BLACK_PIXEL and pix[1] <= BLACK_PIXEL and pix[
            2] <= BLACK_PIXEL:
        return True
    return False
    def do_task(self, screen):

        pyautogui.PAUSE = 0

        colors = ["yellow", "blue", "cyan"]
        offset = 266

        ref_rgb = [
            (255, 227, 0),  # yellow
            (83, 98, 255),  # blue
            (111, 249, 255)
        ]  # cyan

        for i in range(3):
            aligned = False

            while not aligned:
                # Comparing pixel colors is sufficient here
                pix = pyautogui.pixel(1300, 232 + i * offset)

                epsilon = 10
                for j in range(3):
                    if abs(pix[j] - ref_rgb[i][j]) > epsilon:
                        break
                    aligned = True

                if aligned:
                    pyautogui.moveTo(1240, 310 + i * offset)
                    pyautogui.click()

        time.sleep(2)
Example #21
0
def run():
    cords = [
        (0, 0, 0),      # 0
        (0, 0, 85),     # 1
        (0, 0, 170),    # 2
        (0, 85, 0),     # 3
        (0, 85, 85),    # 4
        (0, 85, 170),   # 5
        (0, 170, 0),    # 6
        (0, 170, 85),   # 7
        (0, 170, 170),  # 8
        (85, 0, 0),     # 9
        (85, 0, 85),    # 10
        (85, 0, 170),   # 11
        (85, 85, 0),    # 12
        (85, 85, 85)    # 13
    ]

    wait('ctrl+5')
    halt_touch()
    point = pixel(16, 112)
    eps, idx = min([(distance2(point, cords[i]), i) for i in range(len(cords))])
    if idx > 10:
        hotkey('alt', 'f%d' % (idx % 10))
    elif idx > 0:
        hotkey('alt', 'num%d' % (idx % 10))
    sys.stdout.write('[%s] Touch index %d with %d epsilon.\n' % (
                     datetime.now().strftime('%Y-%m-%d %H:%M:%S'),
                     idx, eps))
    sleep(0.010)
Example #22
0
 def events(self, event):
     self.x, self.y = pyautogui.position()
     self.r, self.g, self.b = pyautogui.pixel(self.x, self.y)
     self.xx = '#%02x%02x%02x' % (self.r, self.g, self.b)
     self.parent.configure(bg=str(self.xx))
     self.display.delete(0, END)
     self.display.insert(0, self.xx)
Example #23
0
def run():
    cords = [
        (0, 0, 0),  # 0
        (9, 28, 85),  # 1
        (19, 57, 170),  # 2
        (28, 85, 0),  # 3
        (38, 113, 85),  # 4
        (47, 142, 170),  # 5
        (57, 170, 0),  # 6
        (66, 198, 85),  # 7
        (76, 227, 170),  # 8
        (85, 0, 0),  # 9
        (94, 28, 85),  # 10
        (104, 57, 170)  # 11
    ]

    halt_touch()
    point = pixel(16, 16)
    eps, idx = min([(distance2(point, cords[i]), i)
                    for i in range(len(cords))])
    if idx != 0:
        hotkey('ctrl', 'f%d' % idx)
    sys.stdout.write('[%s] Touch index %d with %d epsilon.\n' %
                     (datetime.now().strftime('%Y-%m-%d %H:%M:%S'), idx, eps))
    sleep(0.100)
    def judge_status(self, check_mark):  # 判断是否频繁

        for position in self.check_marks_ponit(check_mark, 3, 1):
            color = pyautogui.pixel(position[0], position[1])
            print("判断是否频繁", color)
            if color[0] < 255:
                return 1
Example #25
0
def closeMap():
    focusRS()

    rgb = pyautogui.pixel(797,26)
    if (173,107,41) == rgb:
        print("マップを閉じる")
        click(789,11, 0.2)
Example #26
0
def click_when_colour(x, y):

    try:
        try:
            pixel = pyautogui.pixel(x, y)
        except:
            pixel = pyautogui.pixel(x, y)
    except:
        try:
            pixel = pyautogui.pixel(x, y)
        except:
            pixel = pyautogui.pixel(x, y)

    if pixel[rgb_check] >= tile_colour[rgb_check] and pixel[
            rgb_check] <= tile_colour[rgb_check] + 10:
        click(x, y)
Example #27
0
def full():
    try:
        if sum(pg.pixel(1867, 774)) // 3 >= 225:
            return True
    except:
        return full()
    return False
Example #28
0
def pixel():
    """
    要获取截屏某个位置的RGB像素值,可以用Image对象的getpixel()方法:
    :return: 
    """
    im = pyautogui.screenshot()
    im.getpixel((100, 200))

    # 也可以用PyAutoGUI的pixel()函数,是之前调用的包装:
    pyautogui.pixel(100, 200)

    # 如果你只是要检验一下指定位置的像素值,可以用pixelMatchesColor()函数,
    # 把X、Y和RGB元组值穿入即可:
    pyautogui.pixelMatchesColor(100, 200, (255, 255, 255))
    # tolerance参数可以指定红、绿、蓝3种颜色误差范围:
    pyautogui.pixelMatchesColor(100, 200, (255, 255, 245), tolerance=10)
Example #29
0
def get_pixel():
    while True:
        try:
            #button7location = pyautogui.locateOnScreen(edit_pic_path('Talk.png'))
            #print(button7location)
            pass
        except:
            pass
        posXY = pyautogui.position()
        color = pyautogui.pixel(posXY[0], posXY[1])
        open_cv_image = np.array(color)
        # Convert RGB (33, 189, 236) to BGR (236, 189, 33) blue
        # Convert RGB (247, 3, 2) to BGR (2, 3, 247) red
        # Convert RGB (140, 247, 231) to BGR (231, 247, 140) talk
        # print(pyautogui.pixelMatchesColor(300,300,(248,248,248)))
        open_cv_image = open_cv_image[::-1]
        print(posXY, color)
        time.sleep(0.2)
        image = np.zeros((300, 300, 3), np.uint8)
        image[:] = open_cv_image
        cv2.imshow('w', image)
        cv2.waitKey(1)
        if posXY[0] == 0:
            break
        x1 = 684
        x2 = 758
        y1 = 336
        y2 = 385
Example #30
0
def screen():
    while True:
        print(pyautogui.position())
        print(pyautogui.pixel(pyautogui.position()[0],
                              pyautogui.position()[1]))
        time.sleep(1)
        os.system("clear")
 def run(self):
     mlen = 0;
     while not self.isStop:
         self.x, self.y = pyautogui.position();
         self.color = pyautogui.pixel(self.x, self.y);
         r, g, b = self.color;
         mess = 'Current Mouse: (%d, %d) color:(%d, %d, %d)'%(self.x,
                 self.y,r, g, b);
         print('\b'*mlen, end='');
         print(mess, end='', flush = True);
         mlen = len(mess);