Python Forum

Full Version: Change variable value during a while loop?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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 x
So 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
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.
(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