I am trying to simulate right mouse click to WoW, I managed to send keyboard presses and the mouse click to minimized window without activating it, but for the mouse clicks it just doesn't click where I want. If I do it in activated window the cursors position is 959, 519, but if I try it with
win32api.PostMessage(hwndMain, win32con.WM_RBUTTONDOWN, 0, 34014143)
or
win32api.PostMessage(hwndMain, win32con.WM_RBUTTONDOWN, 959, 519)
it just wont work, it does click only within WoW but it still uses the cursor real position.
I am fairly new to Python, would u know a solution?
Below whole code I use
from pynput.keyboard import Key, Controller
import time
import random
from tkinter import *
import win32api
import win32con
from window_list import window_list
keyboard = Controller()
looping = 0
hwndMain = window_list["World of Warcraft"]
time.sleep(1)
def inter_attack():
for key in range(6):
time.sleep(random.uniform(0.5, 0.7))
win32api.PostMessage(hwndMain, win32con.WM_KEYDOWN, 0x46, 0)
win32api.PostMessage(hwndMain, win32con.WM_KEYUP, 0x46, 0)
time.sleep(random.uniform(2.5, 3.5))
win32api.PostMessage(hwndMain, win32con.WM_KEYDOWN, 0x32, 0)
win32api.PostMessage(hwndMain, win32con.WM_KEYUP, 0x32, 0)
#infinite loop
while looping == 0:
#time.sleep(1)
#win32api.SetCursorPos((959, 519)) # just to find if coordinates work and where to put the mouse click
time.sleep(0.1)
win32api.PostMessage(hwndMain, win32con.WM_RBUTTONDOWN, 0, 34014143)
win32api.PostMessage(hwndMain, win32con.WM_RBUTTONUP, 0, 34014143)
time.sleep(1.5)
win32api.PostMessage(hwndMain, win32con.WM_KEYDOWN, 0x35, 0)
win32api.PostMessage(hwndMain, win32con.WM_KEYUP, 0x35, 0)
inter_attack()