Change variable value during a while loop? - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Change variable value during a while loop? (/thread-30969.html) |
Change variable value during a while loop? - penahuse - Nov-15-2020 Hi! Is there a way to hange variable value during a while loop? example: import win32api global x x = 1 if win32api.GetAsyncKeyState(0x70): x = 4 def lmb_down(): lmb_state = win32api.GetKeyState(0x01) return lmb_state < 0 while lmb_down(): move_mouse xSo is possible change the value of x during the while loop? I mean if I press F1 while im pressing left mouse button and my mouse is moving 1 can it move 4? Thanks RE: Change variable value during a while loop? - bowlofred - Nov-15-2020 Put your check (the GetAsyncKeyState call) into the loop as well. Make sure it has an else clause to set it back to 1 when the key is up. RE: Change variable value during a while loop? - penahuse - Nov-15-2020 (Nov-15-2020, 11:41 PM)bowlofred Wrote: Put your check (the GetAsyncKeyState call) into the loop as well. Make sure it has an else clause to set it back to 1 when the key is up. Thank you for answer. The "real" code is a bit more complex so would be great if was possible to do it without another check inside the loop |