Jump to content

How To If Winactive check for 2 different programs are active


Recommended Posts

 

 

I have a hotkey script and it runs on ifwinactive and it will do XYZ but I cant figure out how to have it lookout for 2 separate programs

 

 If WinActive('[CLASS:AE_CApplication_15.1]','Chrome - Chromium')

doenst work. but they work on their own

i.e.

 If WinActive('Chrome - Chromium') - works

 If WinActive('[CLASS:AE_CApplication_15.1]') - works

 

how can I have it look out for both? 

 

 

 

Link to comment
Share on other sites

17 minutes ago, Nine said:

If WinActive('Chrome - Chromium') and WinActive('[CLASS:AE_CApplication_15.1]') then XYZ

 

That didnt work for me but the OR did

 

5 minutes ago, mikell said:

... or 'or'  :)

 

lol I thought of that in my head but I didnt think it would be a code type of thing lol, thanks it worked and easy enough. 

Link to comment
Share on other sites

 

8 hours ago, mikell said:

... or 'or'  :)

 

I initially thought this worked cause well it performed the action when I tested it but what I failed to test was if it DOES NOT perform the action if those windows arent active and well this or seems to nullify the 'IF winactive" statement and just triggers the action no matter what when called from hotkey

 

this is my exact script Im working with.

 

 

#include <AutoItConstants.au3>

HotKeySet("{NUMPADADD}", "ENABLE")

While 1
    Sleep(100)
WEnd

Func ENABLE()
    If WinActive('Chrome - Chromium') Or ('[CLASS:AE_CApplication_15.1]')   Then
       Switch @HotKeyPressed
       Case "{NUMPADADD}"

                 $iPID = Run("rundll32.exe shell32.dll,Control_RunDLL mmsys.cpl,,1", @ScriptDir, @SW_HIDE)



                  AutoItSetOption("MouseCoordMode",2)
                  WinWaitActive("[CLASS:#32770]", "", 10)
                  MouseClick($MOUSE_CLICK_RIGHT, 83, 106,1, 0)
                  send('E')

                  Sleep(100)
ProcessClose($iPID)

        Case "{NUMPADADD}"

           Exit
        EndSwitch
     Else
         HotKeySet(@HotKeyPressed)
        Send(@HotKeyPressed)
        HotKeySet(@HotKeyPressed, "ENABLE")
    EndIf
 EndFunc

 

 

 

 

 

 

 

 

Link to comment
Share on other sites

I don't understand the reason for all this hotkey management. Isn't this enough ?

#include <AutoItConstants.au3>

HotKeySet("{NUMPADADD}", "ENABLE")

While 1
    Sleep(10)
WEnd

Func ENABLE()
    If WinActive('Chrome - Chromium') Or ('[CLASS:AE_CApplication_15.1]')   Then
                 $iPID = Run("rundll32.exe shell32.dll,Control_RunDLL mmsys.cpl,,1", @ScriptDir, @SW_HIDE)

                  AutoItSetOption("MouseCoordMode",2)
                  WinWaitActive("[CLASS:#32770]", "", 10)
                  MouseClick($MOUSE_CLICK_RIGHT, 83, 106,1, 0)
                  send('E')

                  Sleep(100)
                  ProcessClose($iPID)
     EndIf
EndFunc


 

Link to comment
Share on other sites

@JamesHustle

If WinActive('Chrome - Chromium') Or ('[CLASS:AE_CApplication_15.1]')   Then

should be

If WinActive('Chrome - Chromium') Or WinActive('[CLASS:AE_CApplication_15.1]') Then ; Are you sure that's an OR and not an AND?
                                                                                    ; The condition to continue with the script is that
                                                                                    ; OR a Window is active, OR another one it is?

And, I agree with @mikell :)

Click here to see my signature:

Spoiler

ALWAYS GOOD TO READ:

 

Link to comment
Share on other sites

1 hour ago, mikell said:

I don't understand the reason for all this hotkey management. Isn't this enough ?

#include <AutoItConstants.au3>

HotKeySet("{NUMPADADD}", "ENABLE")

While 1
    Sleep(10)
WEnd

Func ENABLE()
    If WinActive('Chrome - Chromium') Or ('[CLASS:AE_CApplication_15.1]')   Then
                 $iPID = Run("rundll32.exe shell32.dll,Control_RunDLL mmsys.cpl,,1", @ScriptDir, @SW_HIDE)

                  AutoItSetOption("MouseCoordMode",2)
                  WinWaitActive("[CLASS:#32770]", "", 10)
                  MouseClick($MOUSE_CLICK_RIGHT, 83, 106,1, 0)
                  send('E')

                  Sleep(100)
                  ProcessClose($iPID)
     EndIf
EndFunc


 

 

I've been using this setup for a long while now, Never had any issues, I remember running it your version and a few others way but I used to run into issues like the script eating up alot of resources such as memory, or hijacking the key so its not usuable anymore etc, and with this way I never ran into those issues again. 

 

1 hour ago, FrancescoDiMuro said:

@JamesHustle

If WinActive('Chrome - Chromium') Or ('[CLASS:AE_CApplication_15.1]')   Then

should be

If WinActive('Chrome - Chromium') Or WinActive('[CLASS:AE_CApplication_15.1]') Then ; Are you sure that's an OR and not an AND?
                                                                                    ; The condition to continue with the script is that
                                                                                    ; OR a Window is active, OR another one it is?

And, I agree with @mikell :)

 

thanks lol another simple error I overlooked, and yes its OR, yeah the condition to continue is on that winactive. What this script does is simple enable my microphone with a single hotkey when Im in 2 certain programs cause thats all i need the mic for, and I also have a disable script which is basically the same thing just to disable. 

 

and i answered why I use all the hotkey management above.  Basically its what worked for me when I first started without issue so I stuck with it. 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...