Untitled

 avatar
unknown
plain_text
a month ago
1.5 kB
2
Indexable
import ctypes
import time

# Define the structures and constants
class POINT(ctypes.Structure):
    _fields_ = [("x", ctypes.c_long), ("y", ctypes.c_long)]

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", ctypes.POINTER(ctypes.c_ulong)),
    ]

class INPUT_I(ctypes.Union):
    _fields_ = [("mi", MOUSEINPUT)]

class INPUT(ctypes.Structure):
    _fields_ = [("type", ctypes.c_ulong), ("ii", INPUT_I)]

INPUT_MOUSE = 0
MOUSEEVENTF_LEFTDOWN = 0x0002
MOUSEEVENTF_LEFTUP = 0x0004

def click():
    # Create an instance of the INPUT structure
    extra = ctypes.c_ulong(0)
    ii = INPUT_I()
    
    # Set up the INPUT structure for a mouse click
    ii.mi = MOUSEINPUT(0, 0, 0, MOUSEEVENTF_LEFTDOWN, 0, ctypes.pointer(extra))
    command = INPUT(ctypes.c_ulong(INPUT_MOUSE), ii)
    
    # Send the mouse down event
    ctypes.windll.user32.SendInput(1, ctypes.pointer(command), ctypes.sizeof(command))
    
    # Set up the INPUT structure for a mouse release
    ii.mi = MOUSEINPUT(0, 0, 0, MOUSEEVENTF_LEFTUP, 0, ctypes.pointer(extra))
    command = INPUT(ctypes.c_ulong(INPUT_MOUSE), ii)
    
    # Send the mouse up event
    ctypes.windll.user32.SendInput(1, ctypes.pointer(command), ctypes.sizeof(command))

# Example usage: Click at the current cursor position
time.sleep(2)  # Wait for 2 seconds before clicking
click()
Leave a Comment