
Originally Posted by
3rd
I had a need to click on the coordinates once every 30 seconds when the game is inactive in full screen window mode, I spent a lot of time but it is apparently impossible to do on ahk, and I couldn't figure it out on C# C++, maybe there is someone here who can make such a program? X 333 Y 242
I see a lot of people trying to send clicks to a game, and honestly, it's almost impossible using ControlClick in AHK.
That's because the game runs with DirectX or OpenGL, and those kinds of UIs are tricky to deal with.
I have a simple code here that gets around that — it sends mouse clicks (left or right) directly to the game. You can even send other mouse buttons too.
This is a simple script I made that you can try out.
All you need to do is install any version of Python (3.x or above).
Just make sure you enable the "Add python.exe to PATH" option during installation.
Once it's installed, open CMD and run this command to install the required library:
Code:
pip install pywin32
Now you can run the code, and it should work just fine.
python code:
Code:
import time, win32gui, win32con
def send_mouse_click(windowID, button="left", x=0, y=0, state=None):
"""
Sends a mouse click (left or right) to a specific window using SendMessage.
A fixed coordinate (x, y) is used for the click location; you can modify this if needed.
Parameters:
windowID: Handle of the target window.
button (str): Type of click ("left" or "right").
state (str or None): State of the click:
- None: Sends a full click (down and up).
- "down": Sends only the mouse button down event.
- "up": Sends only the mouse button up event.
"""
lParam = (y << 16) | (x & 0xFFFF) # Combine x and y into a single lParam value
button = button.lower()
if button == "left":
if state is None:
# Send left mouse button down and up
win32gui.PostMessage(windowID, win32con.WM_LBUTTONDOWN, win32con.MK_LBUTTON, lParam)
win32gui.PostMessage(windowID, win32con.WM_LBUTTONUP, 0, lParam)
elif state.lower() == "down":
# Send only left mouse button down
win32gui.PostMessage(windowID, win32con.WM_LBUTTONDOWN, win32con.MK_LBUTTON, lParam)
elif state.lower() == "up":
# Send only left mouse button up
win32gui.PostMessage(windowID, win32con.WM_LBUTTONUP, 0, lParam)
else:
raise ValueError("State for mouse click must be 'down', 'up' or None.")
elif button == "right":
if state is None:
# Send right mouse button down and up
win32gui.PostMessage(windowID, win32con.WM_RBUTTONDOWN, win32con.MK_RBUTTON, lParam)
win32gui.PostMessage(windowID, win32con.WM_RBUTTONUP, 0, lParam)
elif state.lower() == "down":
# Send only right mouse button down
win32gui.PostMessage(windowID, win32con.WM_RBUTTONDOWN, win32con.MK_RBUTTON, lParam)
elif state.lower() == "up":
# Send only right mouse button up
win32gui.PostMessage(windowID, win32con.WM_RBUTTONUP, 0, lParam)
else:
raise ValueError("State for mouse click must be 'down', 'up' or None.")
else:
raise ValueError("Button must be 'left' or 'right'.")
# Example usage: repeatedly send left-click to a window named "Trove"
hwnd = win32gui.FindWindow(None, "Trove")
while True:
send_mouse_click(hwnd, "left", 333, 242)
time.sleep(30) # Wait 30 seconds between clicks