Author Topic: Return focus to a window at the end of a command  (Read 1354 times)

Braonain

  • Newbie
  • *
  • Posts: 6
Return focus to a window at the end of a command
« on: December 14, 2020, 06:04:48 PM »
So I am attempting to break out of my game window to get data from an excel workbook that is already open and return focus back to the game.

Display window 'excelFile.xlsx - Excel' as [Normal]
Press Down key and hold for 0.1 second and release
Press Left Ctrl+C keys and holf for 0.1 second and release
Display window 'Elite - Dangerous (CLIENT)' as [Normal]

So what I get is that the command executes and collects the data I am after form the excel workbook but does not return focus to the Elite Dangerous window.  I have to reach down, in the blind because I am in VR, for my mouse and click the client window to be able to interact with the game.

The VoiceAttack window displays a result of:  Unable to acquire window or process for window function

I have tried to shorten the name and add wild cards.  I have also attempted to use the windows process nameEliteDangerous64.exe and neither of those help.

Any advice please?


Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4759
  • RTFM
Re: Return focus to a window at the end of a command
« Reply #1 on: December 14, 2020, 06:17:16 PM »
Have you tried running VoiceAttack as administrator?

Are you getting the target name from the "Window Title" dropdown or the "Active Window Details" section? If the class name appears to be unique, have you tried that?

Braonain

  • Newbie
  • *
  • Posts: 6
Re: Return focus to a window at the end of a command
« Reply #2 on: December 14, 2020, 06:26:20 PM »
No I will test and respond

Braonain

  • Newbie
  • *
  • Posts: 6
Re: Return focus to a window at the end of a command
« Reply #3 on: December 14, 2020, 06:29:19 PM »
No.  I set Voice Attack to run as admin and then manually launched it as admin then tested.  I got the same results.

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4759
  • RTFM
Re: Return focus to a window at the end of a command
« Reply #4 on: December 14, 2020, 06:33:44 PM »
...and the rest?

Braonain

  • Newbie
  • *
  • Posts: 6
Re: Return focus to a window at the end of a command
« Reply #5 on: December 14, 2020, 06:36:38 PM »
I was getting the window name from the drop down.

So it is giving the MainWindowTitle

Braonain

  • Newbie
  • *
  • Posts: 6
Re: Return focus to a window at the end of a command
« Reply #6 on: December 14, 2020, 06:46:39 PM »
Will Voice Attack use the process name?

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4759
  • RTFM
Re: Return focus to a window at the end of a command
« Reply #7 on: December 14, 2020, 06:47:53 PM »
Yes, the process name is checked if no window title matches the search string.

The class name doesn't work either? Note that clicking the class name adds it to the "Window Title" field with a "+" prefix, without which the action will not search class names.


If the targeting parameters are correct, something must be stopping VoiceAttack from successfully getting the handle for the game window.
Given how popular Elite:Dangerous is among VoiceAttack users (including in VR), and that this has not been reported as an issue before, it may be the configuration of your machine, or specifically the game (given that switching to Excel presumably does work).


Just in case, if you're running any plugins or additional software (E.G. EDDI), disable plugin support, and run the game by itself (and VoiceAttack), then check whether the window handle is found.

Braonain

  • Newbie
  • *
  • Posts: 6
Re: Return focus to a window at the end of a command
« Reply #8 on: December 14, 2020, 06:55:25 PM »
Haha it will!  You are the man.  So that is where when I get-process on the active window it returns the same name in the MainWindowTitle as the drop down list fetches.  I tried the processName of  EliteDangerous64 and got a result where I could see the movement on the excel file where the command was collecting the data but I still had controls within the game. 


That is soo weird.


So this is how I was collecting information on my focus window in powershell in case any one runs across this thread later.

$code = @'
    [DllImport("user32.dll")]
     public static extern IntPtr GetForegroundWindow();
'@
Add-Type $code -Name Utils -Namespace Win32
while(1){
    $hwnd = [Win32.Utils]::GetForegroundWindow()
    Get-Process |
        Where-Object { $_.mainWindowHandle -eq $hwnd } |
        Select-Object processName, MainWindowTItle, MainWindowHandle  | Format-Table -Wrap -AutoSize
    sleep -Milliseconds 1000
}

ProcessName         MainWindowTitle            MainWindowHandle
-----------              ---------------                 ----------------
EliteDangerous64   Elite - Dangerous (CLIENT)           593490

That is what the return looked like
And This was my command to return focus back to the game.

Display window 'EliteDangerous64' as [Normal]

Thank you so much for your help btw Pfeil

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4759
  • RTFM
Re: Return focus to a window at the end of a command
« Reply #9 on: December 14, 2020, 07:02:29 PM »
You mentioned trying "EliteDangerous64.exe", which should have worked; VoiceAttack will remove the ".exe" suffix internally and search for the process name, with the same end result as using the process name directly.


Not sure why you were using a PowerShell script instead of the "Active Window Details" section of the "Perform a Window Function" dialog, which shows information relevant to VoiceAttack regarding the active window (including the process name), and allows you to click said information to automatically insert it into the "Window Title" field