I am trying to automate a tedious task in an idle clicker game (it is not competitive and scripting is generally considered fine by the community). I initially tried using AutoHotkey's ControlClick
, but this does not work with the game. I tried creating a Python script using various methods including win32api.mouse_event
, win32gui.PostMessage
, win32giu.SendMessage
, pywinauto
, pydirectinput
and maybe others I am forgetting.
I am able to send key presses using pywinauto.Application
module (code below), but cannot figure out how to send mouse clicks.
if(__name__ == "__main__"):
app = pywinauto.Application(backend='win32').connect(title_re="NGU Idle").window(title_re="NGU Idle")
while(True):
if keyboard.is_pressed("pause"): # just to exit the loop
break
app.send_keystrokes("w")
time.sleep(0.02)
I think the issue that I am facing, is that for most programs of this sort, there is a parent controller and a child controller to which background clicks can be sent, however Unity manages things differently. Using Window Spy
, the window has the class UnityWndClass
. Looking around at other threads on StackOverflow and elsewhere (e.g. Is there a way to send a click event to a window in the background in python?), the way this seems to be done in other programs is using hWnd
such as below (answer in linked thread), which doesn't work since hwnd1
is 0
:
def click(x, y):
hWnd = win32gui.FindWindow(None, "BlueStacks")
lParam = win32api.MAKELONG(x, y)
hWnd1= win32gui.FindWindowEx(hWnd, None, None, None)
win32gui.SendMessage(hWnd1, win32con.WM_LBUTTONDOWN, win32con.MK_LBUTTON, lParam)
win32gui.SendMessage(hWnd1, win32con.WM_LBUTTONUP, None, lParam)
click(100,100)
So, is this possible? Maybe not in Python? Any leads are welcome!