Python Forum
Change variable value during a while loop?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Change variable value during a while loop?
#1
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
Reply
#2
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.
Reply
#3
(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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Variable definitions inside loop / could be better? gugarciap 2 375 Jan-09-2024, 11:11 PM
Last Post: deanhystad
  How to create a variable only for use inside the scope of a while loop? Radical 10 1,526 Nov-07-2023, 09:49 AM
Last Post: buran
  Nested for loops - help with iterating a variable outside of the main loop dm222 4 1,532 Aug-17-2022, 10:17 PM
Last Post: deanhystad
  loop (create variable where name is dependent on another variable) brianhclo 1 1,103 Aug-05-2022, 07:46 AM
Last Post: bowlofred
  Multiple Loop Statements in a Variable Dexty 1 1,175 May-23-2022, 08:53 AM
Last Post: bowlofred
Big Grin Variable flag vs code outside of for loop?(Disregard) cubangt 2 1,131 Mar-16-2022, 08:54 PM
Last Post: cubangt
  How to save specific variable in for loop in to the database? ilknurg 1 1,110 Mar-09-2022, 10:32 PM
Last Post: cubangt
  How to add for loop values in variable paulo79 1 1,411 Mar-09-2022, 07:20 PM
Last Post: deanhystad
  Using Excel Cell As A Variable In A Loop knight2000 7 4,015 Aug-25-2021, 12:43 PM
Last Post: snippsat
  Change the varaible in For Loop quest 2 1,681 Aug-13-2021, 03:35 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020