Author Topic: Performing commands on background apps  (Read 1232 times)

Murble

  • Newbie
  • *
  • Posts: 4
Performing commands on background apps
« on: August 12, 2020, 11:51:42 AM »
My goal is to make an AFK bot for a game to make sure I don't get kicked from a server. As it is, if I go AFK for 5 minutes, I get kicked. However, if I have it press the A and D key to move back and forth every few seconds, it's fine. This works well if I am just going AFK to go to the bathroom, or get something to eat, but if I want to go AFK to watch a video on the same computer, problems occur.

So, what I want to do is have the game window get minimized, allowing me to go on YouTube, while still having the A and D keys pressed on the game to ensure I don't get kicked.

I know about the 'Send command to this target' option, and have it set up to send commands to the game window. This works, however if I minimize the game window to start viewing a video, it beeps every time it tries to send a command to the game and doesn't work. I assumed this is because the window is minimized, and when I un-minimized the game window it started working again.
So, I learned that commands can only be sent to non-minimized windows. To go around this limitation, I decided to instead have it move the game window offscreen to where I can't see it, to -5000 x and -5000 y. This allowed the A and D commands to be sent, while I can view YouTube.
The issue with this though is that whenever it sends a command to the game window, it unfocuses the window I am currently looking at. So if I was trying to search for something online, while I am typing into the search bar, it sends a command to the game window, unfocusing google, making me have to click on the search bar again so I can continue typing.
Another problem that happens is while YouTube is in fullscreen, if it sends a command, since it unfocuses YouTube, the taskbar appears on the bottom of the screen, which is really annoying.

So, what is an effective way of sending commands to a game running in the background, while allowing you to continue using other apps?

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4759
  • RTFM
Re: Performing commands on background apps
« Reply #1 on: August 12, 2020, 11:56:16 AM »
As the Windows input system is designed for a human operator, the window that receives normal keyboard input is required to have focus; This is not a VoiceAttack-specific limitation.

Murble

  • Newbie
  • *
  • Posts: 4
Re: Performing commands on background apps
« Reply #2 on: August 12, 2020, 12:45:12 PM »
As the Windows input system is designed for a human operator, the window that receives normal keyboard input is required to have focus; This is not a VoiceAttack-specific limitation.

I understand the limitation is with windows. Sorry, if it seemed I was looking for a native solution to this. What I'm looking for is more of a decent workaround to this issue.

Something along the lines of taking the window you currently have active, saving it to a variable, and after performing the commands, setting it back to the focused window.

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4759
  • RTFM
Re: Performing commands on background apps
« Reply #3 on: August 12, 2020, 01:08:42 PM »
You can store the window title of the active window, send the input to the target window, then switch back to the previously active window, using something like
Code: [Select]
Set text [lastWindowTitle] to '{ACTIVEWINDOWTITLE}'
Press D key and hold for 0,01 seconds and release
Display window 'lastWindowTitle' as [Show]

Set the "Send command to this target:" option to the target application, so VoiceAttack will automatically switch focus to it before sending the keypress.

Depending on how the target application behaves, you may also need a delay between the keypress and switching back.


Note that this is indeed a workaround; If you happen to be actively typing when the switch happens, your input will still momentarily go to the target window.