pyautogui.displayMousePosition() none

Viewed 27

I'm using pycharm and this is my code.

import pyautogui

while True:

    position = pyautogui.displayMousePosition()
    print(position)

After I hit play, the code starts working however the only response I get is Press "Ctrl-C to quit" and after I cancel the code an infinite list of none appears.

1 Answers

"pyautogui.DisplayMousePosition()" is more complex. You can search why it's not working but you can use the code below.

import pyautogui

while True:
   x, y = pyautogui.position()  # Setting x and y to the coordinates of mouse
   print(x, y)  # Printing x and y values

You can say "print(pyautogui.position().x, pyautogui.position().y)" but if you want to use x and y on something diffrent, use "x,y=pyautogui.position()". Note that the code above will print coordinates so fast until closing the program :)

Related