May-31-2020, 05:44 PM
(May-31-2020, 05:39 PM)DreamingInsanity Wrote: I did some testing. If you use 'GetAsyncKeyState' it should work. 'GetAsyncKeyState' is basically 'isKeyPressed' so the moment you let go of a button, it will no longer return true.
def button1_pressed(): # Returns true if the left mouse button is pressed button1_state = win32api.GetAsyncKeyState(0x01) return bool(button1_state) def button2_pressed(): # Returns true if the right mouse button is pressed button2_state = win32api.GetAsyncKeyState(0x02) return bool(button2_state) def button3_pressed(): # Returns true if the M button is pressed button3_state = win32api.GetAsyncKeyState(0x4D) return bool(button3_state) while True: while button1_pressed() and button2_pressed(): # No matter which one is pressed first to me print("do some") while button3_pressed(): # Only if it is pressed after button1 and button2 are pressed print("do some2") if button2_pressed() == 0: break # this only breaks the inner while loop break # added an extra break else it would just be stuck in an endless loop
Now it work like my old code:
1 - if user press "button1" and "button2" then "press button3"
Its ok to me "do some 2"
or
2 - if user "press button2" and "button1" then "press button3"
Its ok to me "do some 2"
but
3 - if user press "button"3 before "button1" and "button2"
Its not ok to "do some2", I need just to "do some"
The sequence of which button is pressed first matters to my purpose.. Can you help me with that?