Home > other >  X,Y Coordinates Convert
X,Y Coordinates Convert

Time:02-26

I have written a program in which I am using pyautogui for autoclicking

My code

import pyautogui, time

time.sleep(5.5)
pyautogui.click(x=443, y=178)
time.sleep(0.5)

but the x, y coordinates which I am using are according to my monitor size which is 1920x1080

My Question: The x, y coordinates are according to 1920x1080 I want to change them in 1280x720 so that it supports on any monitor resolution. I wonder I can do that using numpy if yes then how?....if no then is there any other way to do it?.... Any help would be appreciated

Thank You

Regards

CodePudding user response:

Hope this helps:

import pyautogui, time

xCoef = 1280/1920
yCoef = 720/1080


def clickFunc(x,y):
    pyautogui.click(x=int(xCoef*x), y=int(y*yCoef))


time.sleep(5.5)
clickFunc(443,178)
time.sleep(0.5)
  • Related