I'm writing a program that moves my mouse (using pyautogui lib) if it has not been moved in x amount of seconds. I take the X,Y coordinates twice once at the start and then again after the time delay, then compare both X and Y values against the previous one. I've having issues with my if statement which in theory should do the above but after testing it out it doesn't work as expected. Can anyone suggest any edits I can a make to fix this simple issue.
Here's my code:
#!/usr/bin/env python3
import pyautogui
import time
currentMouseX, currentMouseY = pyautogui.position() #Grabs X,Y mouse position
print("position X1 is", currentMouseX)
print("position Y1 is", currentMouseY)
X1 = currentMouseX
Y1 = currentMouseY
time.sleep(3)
currentMouseX2, currentMouseY2 = pyautogui.position() #Grabs second X,Y position after 3 seconds
X2 = currentMouseX
Y2 = currentMouseY
print("position X2 is", currentMouseX2)
print("position Y2 is", currentMouseY2)
**if ((X1 == X2) and (Y1 == Y2)):
print ("!!! MOVE MOUSE !!!")
else:
print("Mouse does not need to be moved")**
FYI: I've left the if statement very simple as I'd like it working before I continue with the program. Any help is very much appreciated.
Aucun commentaire:
Enregistrer un commentaire