Author Topic: How Do I Invoke A Shortcut Only If A Target Application Is Running?  (Read 855 times)

dryh2o

  • Newbie
  • *
  • Posts: 16
I have four spoken commands - "tap up" "tap down" "tap left" and "tap right" - that move the mouse one "mickey" in the specified direction. I would also like to assign the arrow keys to these, but doing so means that when the game isn't running, the arrow keys are still going to run the commands versus act as they normally do.

I tried the "send command to this target" option thinking that maybe with that checked, the command wouldn't run if the target window wasn't running, but it still does.

What I am aiming for, if it's possible, is to have the command only run when the game (Ark in this case) is running so that when I return to the desktop, my arrow keys function normally without my having to switch profiles or exit VA. I searched the documentation but found no way to do this but I may not be searching the wrong keywords.

As always, any help is appreciated.

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: How Do I Invoke A Shortcut Only If A Target Application Is Running?
« Reply #1 on: December 22, 2020, 10:24:06 PM »
If you enable the "Stop command if target window focus is lost" option alongside the "Send command to this target:"  option, the command should not run if the target is not available.

dryh2o

  • Newbie
  • *
  • Posts: 16
Re: How Do I Invoke A Shortcut Only If A Target Application Is Running?
« Reply #2 on: December 23, 2020, 02:46:24 PM »
Thanks for your help. Unfortunately, that only disables those keys when I was not in the game leaving me without arrow keys otherwise. When I slept on the problem, I remembered AutoHotkey and was able to do what I needed there with the following commands (for anyone curious):

#IfWinActive ahk_exe ShooterGame.exe
Left::MouseMove, -1, 0, 0, R
Right::MouseMove, +1, 0, 0, R
Up::MouseMove, 0, +1, 0, R
Down::MouseMove, 0, -1, 0, R
#IfWinActive

So basically, if the "ShooterGame.exe" process has focus, change the arrow keys to move the mouse. If it doesn't have focus, no changes are made to those keys and they function as they normally do.

Thanks again for your help.

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: How Do I Invoke A Shortcut Only If A Target Application Is Running?
« Reply #3 on: December 23, 2020, 02:56:47 PM »
It is not currently possible to dynamically enable or disable the "Do not allow key to be passed through" option.

Closest you can get with VoiceAttack is to have the "Do not allow key to be passed through" option enabled, but use a condition to perform your replacement function when an application is running/window is active, and otherwise send a keypress, E.G.
Code: [Select]
Begin Text Compare : [{ACTIVEWINDOWPROCESSNAME}] Equals 'ShooterGame'
    Move mouse left [1] relative mickey(s) (from cursor position)
Else
    Press down Left key
    Start Loop While :  Keyboard Key 'Left Arrow' Is Pressed
    End Loop
    Release Left key
End Condition

dryh2o

  • Newbie
  • *
  • Posts: 16
Re: How Do I Invoke A Shortcut Only If A Target Application Is Running?
« Reply #4 on: December 23, 2020, 03:52:06 PM »
I used to use the very basic features of VoiceAttack, but over the past year or so I have begun to utilize much more advanced features. I appreciate the information and I'll add it to my notes.