mercredi 7 juillet 2021

Python: Neither if nor else trigger inside of a while true loop

I'm trying to make the user's mouse cursor move in a rectangle pattern (def moves_Cursor) while inputting x (def holds_X) when the user is holding c (def variable).

The variable def is being called upon and print statements work inside of it but neither the print statement inside of if nor else are triggering and he program therefore doesn't work.

General optimization tips are also appreciated.

import threading
import pyautogui
import keyboard
pyautogui.FAILSAFE = False
pyautogui.PAUSE = 0
move = False


def moves_Cursor():
    while True:
        if move == True:
            pyautogui.moveTo(980, 560, 0.3)
            pyautogui.moveTo(980, 520, 0.3)
            pyautogui.moveTo(940, 520, 0.3)
            pyautogui.moveTo(940, 560, 0.3)


def holds_X():
    while True:
        if move == True:
            pyautogui.press('x')


def variable():
    while True:
        if keyboard.is_pressed('c'):
            print("pressed")
            move = True
        else:
            print("else")
            var = False


threading.Thread(target=moves_Cursor).start()
threading.Thread(target=holds_X).start()
threading.Thread(target=variable).start()

Thanks in advance!

Aucun commentaire:

Enregistrer un commentaire