由于ctypes,您可以使用低级Windows API。请参见下面的示例(改编自我未测试过的内容,但应该可以)
import ctypesMOUSEEVENTF_MOVE = 0x0001 # mouse moveMOUSEEVENTF_ABSOLUTE = 0x8000 # absolute moveMOUSEEVENTF_MOVEABS = MOUSEEVENTF_MOVE + MOUSEEVENTF_ABSOLUTEMOUSEEVENTF_LEFTDOWN = 0x0002 # left button down MOUSEEVENTF_LEFTUP = 0x0004 # left button up MOUSEEVENTF_CLICK = MOUSEEVENTF_LEFTDOWN + MOUSEEVENTF_LEFTUPdef click(x, y): #move first x = 65536L * x / ctypes.windll.user32.GetSystemMetrics(0) + 1 y = 65536L * y / ctypes.windll.user32.GetSystemMetrics(1) + 1 ctypes.windll.user32.mouse_event(MOUSEEVENTF_MOVEABS, x, y, 0, 0) #then click ctypes.windll.user32.mouse_event(MOUSEEVENTF_CLICK, 0, 0, 0, 0)
更新:我没有测试下面的代码,但我认为它应该可以帮助您编写一些内容来获得孩子的位置。然后,您可以尝试单击正确的位置。
CHILD= Nonedef the_callback(child_hwnd, regex): '''Pass to win32gui.EnumWindows() to check all the opened windows''' if re.match(regex, win32gui.GetWindowText(child_hwnd)): CHILD= child_hwndwin32gui.EnumChildWindows(hwnd, the_callback, regex)if CHILD: (x_tl, y_tl, x_br, y_br) = win32gui.GetWindowRect(CHILD)



