I searched a lot for simulate mouse clicks and movement for directx games. I found a good sources about keypressing but nothing for mouse. Actually there is good stackoverflow topic about key press with direct input (Simulate Python keypresses for controlling a game). But i don't have enough experience to make it work for mouse clicks on certain location.
I tried a lot of python module like pyautogui, win32 etc. they are not working. Even i tried to click it over autohotkey with sending arguments to '.ahk' file but it's not stable and not a good way. I will appreciate for every comment. I'm working on just this click for 2 days and i'm totally lost. Thanks!
I found this code from reddit for clicks in game but it's not working either.
import ctypes
PUL = ctypes.POINTER(ctypes.c_ulong)
class KeyBdInput(ctypes.Structure):
_fields_ = [("wVk", ctypes.c_ushort),
("wScan", ctypes.c_ushort),
("dwFlags", ctypes.c_ulong),
("time", ctypes.c_ulong),
("dwExtraInfo", PUL)]
class HardwareInput(ctypes.Structure):
_fields_ = [("uMsg", ctypes.c_ulong),
("wParamL", ctypes.c_short),
("wParamH", ctypes.c_ushort)]
class MouseInput(ctypes.Structure):
_fields_ = [("dx", ctypes.c_long),
("dy", ctypes.c_long),
("mouseData", ctypes.c_ulong),
("dwFlags", ctypes.c_ulong),
("time", ctypes.c_ulong),
("dwExtraInfo", PUL)]
class Input_I(ctypes.Union):
_fields_ = [("ki", KeyBdInput),
("mi", MouseInput),
("hi", HardwareInput)]
class Input(ctypes.Structure):
_fields_ = [("type", ctypes.c_ulong),
("ii", Input_I)]
def set_pos(x, y):
x = 1 + int(x * 65536./1920.)
y = 1 + int(y * 65536./1080.)
extra = ctypes.c_ulong(0)
ii_ = Input_I()
ii_.mi = MouseInput(x, y, 0, (0x0001 | 0x8000), 0, ctypes.pointer(extra))
command = Input(ctypes.c_ulong(0), ii_)
ctypes.windll.user32.SendInput(1, ctypes.pointer(command), ctypes.sizeof(command))
def left_click():
extra = ctypes.c_ulong(0)
ii_ = Input_I()
ii_.mi = MouseInput(0, 0, 0, 0x0002, 0, ctypes.pointer(extra))
x = Input(ctypes.c_ulong(0), ii_)
ctypes.windll.user32.SendInput(1, ctypes.pointer(x), ctypes.sizeof(x))
extra = ctypes.c_ulong(0)
ii_ = Input_I()
ii_.mi = MouseInput(0, 0, 0, 0x0004, 0, ctypes.pointer(extra))
x = Input(ctypes.c_ulong(0), ii_)
ctypes.windll.user32.SendInput(1, ctypes.pointer(x), ctypes.sizeof(x))
left_click() function is working but click works with all modules what i need is set_pos() to work but unfortunately it's not.