Pyhton physical mouse click

15 views Asked by At

In a game, i did a market search for Price/unit. I need to click to a specific location but the game doesn't recognize my click with a code. I need to emulate a physical mouse click. I'm new to coding so i asked chatgpt.

import win32api
import win32con
import time

def click(x, y):
    win32api.SetCursorPos((x, y))  # Mouse'u belirtilen koordinata taşı
    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, x, y, 0, 0)  # Sol tıklama başlat
    time.sleep(0.1)  # Kısa bir süre beklet
    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, x, y, 0, 0)  # Sol tıklamayı bırak

if __name__ == "__main__":
    time.sleep(2)  # Kod çalıştırıldıktan 2 saniye sonra tıklama için beklenen süre
    click(528, 377)  # Belirtilen koordinatlarda sol tıklama yap

I also added a macro to my keyboard via Razer Synapse and pressed that macro via code. When i press Num2 it detects and presses. But it doesn't work with the code.

0

There are 0 answers