Get X and Y from the screen using PYTHON

2

I want to create a bot (macro) that performs some click tasks, so I'm using pyautogui in python !

But I do not have much experience with X and Y, and I'm testing it manually and boring.

I would like to get the x and y by clicking on the screen, for example, I click on this location on the screen and display the X and Y of the click location on the console. Possible?

    
asked by anonymous 23.10.2017 / 02:54

2 answers

2

Well one way to do this in pyautogui would be basically like this:

#pegar o retorno da posicao atual de x e y do mouse e passar o valor da tupla para as duas variaveis
x, y = pyautogui.position()
print "Posicao atual do mouse:"
print "x = "+str(x)+" y = "+str(y)

print""

#retorna verdadeiro se x & y estiverem dentro da tela
print "Esta dentro da tela?"
resp = pyautogui.onScreen(x, y)
print str(resp)
  

Reference: pyautogui

    
23.10.2017 / 15:22
1

A quick solution using PyUserInput and without going into operating system specificities: instances of mouse have method position() , which returns the position (X, Y) with each call:

$ pip install git+https://github.com/PyUserInput/PyUserInput.git
>>> import pymouse
>>> mouse = pymouse.PyMouse()
>>> mouse.position()
(562, 528)
>>> mouse.position()
(1259, 195)
>>> mouse.position()
(157, 259)
    
23.10.2017 / 05:53