玩一个4399小游戏:
http://www.4399.com/flash/141202_2.htm#his_index_6
[Python] 纯文本查看 复制代码 from ctypes import * # 获取屏幕上某个坐标的颜色
import pyautogui
import win32api,win32gui,win32con
def get_color(x, y):
gdi32 = windll.gdi32
user32 = windll.user32
hdc = user32.GetDC(None) # 获取颜色值
pixel = gdi32.GetPixel(hdc, x, y) # 提取RGB值
r = pixel & 0x0000ff
g = (pixel & 0x00ff00) >> 8
b = pixel >> 16
return [r, g, b]
# hwnd = 133196
# win32gui.SetForegroundWindow(hwnd)
def doClick(cx, cy,hwnd=hwnd):
long_position = win32api.MAKELONG(cx, cy) # 模拟鼠标指针 传送到指定坐标
win32api.PostMessage(hwnd, win32con.WM_LBUTTONDOWN, win32con.MK_LBUTTON, long_position) # 模拟鼠标按下
win32api.PostMessage(hwnd, win32con.WM_LBUTTONUP, win32con.MK_LBUTTON, long_position) # 模拟鼠标弹起
pyautogui.PAUSE == 0.001
for i in range(999):
y = 613
if get_color(729, y) == [17, 17, 17]:
pyautogui.click(729, y)
if get_color(781, y) == [17, 17, 17]:
pyautogui.click(781, y)
if get_color(831, y) == [17, 17, 17]:
pyautogui.click(831, y)
if get_color(880, y) == [17, 17, 17]:
pyautogui.click(880, y)
用pyautogui.click()可以每秒点100次左右,用win32api.PostMessage()点会慢一点,有没有更快的? |