简体   繁体   中英

X,Y Coordinates Convert

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

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM