Author Topic: Sending Command to Specific App Without Changing Focus to That App  (Read 1818 times)

LinuxDevice

  • Newbie
  • *
  • Posts: 42
I'd like to simplify some key bindings across several applications, and to do that I'd like to send commands for specific applications (such as TrackIR or OBS Studio) such that those other applications do not go to the foreground, and thus put my running game in background. I have not figured out how to do that, and it seems I have to make bindings not conflicting with several apps if I want to send a command which does not force me out of my game.

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4781
  • RTFM
Re: Sending Command to Specific App Without Changing Focus to That App
« Reply #1 on: June 09, 2023, 03:31:22 AM »
Windows sends normal keyboard output to whichever application has focus. That is not VoiceAttack-specific.


For OBS in particular, it could be worth looking into something like this command line tool

Other applications may also offer alternative input methods to keyboard input (I.E. APIs). E.G. many media players do.

Starblue7

  • Full Member
  • ***
  • Posts: 131
Re: Sending Command to Specific App Without Changing Focus to That App
« Reply #2 on: June 09, 2023, 03:34:49 AM »
I know for Track IR,  I can push a command to it to [pause the tracking] and not get kicked out of the game and lose focus of the game.
I mean, in my VA profile, I don't specify in the command to send to any specific target.
However, the Profile General 'Send Commands to this target: >~GameProcess

TrackIR is minimiized and still picks up the keybind and does its thing without losing game focus.
I can also send a keybind to Joystick Gremlin also without losing the focus of the game.
I'm running the game in Windows Borderless.

Even though you specify at the profile level to send those binds to TrackIR and Joystick Gremlin, the game application will still maintain focus.  TrackIR and Joystick Gremlin will pick up the commands in the background, even though your profile sends those keys to the game process explicitly.

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4781
  • RTFM
Re: Sending Command to Specific App Without Changing Focus to That App
« Reply #3 on: June 09, 2023, 03:46:36 AM »
Those applications are specifically set up to listen for global hotkeys.

I assumed that's what the OP was referring to with
it seems I have to make bindings not conflicting with several apps if I want to send a command which does not force me out of my game.


I will mention that if an application offers global hotkeys but no other non-GUI input methods, it's worth checking whether they accept F13 to F24
Those aren't physically present on all but a few niche keyboards, but VoiceAttack can send them (though some applications may ignore them).

You can use the Key Chooser dropdown (opened by clicking the keyboard icon directly under the non-modifier key indicator on the configuration dialog for the keypress action) to select keys not present on your physical keyboard.


Some applications may also offer command line options that can affect a running instance (as VoiceAttack also does, E.G. the "-listeningoff" argument)

Starblue7

  • Full Member
  • ***
  • Posts: 131
Re: Sending Command to Specific App Without Changing Focus to That App
« Reply #4 on: June 09, 2023, 07:24:02 AM »
Oh damn.  that's kewl.  didn't know that.
Yeah, I was able to push the F13 key to TrackIR [Pause] Binding.
This opens up some doors :)

LinuxDevice

  • Newbie
  • *
  • Posts: 42
Re: Sending Command to Specific App Without Changing Focus to That App
« Reply #5 on: June 10, 2023, 02:59:39 PM »
Unfortunately, in "Edit a Command", the checkbox for "Send command to this target" causes that target to foreground. It doesn't seem to matter what application. If it is TrackIR, then that goes to foreground. If it is OBS Studio, then that goes to foreground. Am I missing something, or is there no choice but to switch focus to the app I'm naming for the case of naming a SPECIFIC target application using the "Send command to this target" checkbox?

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4781
  • RTFM
Re: Sending Command to Specific App Without Changing Focus to That App
« Reply #6 on: June 10, 2023, 03:27:34 PM »
The targeting options are specifically intended for making sure a given window is in the foreground, before sending input (given, as I mentioned, Windows sends normal keyboard input to whichever window has focus).

If you're using applications that have global hotkeys, I.E. their application window doesn't need to be in the foreground for the application to receive input, the targeting options don't need to be configured to target that specific application.
E.G. you can just have input sent to the active window.

Starblue7

  • Full Member
  • ***
  • Posts: 131
Re: Sending Command to Specific App Without Changing Focus to That App
« Reply #7 on: June 10, 2023, 06:29:45 PM »
Right.  Active Window of course will work, but only of your applications in question are listening for keypresses without needed focus.  TrackIR and Joystick Gremlin will listen for key presses and take action without needing to be a target application to take focus.  Thus you can set your commands for say something like:

VA Command:
Say:  "Center TrackIR"
Target: Active Window
Keypress: F11

TrackIR will identify the keystroke even if your active window is the game window.  You will not lose focus to your game window, and TrackIR will process your command because it could catch the F11 keypress.

