Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to print out 'Live' mouse position coordinates using pyautogui?

I used lots of different source codes, and even copied and pasted but I keep getting random symbols that shift when i move my mouse over them here is my code...

import pyautogui, time, sys
print('Press Ctrl-C to quit.')
try:
    while True:
        CurserPos = pyautogui.position()
        print('\b' * len(CurserPos), end='\r')
        sys.stdout.flush()

I will show the output as an image. I am rather new to Python and would really appreciate some expert advice. Thanks

like image 256
SovietStormSam Avatar asked Jun 13 '17 23:06

SovietStormSam


People also ask

How do I get mouse coordinates in Pyautogui?

How do I get the mouse position in Python using Pyautogui? To determine the mouse's current position, we use the statement, pyautogui. position(). This function returns a tuple of the position of the mouse's cursor.

How do I get the XY coordinates of a mouse Python?

How do you find XY coordinates on a mouse? It can be find using the clientX and clientY property: ClientX: It gives the horizontal coordinate of the event. ClientY: It gives the vertical coordinate of the mouse.

How do I find my mouse coordinates?

Once you're in Mouse settings, select Additional mouse options from the links on the right side of the page. In Mouse Properties, on the Pointer Options tab, at the bottom, select Show location of pointer when I press the CTRL key, and then select OK. To see it in action, press CTRL.


2 Answers

This code will print the live position of your mouse after every one second.

import pyautogui as py #Import pyautogui
import time #Import Time

while True: #Start loop
    print (py.position())
    time.sleep(1)

Pyautogui can programmatically control the mouse & keyboard.

More information about it can be found here https://pypi.org/project/PyAutoGUI/

like image 96
Henul Avatar answered Nov 02 '22 22:11

Henul


Code :

import pyautogui
pyautogui.displayMousePosition()

Here is some output :

Press Ctrl-C to quit.
X:  0 Y: 1143 RGB: ( 38,  38,  38)

Here is the video where this is being demonstrated https://youtu.be/dZLyfbSQPXI?t=809

like image 20
Joji Antony Avatar answered Nov 02 '22 21:11

Joji Antony