Author Topic: Run commands only if certain process is active  (Read 1935 times)

Ninja

  • Newbie
  • *
  • Posts: 8
Run commands only if certain process is active
« on: November 14, 2021, 05:00:58 PM »
Is there a way to let commands run only if a particular exe is the foreground window, else ignore all voice/keyboard/joystick/mouse commands if not active?

I could only think of adding this to the top of every command:
Code: [Select]
Set text [dcs] to 'dcs.exe'
Begin Text Compare : [{PROCESSFOREGROUND:dcs}] Equals '0'
    Exit Command
End Condition
Say, 'Active'

Is there a better option? Kinda like:
Code: [Select]
#IfWinActive in AutoHotKey.

Basically I don't want VA to work if I have Alt-Tab'd out of the target program

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4781
  • RTFM
Re: Run commands only if certain process is active
« Reply #1 on: November 14, 2021, 05:10:05 PM »
One approach would be to use the "Enable profile switching for the following windows or processes" in your profile, set to the process name or window title of your target application, combined with another profile that has that same option set to "*" (a single asterisk character, to designate it as the default profile) and contains no commands (or only commands you do still want to execute while the target application is not in the foreground).

Do make sure to check the "Enable Auto Profile Switching" option on the "General" tab of the VoiceAttack options window.

Ninja

  • Newbie
  • *
  • Posts: 8
Re: Run commands only if certain process is active
« Reply #2 on: November 14, 2021, 06:56:58 PM »
Thanks for the reply, Pfeil.

Since I use separate profiles for each aircraft in DCS, your solution would not switch back the original profile for me.

However it did give me an idea: use Alt-Tab as a hotkey to check if DCS is not active, and then just disable all of VA's Listening/KB/Mouse/Joystick input monitoring.
I used a loop to wait until DCS is active again to resume VA's own actions.

This way, the active profile need not be changed.

Here's what I did:
Code: [Select]
Set text [dcs] to 'DCS.exe'
Pause 0.5 seconds
Begin Text Compare : [{PROCESSFOREGROUND:dcs}] Equals '0'
    Stop VoiceAttack listening
    Disable Hotkeys
    Disable Mouse Shortcuts
    Disable Joysticks

    Start Loop While : [{PROCESSFOREGROUND:dcs}] Equals '0'
        Pause 0.5 seconds
    End Loop

    Start VoiceAttack listening
    Enable Hotkeys
    Enable Mouse Shortcuts
    Enable Joysticks
End Condition

SemlerPDX

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 291
  • Upstanding Lunatic
    • My AVCS Homepage
Re: Run commands only if certain process is active
« Reply #3 on: November 16, 2021, 02:43:22 PM »
That's a smart way to cut off commands when alt-tabbed into another process!  Well done!

Ninja

  • Newbie
  • *
  • Posts: 8
Re: Run commands only if certain process is active
« Reply #4 on: November 17, 2021, 05:18:02 PM »
Hehe thanks!