def xiazhu(s, hwnd): time.sleep(0.5) ##win32gui.SetForegroundWindow(hwnd) windll.user32.SetCursorPos(673, 350) hdc = win32gui.GetDC(hwnd) color1 = color2 = win32gui.GetPixel(hdc, 673, 350) win32gui.ReleaseDC(hwnd, hdc) while color1 == color2 and color1 == 2787168: time.sleep(1) hdc = win32gui.GetDC(hwnd) color2 = win32gui.GetPixel(hdc, 673, 350) win32gui.ReleaseDC(hwnd, hdc)
def get_realtime_pixel(): # 실시간으로 마우스 위치의 픽셀을 출력하는 함수 prev = win32api.GetCursorPos() while True: mouse_p = win32api.GetCursorPos() if prev != mouse_p: print('Hex : ' + str( hex( win32gui.GetPixel( win32gui.GetDC(win32gui.GetDesktopWindow()), mouse_p[0], mouse_p[1]))) + ' Int : ' + str( win32gui.GetPixel( win32gui.GetDC(win32gui.GetDesktopWindow()), mouse_p[0], mouse_p[1]))) prev = mouse_p
def get_desktop_color(): hwnd = win32gui.GetDesktopWindow() dc = win32gui.GetWindowDC(hwnd) long_colour = win32gui.GetPixel(dc, *ColorCheck.get_mouse_point()) i_colour = int(long_colour) return (i_colour & 0xff), ((i_colour >> 8) & 0xff), ((i_colour >> 16) & 0xff)
def get_pixel(self, x: int, y: int) -> QPixel: """ Gets the pixel at x,y Example: -------- >>> screen = Screen() # Does create wx.App(...) >>> screen.get_pixel(24, 24) # Gets the pixel at 24, 24. Returns a Pixel(...) instance. :param x: The Y coordinate of the pixel :param y: The X coordinate of the pixel :returns: A Pixel(...) instance of the given x and y coordinates """ if self.getPixelMethod == "Pillow": from PIL import ImageGrab, Image pil_color: _t.Tuple[int, int, int] = ImageGrab.grab((x, y, x + 1, y + 1)).getpixel((0, 0)) # noinspection PyTypeChecker return QPixel(x, y, QColor(pil_color)) elif self.getPixelMethod == "PyWin32": # noinspection PyPackageRequirements import win32gui win32gui.GetPixel(self.dc, x, y) else: raise ValueError(f"Invalid pixel method: {self.getPixelMethod}, " f"look at the Screen Class doc for more information")
def getPixelOnDesktop(self, x, y): hwnd = win32gui.GetDesktopWindow() dc = win32gui.GetWindowDC(self.desktopHwnd) long_color = win32gui.GetPixel(dc, x, y) color = int(long_color) color = (color & 0xff), ((color >> 8) & 0xff), ((color >> 16) & 0xff) return libs.rgb_to_hex(color)
def get_pixel_color(x, y): desktop_window_id = win32gui.GetDesktopWindow() desktop_window_dc = win32gui.GetWindowDC(desktop_window_id) long_colour = win32gui.GetPixel(desktop_window_dc, x, y) color = int(long_colour) win32gui.ReleaseDC(desktop_window_id, desktop_window_dc) return (color & 0xff), ((color >> 8) & 0xff), ((color >> 16) & 0xff)
def getPixel(x, y): hwnd = win32gui.WindowFromPoint((x, y)) hdc = win32gui.GetDC(hwnd) x1, y1 = win32gui.ScreenToClient(hwnd, (x, y)) color = win32gui.GetPixel(hdc, x1, y1) win32gui.ReleaseDC(hwnd, hdc) return color % 256, color / 256 % 256, color / 256 / 256
def checkHealth(keyCode): x, y = calculateHPxy(80) color = win32gui.GetPixel(win32gui.GetDC(win32gui.GetActiveWindow()), x, y) r, g, b = rgbint2rgbtuple(color) if r < 50: time.sleep(0.3) useSkill(keyCode)
def get_pixel_color(x, y): def rgb_to_hex(tup): """Convert RGB value to HEX.""" return '%02x%02x%02x'.upper() % (tup[0], tup[1], tup[2]) """Get the color of selected pixel in HEX.""" dc = win32gui.GetWindowDC(Window.id) rgba = win32gui.GetPixel(dc, x + 8 + Window.x, y + 8 + Window.y) win32gui.ReleaseDC(Window.id, dc) r = rgba & 0xff g = rgba >> 8 & 0xff b = rgba >> 16 & 0xff return rgb_to_hex((r, g, b)) def pixel_search(self, color, x_start, y_start, x_end, y_end): """Find the first pixel with the supplied color within area. Function searches per row, left to right. Returns the coordinates of first match or None, if nothing is found. Color must be supplied in hex. """ bmp = self.get_bitmap() width, height = bmp.size for y in range(y_start, y_end): for x in range(x_start, x_end): if y > height or x > width: continue t = bmp.getpixel((x, y)) if (self.rgb_to_hex(t) == color): return x - 8, y - 8 return None
def display_room_rect(left_top_x, left_top_y, right_bot_x, right_bot_y): hWnd = win32gui.FindWindow(None, "QQ游戏 - 连连看角色版") win32gui.SetForegroundWindow(hWnd) win32gui.SetActiveWindow(hWnd) hDC = win32gui.GetWindowDC(hWnd) rect = win32gui.GetWindowRect(hWnd) x = rect[0] y = rect[1] w = rect[2] - x h = rect[3] - y print("Window name: " + win32gui.GetWindowText(hWnd)) print("Window hDC: " + str(hDC)) print("x, y, w, h == " + str(x) + " " + str(y) + " " + str(w) + " " + str(h) + " ") image = np.zeros( (right_bot_y - left_top_y + 1, right_bot_x - left_top_x + 1, 3)) for y in range(right_bot_y - left_top_y + 1): #h for x in range(right_bot_x - left_top_x + 1): #w image[y, x] = np.asarray( Int2RGB(win32gui.GetPixel(hDC, x + left_top_x, y + left_top_y))) / 255 win32gui.ReleaseDC(hWnd, hDC) plt.imshow(image[..., ::-1]) # GetPixel得到的是BGR而不是RGB,所以需要转换一下 plt.show()
def GetColor(i_x,i_y): i_desktop_window_id = win32gui.GetDesktopWindow() i_desktop_window_dc = win32gui.GetWindowDC(i_desktop_window_id) long_colour = win32gui.GetPixel(i_desktop_window_dc, i_x, i_y) i_colour = int(long_colour) print "icolour====",i_colour return (i_colour & 0xff), ((i_colour >> 8) & 0xff), ((i_colour >> 16) & 0xff)
def get_pixel_rgb(pos): hwnd = get_hos_handler() x, y = pos dc = win32gui.GetDC(hwnd) rgbint = win32gui.GetPixel(dc, x, y) win32gui.ReleaseDC(hwnd, dc) return rgbint2rgbtuple(rgbint)
def get_pixel_colour(i_x, i_y): i_desktop_window_id = win32gui.GetDesktopWindow() i_desktop_window_dc = win32gui.GetWindowDC(i_desktop_window_id) long_colour = win32gui.GetPixel(i_desktop_window_dc, i_x, i_y) i_colour = int(long_colour) return (i_colour & 0xff), ((i_colour >> 8) & 0xff), ((i_colour >> 16) & 0xff)
def readPixel(x, y): if x >= 1920: x = 1919 if y >= 1080: y = 1079 color = win32gui.GetPixel(win32gui.GetDC(win32gui.GetActiveWindow()), x, y) r, g, b = rgbint2rgbtuple(color) return r, g, b
def getPixelWithDC(self, dc, x, y): # GetPixel include title bar x += self.dx y += self.dy long_color = win32gui.GetPixel(dc, x, y) color = int(long_color) color = (color & 0xff), ((color >> 8) & 0xff), ((color >> 16) & 0xff) return libs.rgb_to_hex(color)
def get_pixel_colour( i_x, i_y ): # returns the color of a pixel with coordinates i_x, i_y # in the format (r, g, b) i_desktop_window_id = win32gui.GetDesktopWindow() i_desktop_window_dc = win32gui.GetWindowDC( i_desktop_window_id ) long_colour = win32gui.GetPixel( i_desktop_window_dc, i_x, i_y ) i_colour = int( long_colour ) return (i_colour & 0xff), ((i_colour >> 8) & 0xff), ((i_colour >> 16) & 0xff)
def get_pixel_color(self, x, y): """Get the color of selected pixel in HEX.""" dc = win32gui.GetWindowDC(window.id) rgba = win32gui.GetPixel(dc, x + 8 + window.x, y + 8 + window.y) win32gui.ReleaseDC(window.id, dc) r = rgba & 0xff g = rgba >> 8 & 0xff b = rgba >> 16 & 0xff return self.rgb_to_hex((r, g, b))
def GetPixelColour(hwnd , i_x, i_y): GetPosWnd(hwnd , i_x, i_y) Active(hwnd) i_x, i_y = win32gui.GetCursorPos() i_desktop_window_id = win32gui.GetDesktopWindow() i_desktop_window_dc = win32gui.GetWindowDC(i_desktop_window_id) long_colour = win32gui.GetPixel(i_desktop_window_dc, i_x, i_y) i_colour = int(long_colour) return (i_colour & 0xff), ((i_colour >> 8) & 0xff), ((i_colour >> 16) & 0xff)
def checkPartyMemberHealth(autohotpy, x, y): color = win32gui.GetPixel(win32gui.GetDC(win32gui.GetActiveWindow()), x, y) r, g, b = rgbint2rgbtuple(color) if r < 75: print("Party member [{},{}] is at RGB: {}, {}, {}".format( x, y, r, g, b)) click(autohotpy, x, y) keyToPress = getPressByKey(autohotpy, HEAL_PARTY_MEMBER_KEY) keyToPress.press()
def work(money, page): LeftClick(read_conf('action1')[0], read_conf('action1')[1]) # 设置金额 time.sleep(0.8) # 延时1s LeftClick_with_screen(read_conf('action2')[0], read_conf('action2')[1], local_action='action2', action='now2', size='60x30') # 添加收款理由 time.sleep(0.4) # LeftClick(53, 666) # 点击输入 # time.sleep(0.5) num = conf.get('settings', 'num') no = '-0' + str(page) reason = num + '-' + str(money) + no #print(reason # time.sleep(0.2) win32api.SendMessage(w3, win32con.WM_SETTEXT, None, str(reason)) # time.sleep(0.2) LeftClick(read_conf('action3')[0], read_conf('action3')[1]) # 点击发送 time.sleep(0.4) LeftClick(read_conf('action4')[0], read_conf('action4')[1]) # 点击输入 time.sleep(0.4) win32api.SendMessage(w3, win32con.WM_SETTEXT, None, str(money)) time.sleep(0.4) LeftClick(read_conf('action5')[0], read_conf('action5')[1]) # 点击发送 time.sleep(0.4) int = 0 count = 0 while int != 15371536: # time.sleep(0.2) win1 = win32gui.GetWindowDC(w1) int = win32gui.GetPixel(win1, read_conf('action6')[0], read_conf('action6')[1]) # 获取确定像素 #print(int) if int != 15371536: if count == 50: count = 0 b_text = u'长时间确定无响应' b = input(b_text) # save(money,page) else: time.sleep(0.2) print('wait a moment') count += 1 LeftClick(read_conf('action6')[0], read_conf('action6')[1]) # 点击确定 time.sleep(0.5) save2(money, page)
def get_pixel_colour(i_x, i_y): i_desktop_window_id = win32gui.GetDesktopWindow() i_desktop_window_dc = win32gui.GetWindowDC(i_desktop_window_id) long_colour = win32gui.GetPixel(i_desktop_window_dc, i_x, i_y) i_colour = int(long_colour) win32gui.ReleaseDC(i_desktop_window_id,i_desktop_window_dc) r,g,b = (i_colour & 0xff), ((i_colour >> 8) & 0xff), ((i_colour >> 16) & 0xff) grayscale = (r+g+b)/3 return int(grayscale)
def xiazhu1(s, hwnd): time.sleep(0.5) ##win32gui.SetForegroundWindow(hwnd) windll.user32.SetCursorPos(671, 336) hdc = win32gui.GetDC(hwnd) color = win32gui.GetPixel(hdc, 671, 336) win32gui.ReleaseDC(hwnd, hdc)
def for_debug(): hWnd = win32gui.FindWindow(None, "QQ游戏 - 连连看角色版") win32gui.SetForegroundWindow(hWnd) win32gui.SetActiveWindow(hWnd) hDC = win32gui.GetWindowDC(hWnd) print(Int2RGB(win32gui.GetPixel(hDC, 605, 588))) print(get_status()) win32gui.ReleaseDC(hWnd, hDC)
def get_pixel_colour(): color_dat = list() i_desktop_window_id = win32gui.GetDesktopWindow() i_desktop_window_dc = win32gui.GetWindowDC(i_desktop_window_id) for height in branch_heights: long_colour = win32gui.GetPixel(i_desktop_window_dc, ref_branch_x, height) i_colour = int(long_colour) color_dat.append(((i_colour & 0xff), ((i_colour >> 8) & 0xff), ((i_colour >> 16) & 0xff))) for color in color_dat: yield color
def getColor(hwnd=wg.GetDesktopWindow(), x=0, y=0): try: hdc = wg.GetWindowDC(hwnd) color = wg.GetPixel(hdc, x, y) wg.ReleaseDC(hwnd, hdc) return bgr2rgb(color) except pywintypes.error: return getColor(hwnd, x, y)
def get_color(self, pos_x, pos_y): try: color = win32gui.GetPixel(win32gui.GetDC(self.window_handle), pos_x, pos_y) except pywintypes.error: return None, None, None red = color & 255 green = (color >> 8) & 255 blue = (color >> 16) & 255 return red, green, blue
def get_pixel_color(hwnd, x, y, window_dc=None): if window_dc == None: window_dc = win32gui.GetWindowDC(hwnd) long_colour = win32gui.GetPixel(window_dc, x, y) i_colour = int(long_colour) colors = { "r": (i_colour & 0xff), "g": ((i_colour >> 8) & 0xff), "b": ((i_colour >> 16) & 0xff), } return colors["r"], colors["g"], colors["b"]
def poll_status(self): colour = win32gui.GetPixel(self.window.osrs_window, self.x, self.y) self.window.reinitialize() colour = int(colour) if self.is_active_colour(colour): self.active = True else: self.active = False return self.active
def read_cursor_position(self): ''' reads the cursor position and retrieve its color ''' while self.running: time.sleep(0.001) hdc = win32gui.GetDC(0) flags, hcursor, (x, y) = win32gui.GetCursorInfo() color = win32gui.GetPixel(hdc, x, y) color = self.rgb_int_to_hex(color) self.color_queue.put(color)
def get_pixel_color(x: int, y: int, debug: bool = False) -> str: """Get the color of selected pixel in HEX.""" dc = win32gui.GetWindowDC(Window.id) rgba = win32gui.GetPixel(dc, x + 8 + Window.x, y + 8 + Window.y) win32gui.ReleaseDC(Window.id, dc) r = rgba & 0xff g = rgba >> 8 & 0xff b = rgba >> 16 & 0xff if debug: print(Inputs.rgb_to_hex((r, g, b))) return Inputs.rgb_to_hex((r, g, b))