How to get coordinates by mouse click with Python?

Asked

Viewed 199 times

-1

I have a code that returns me the value of a color in hexadecimal in a given coordinate, in the case of the code the coordinates are 200 and 200, the problem is that keep putting these values by the keyboard is a bit laborious, would have some way to add these coordinates via a mouse click ?. type by clicking on the point where I want the coordinates go directly there, to getpixel()? Thank you very much

import pyautogui

pixelColor = pyautogui.screenshot().getpixel((200,200,)) pixelColor = '#%02x%02x%02x' % (pixelColor) print(pixelColor)

1 answer

-1

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

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

#retorna True se x & y estiverem dentro da tela
print ("\nEsta dentro da tela?")
resp = pyautogui.onScreen(x, y)
print (str(resp))
  • Thank you champ but I think I expressed myself badly, I did not want the mouse coordinates, I wanted to pick the coordinates with the mouse click instead of me putting the values through the keyboard. I click on my screen and it captures the coordinates and throws them in my code.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.