Python Forum
[HELP] Nested conditional? double condition followed by another condition.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[HELP] Nested conditional? double condition followed by another condition.
#15
(May-31-2020, 08:00 PM)DreamingInsanity Wrote:
(May-31-2020, 07:08 PM)penahuse Wrote: Yes, Im using your code, its right: if I hold M without button 1 and button 2 its suposed to do nothing indeed.

If I presse button 1 + button 2 the output is "do some"

But if you press M then press button 1 and button 2 too (so M + button 1+ button2 are pressed right now) the output is "do some 2" but I need just "do some" because M was pressed before other buttons.

Different is if I press buttom 1 + 2 and after buttom M, in this case i want "do some 2"
Right now I understand - sorry!

I hope this works:
import win32api
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() and not button3_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
it's hard to test since if I hold down 'm' it just types a load of m's so I don't know if it's working.

Mate, you almost got it..

now if button M is not pressed it do nothing but if the the M is pressed before button1 and button2 it need to "do some"

right now with this code if I presse M before button 1 and button 2 nothing happens
Reply


Messages In This Thread
RE: [HELP] Nested conditional? double condition followed by another condition. - by penahuse - May-31-2020, 08:08 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Get an average of the unique values of a column with group by condition and assign it klllmmm 0 445 Feb-17-2024, 05:53 PM
Last Post: klllmmm
  unable to remove all elements from list based on a condition sg_python 3 529 Jan-27-2024, 04:03 PM
Last Post: deanhystad
  Python Alteryx QS-Passing pandas dataframe column inside SQL query where condition sanky1990 0 791 Dec-04-2023, 09:48 PM
Last Post: sanky1990
  Sent email based on if condition stewietopg 1 929 Mar-15-2023, 08:54 AM
Last Post: menator01
  Replacing values ​​in Mysql with a condition stsxbel 0 662 Mar-05-2023, 08:20 PM
Last Post: stsxbel
  create new column based on condition arvin 12 2,429 Dec-13-2022, 04:53 PM
Last Post: jefsummers
Question Running an action only if time condition is met alexbca 5 1,399 Oct-27-2022, 02:15 PM
Last Post: alexbca
  How to assign a value to pandas dataframe column rows based on a condition klllmmm 0 886 Sep-08-2022, 06:32 AM
Last Post: klllmmm
  How to write the condition for deleting multiple lines? Lky 3 1,210 Jul-10-2022, 02:28 PM
Last Post: Lky
  Can I check multi condition for 1 item in a easy way? korenron 4 1,637 May-01-2022, 12:43 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