Of course, this also means that any binds in your game (or Active Window) cannot be using F11.
Also, if you tab out of your game to let's say Chrome, and you somehow kick off F11, you'll force Chrome into Full Screen mode unintentionally.  So you'll need to choose the binds strategically to avoid potential conflicts.

Thus, I think Pfeil's idea of F13 - F24 is a great option to use for this, as these buttons typically are never used/identified.
I'm thinking of changing over all of my TrackIR, Joystick Gremlin and Push To Talk keys to the above F13-F24.

LinuxDevice

  • Newbie
  • *
  • Posts: 42
Re: Sending Command to Specific App Without Changing Focus to That App
« Reply #8 on: June 10, 2023, 08:37:55 PM »
I really am happy to hear about the F13 through F24 keys. It adds something new that can help a lot. However, most applications I am working with can only see that key if I type it in, and so my games don't seem to have an option to use those keys without a keyboard I don't have (does anyone have a keyboard with actual F13 through F24 keys?). I do plan to try and program VoiceAttack to put out those keys, perhaps in a new profile, and to see what apps can use those bindings.

On the other hand, there are a limited number of bindings based on actual keyboard keys which I have. There might be cases where I can bind VoiceAttack to something I'll never touch with an actual keyboard, but in most cases I still want the ability to access functions without VoiceAttack, so I'd like to use actual keys.

Now if I can send one key specifically to one application, then many applications can share that binding, and it is simply a case of telling VoiceAttack where to send it; then all apps never collide even when they use the same binding. I can't do this though if it pulls those background apps to foreground (and kills me in game).

I am sad there is no way to direct commands to specific applications without pulling them to focus. It would be quite useful with the limited number of keys. Regardless, I still find VoiceAttack to be one of the most useful apps out there.

Starblue7

  • Full Member
  • ***
  • Posts: 131
Re: Sending Command to Specific App Without Changing Focus to That App
« Reply #9 on: June 10, 2023, 09:14:52 PM »
I really am happy to hear about the F13 through F24 keys. It adds something new that can help a lot. However, most applications I am working with can only see that key if I type it in, and so my games don't seem to have an option to use those keys without a keyboard I don't have (does anyone have a keyboard with actual F13 through F24 keys?). I do plan to try and program VoiceAttack to put out those keys, perhaps in a new profile, and to see what apps can use those bindings.

In Voice Attack, you can make a Key Press for any of those F13 - F24 keys.
You'll need to use a Voice Attack Command with one of those Key Press events in the command if you don't have a keyboard with physical F13-F24 keys.

Now if I can send one key specifically to one application, then many applications can share that binding, and it is simply a case of telling VoiceAttack where to send it; then all apps never collide even when they use the same binding. I can't do this though if it pulls those background apps to foreground (and kills me in game).

I am sad there is no way to direct commands to specific applications without pulling them to focus. It would be quite useful with the limited number of keys. Regardless, I still find VoiceAttack to be one of the most useful apps out there.

There MIGHT be a way to send a key press, via Voice Attack Inline Function to a specific application without that application needing/taking focus beyond just using the Active Window target in Voice Attack.
It also might be impossible.

Pfeil could answer that better.

A simple google search started me on the path:
https://stackoverflow.com/questions/41104257/c-sharp-sending-keys-to-another-window-without-focus
https://stackoverflow.com/questions/42498440/sendkeys-to-a-specific-program-without-it-being-in-focus

If you could get a confirmed Inline Function working, you could have Voice Attack fire off the command with the Inline Function and pass along the keypress you want to send via that command via the application you specify.

So, for example, in Voice Attack in a command you could.
Set Variable Name of the Application
Set Variable of the Key Press for that application

Then,
Call up the command with the inline function to send the key to the specified application via the Execute Command from origin command.
That will then send that particular keypress to that particular application.

THIS IS JUST OFF THE TOP OF MY HEAD.  I've never done it.

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4781
  • RTFM
Re: Sending Command to Specific App Without Changing Focus to That App
« Reply #10 on: June 10, 2023, 09:21:44 PM »
Yes, that is technically possible, however there are certain limitations, including applications (especially games) ignoring that type of input, and not being able to send modifiers (while there are facilities to do so, most applications seem to poll the actual state, circumventing/ignoring any modifiers that are sent using those API methods)

As mentioned, normal keyboard input is sent to the active window. The API methods linked would not be considered normal keyboard input, which as implied means it's not nearly as universally applicable as normal keyboard input.


This would be something only very advanced users that are experienced with C#, Windows (API), and complex troubleshooting, should attempt to use. This would not be something that falls within the scope of VoiceAttack itself.