KnowBrainer Speech Recognition
Decrease font size
Increase font size
Topic Title: Bring window to front
Topic Summary: A Script helper which forces a named window to the front
Created On: 04/05/2021 02:08 PM
Status: Post and Reply
Linear : Threading : Single : Branch
 Bring window to front   - Edgar - 04/05/2021 02:08 PM  
 Bring window to front   - Edgar - 04/05/2021 04:36 PM  
 Bring window to front   - Edgar - 04/05/2021 04:38 PM  
 Bring window to front   - Edgar - 04/05/2021 05:45 PM  
 Bring window to front   - kkkwj - 04/06/2021 01:06 AM  
 Bring window to front   - Edgar - 04/06/2021 10:10 AM  
 Bring window to front   - kkkwj - 04/06/2021 02:44 PM  
 Bring window to front   - Edgar - 04/06/2021 02:59 PM  
 Bring window to front   - PG LTU - 04/06/2021 04:07 PM  
 Bring window to front   - kkkwj - 04/06/2021 04:15 PM  
 Bring window to front   - Edgar - 04/06/2021 05:47 PM  
 Bring window to front   - alexander - 04/10/2021 09:34 PM  
 Bring window to front   - R. Wilke - 04/11/2021 01:06 PM  
 Bring window to front   - quintijn - 04/13/2021 11:09 AM  
 Bring window to front   - alexander - 04/13/2021 01:04 PM  
 Bring window to front   - R. Wilke - 04/13/2021 06:10 PM  
 Bring window to front   - alexander - 04/15/2021 04:26 PM  
 Bring window to front   - kkkwj - 04/14/2021 02:11 AM  
 Bring window to front   - R. Wilke - 04/14/2021 11:00 AM  
 Bring window to front   - kkkwj - 04/14/2021 11:00 PM  
 Bring window to front   - quintijn - 04/20/2021 12:07 PM  
 Bring window to front   - kkkwj - 04/20/2021 02:28 PM  
 Bring window to front   - Edgar - 04/20/2021 02:44 PM  
 Bring window to front   - BigTech - 04/20/2021 11:27 PM  
 Bring window to front   - BigTech - 04/22/2021 11:13 PM  
 Bring window to front   - quintijn - 04/28/2021 10:48 AM  
 Bring window to front   - BigTech - 05/03/2021 11:04 PM  
 Bring window to front   - kkkwj - 05/18/2021 03:01 PM  
 Bring window to front   - BigTech - 12/11/2021 05:22 PM  
 Bring window to front   - R. Wilke - 05/18/2021 04:05 PM  
 Bring window to front   - dilligence - 05/19/2021 10:25 AM  
 Bring window to front   - R. Wilke - 05/19/2021 03:19 PM  
 Bring window to front   - dilligence - 05/20/2021 11:49 AM  
 Bring window to front   - alexander - 06/17/2021 11:05 AM  
Keyword
 04/05/2021 04:36 PM
User is offline View Users Profile Print this message

Author Icon
Edgar
Top-Tier Member

Posts: 1260
Joined: 04/03/2009

Tiny improvement - allow multiple window titles… Only the Main method has changed:

 

      static void Main(string[] args) {

         if (args.Length == 0) {

            MessageBox.Show("You must supply a window title", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);

            return;

         }

         string inputParameter = string.Join(" ", args).Trim();

         string[] titles = inputParameter.Split(';');

         List<string> windowTitles = new List<string>();

         foreach (string phrase in titles)

            windowTitles.Add(phrase.Trim());

         foreach (string phrase in windowTitles)//DEBUG efm5 2021 04 5 testing

            MessageBox.Show(phrase, "DEBUG TITLE", MessageBoxButtons.OK, MessageBoxIcon.Error);

 

         Process[] processlist = Process.GetProcesses();

         foreach (Process process in processlist) {

            if (!String.IsNullOrEmpty(process.MainWindowTitle)) {

               foreach (string phrase in windowTitles){

                  if (StringContainsPhrase(phrase, process.MainWindowTitle)) {

                     NativeMethods.ShowWindowAsync(process.MainWindowHandle, NativeMethods.ShowWindowCommands.SW_SHOWDEFAULT);

                     NativeMethods.ShowWindowAsync(process.MainWindowHandle, NativeMethods.ShowWindowCommands.SW_SHOW);

                     NativeMethods.SetForegroundWindow(process.MainWindowHandle);

                  }

               }

            }

         }

      }

WARNING - although it works reliably every time on my system, my beta tester says it only works about half the time on theirs!



-------------------------

-Edgar
DPI 15.3, 64-bit Windows 10 Pro, OpenOffice & Office 365, Norton Security, Shure X2U XLR to USB mic adapter with Audio Technica DB135 vocal mic, Asus X299-Deluxe Prime, Intel Core i9-7940X (14 core, 4.3 GHz overclocked to 4.9 GHz), G.SKILL TridentZ Series 64GB (4 x 16GB) DDR4 3333 (PC4 26600) F4-3333C16Q-64GTZ, NVIDIA GIGABYTE GeForce GTX 1060 GV-N1060G1 GAMING-6GD REV 2.0 6GB graphics card with 3 1920x1080 monitors

 04/05/2021 04:38 PM
User is offline View Users Profile Print this message

Author Icon
Edgar
Top-Tier Member

Posts: 1260
Joined: 04/03/2009

Oh yeah, you use a semicolon to separate the window titles:

ShellExecute "D:\\GetMousePosition\\GetMousePosition\\bin\\Release\\GetMousePosition.exe" & " " & _Arg1, 7

Wait 500

 

ShellExecute "D:\\BringWindowToFront\\BringWindowToFront\\bin\\Release\\BringWindowToFront.exe" & " " & "Mouse Coordinates; Preferences"

I checked the syntax for "ShellExecute" and am wondering if that trailing ", 7" might be causing grief.



-------------------------

-Edgar
DPI 15.3, 64-bit Windows 10 Pro, OpenOffice & Office 365, Norton Security, Shure X2U XLR to USB mic adapter with Audio Technica DB135 vocal mic, Asus X299-Deluxe Prime, Intel Core i9-7940X (14 core, 4.3 GHz overclocked to 4.9 GHz), G.SKILL TridentZ Series 64GB (4 x 16GB) DDR4 3333 (PC4 26600) F4-3333C16Q-64GTZ, NVIDIA GIGABYTE GeForce GTX 1060 GV-N1060G1 GAMING-6GD REV 2.0 6GB graphics card with 3 1920x1080 monitors

 04/05/2021 05:45 PM
User is offline View Users Profile Print this message

Author Icon
Edgar
Top-Tier Member

Posts: 1260
Joined: 04/03/2009

Originally posted by: Edgar WARNING - although it works reliably every time on my system, my beta tester says it only works about half the time on theirs!

It turns out that it looks like my beta tester was using the code after having modified it and trying to use it for something for which it was not intended.

I have tested quite intensively now and, when compiled as provided and used as intended, it seems to be completely reliable.



-------------------------

-Edgar
DPI 15.3, 64-bit Windows 10 Pro, OpenOffice & Office 365, Norton Security, Shure X2U XLR to USB mic adapter with Audio Technica DB135 vocal mic, Asus X299-Deluxe Prime, Intel Core i9-7940X (14 core, 4.3 GHz overclocked to 4.9 GHz), G.SKILL TridentZ Series 64GB (4 x 16GB) DDR4 3333 (PC4 26600) F4-3333C16Q-64GTZ, NVIDIA GIGABYTE GeForce GTX 1060 GV-N1060G1 GAMING-6GD REV 2.0 6GB graphics card with 3 1920x1080 monitors

 04/06/2021 01:06 AM
User is offline View Users Profile Print this message

Author Icon
kkkwj
Top-Tier Member

Posts: 865
Joined: 11/05/2015

Hi Edgar, that was interesting! I've never seen ShowWindowAsync before. Does it bring the window to the front AND make it the active foreground window that gets keyboard input, etc? It seems like a really nice way to bring windows to the foreground even when your app didn't spawn the windows in the first place. Thank you for posting this example!

-------------------------

Win10/11/x64, AMD Ryzen 7 3700X/3950X, 64/128GB RAM, Dragon 15.3, SP 7 Standard, SpeechStart, Office 365, KB 2017, Dragon Capture, Samson Meteor USB Desk Mic, Amazon YUWAKAYI headset, Klim and JUKSTG earbuds with microphones, 3 BenQ 2560x1440 monitors, Microsoft Sculpt Keyboard and fat mouse

 04/06/2021 10:10 AM
User is offline View Users Profile Print this message

Author Icon
Edgar
Top-Tier Member

Posts: 1260
Joined: 04/03/2009

Originally posted by: kkkwj  ShowWindowAsync […] Does it bring the window to the front AND make it the active foreground window that gets keyboard input, etc?

That is my understanding. I think that there is a similar ShowWindow library function (no Asynchronous) but I am not sure what the differences are. From my experiences it looks like SetForegroundWindow can give a window focus but does not always make it display on the desktop; ShowWindowAsync seems to (almost?) always make it show on the desktop and, from my experience it always gets focus too.



-------------------------

-Edgar
DPI 15.3, 64-bit Windows 10 Pro, OpenOffice & Office 365, Norton Security, Shure X2U XLR to USB mic adapter with Audio Technica DB135 vocal mic, Asus X299-Deluxe Prime, Intel Core i9-7940X (14 core, 4.3 GHz overclocked to 4.9 GHz), G.SKILL TridentZ Series 64GB (4 x 16GB) DDR4 3333 (PC4 26600) F4-3333C16Q-64GTZ, NVIDIA GIGABYTE GeForce GTX 1060 GV-N1060G1 GAMING-6GD REV 2.0 6GB graphics card with 3 1920x1080 monitors

 04/06/2021 02:44 PM
User is offline View Users Profile Print this message

Author Icon
kkkwj
Top-Tier Member

Posts: 865
Joined: 11/05/2015

Well, I can vouch for the fact that calling ShowWindow from some random non-foreground piece of code rarely if ever works reliably. Windows has rules against doing that. But it looks like you have figured out a clever way of just sending a message to tell the window to take over the foreground itself. I'll have to try it out!

-------------------------

Win10/11/x64, AMD Ryzen 7 3700X/3950X, 64/128GB RAM, Dragon 15.3, SP 7 Standard, SpeechStart, Office 365, KB 2017, Dragon Capture, Samson Meteor USB Desk Mic, Amazon YUWAKAYI headset, Klim and JUKSTG earbuds with microphones, 3 BenQ 2560x1440 monitors, Microsoft Sculpt Keyboard and fat mouse

 04/06/2021 02:59 PM
User is offline View Users Profile Print this message

Author Icon
Edgar
Top-Tier Member

Posts: 1260
Joined: 04/03/2009

As it turns out, this seems to have been a slight detour down an unnecessary road. The original use case was for forcing a window to the front when it has been started by a DVC or Advanced Script (either Dragon® or KnowBrainer). Sometimes (with newer Windows 10 updates virtually always) if I have a script that uses AppBringUp or ShellExecute, and the resulting application opens a window, that window fails to display on the desktop although it does show up in the taskbar. This application was designed to bring said window out of Never-Never Land and force it to show up, in focus, on the desktop, in front of every other window. It works great for that.

However, the real problem turned out to be that ShellExecute has an optional switch:

ShellExecute method

Run a script or application in the Windows Shell.

Syntax

      .ShellExecute "application", "parameters", "dir", "verb", window

 

      .ShellExecute 'some program.exe', '"some parameters with spaces"', , "runas", 1

Key

   application   The file to execute (required)

   parameters    Arguments for the executable

   dir           Working directory

   verb          The operation to execute (runas/open/edit/print)

   window        View mode application window (normal=1, hide=0, 2=Min, 3=max, 4=restore, 5=current, 7=min/inactive, 10=default)

[\q]

 

Someone on the forum decided that adding that "7" was better than leaving it without anything; I'm wondering if this is incorrect. I tried out both "1" and "10" and had complete success by adding "10". Adding "10" has resolve the issue completely for me. I went back through all of my Dragon® and KnowBrainer personal commands and either changed the "7" to "10" or added "10" to those without anything.



-------------------------

-Edgar
DPI 15.3, 64-bit Windows 10 Pro, OpenOffice & Office 365, Norton Security, Shure X2U XLR to USB mic adapter with Audio Technica DB135 vocal mic, Asus X299-Deluxe Prime, Intel Core i9-7940X (14 core, 4.3 GHz overclocked to 4.9 GHz), G.SKILL TridentZ Series 64GB (4 x 16GB) DDR4 3333 (PC4 26600) F4-3333C16Q-64GTZ, NVIDIA GIGABYTE GeForce GTX 1060 GV-N1060G1 GAMING-6GD REV 2.0 6GB graphics card with 3 1920x1080 monitors

 04/06/2021 04:07 PM
User is offline View Users Profile Print this message

Author Icon
PG LTU
Top-Tier Member

Posts: 2197
Joined: 03/21/2007

I hope I haven't inadvertently created a problem. Whenever I use ShellExecute to send stuff to an AHK program, I use "6" at the end ("minimized window; not active") because I don't need to see anything (and I have suggested such a thing over this forum often). Naturally, in a DVC (or DAS) that works on a window, I would use the proper windowStyle constant for the situation.
Please look here:
https://www.nuance.com/products/help/dragon/dragon-for-pc/scriptref/Content/scrptref/shellexecute.htm



-------------------------




PG





Remember folks, my comments and this forum are for entertainment value only, please, no wagering or other reliance on the contents herein.  I permit no commercial use of my ideas (whether expressions or embodiments) without my written consent.



 04/06/2021 04:15 PM
User is offline View Users Profile Print this message

Author Icon
kkkwj
Top-Tier Member

Posts: 865
Joined: 11/05/2015

Hi Edgar, I'm with PG on the 6,7 thing. I was probably the "someone on the forum" who suggested using 7 was the right thing to do for times when I didn't want to see a DOS console window pop up when I ran a DOS exe file (your StatementConstructor, as I recall). As far as I could tell, there was no difference between 6 and 7. PG uses 6, and ended up with using 7 because it was the last one I tried and easiest to remember. I don't recall seeing the 10 before; I've certainly never tried it.

-------------------------

Win10/11/x64, AMD Ryzen 7 3700X/3950X, 64/128GB RAM, Dragon 15.3, SP 7 Standard, SpeechStart, Office 365, KB 2017, Dragon Capture, Samson Meteor USB Desk Mic, Amazon YUWAKAYI headset, Klim and JUKSTG earbuds with microphones, 3 BenQ 2560x1440 monitors, Microsoft Sculpt Keyboard and fat mouse

 04/06/2021 05:47 PM
User is offline View Users Profile Print this message

Author Icon
Edgar
Top-Tier Member

Posts: 1260
Joined: 04/03/2009

I see that the DragonĀ® documentation in the Windows documentation (which I quoted) do not exactly agree. DragonĀ® says:
windowStyle Controls how the window appears when you activate the application. Must be one of the following:
1, 5, or 9 default window size; active (default)
2 minimized window; active
3 maximized window; active
4 or 8 default window size; not active
6 or 7 minimized window; not active
but that may no longer be true with the new Basic in 15.61.


-------------------------

-Edgar
DPI 15.3, 64-bit Windows 10 Pro, OpenOffice & Office 365, Norton Security, Shure X2U XLR to USB mic adapter with Audio Technica DB135 vocal mic, Asus X299-Deluxe Prime, Intel Core i9-7940X (14 core, 4.3 GHz overclocked to 4.9 GHz), G.SKILL TridentZ Series 64GB (4 x 16GB) DDR4 3333 (PC4 26600) F4-3333C16Q-64GTZ, NVIDIA GIGABYTE GeForce GTX 1060 GV-N1060G1 GAMING-6GD REV 2.0 6GB graphics card with 3 1920x1080 monitors

 04/10/2021 09:34 PM
User is offline View Users Profile Print this message

Author Icon
alexander
Top-Tier Member

Posts: 207
Joined: 07/31/2016

fwiw, here is Mark's vocola extension file for doing window activation
https://github.com/mdbridge/bit-bucket/blob/c55b19563b11766350726f346b29ac61bcdfc266/voice/Vocola_development/unofficial/vocola_ext_window_switching.py#L226

Window.Go is great cause you can use regex. But win32gui.SetForegroundWindow is annoyingly unreliable (blinking app in taskbar but no activation)

Most reliable thing I've found is to "Ctrl+click" the taskbar app. I have scripts to activate apps that way, never fails. After that, the SetForegroundWindow for that app can also work reliably in my experience.
 04/11/2021 01:06 PM
User is offline View Users Profile Print this message

Author Icon
R. Wilke
Top-Tier Member

Posts: 7809
Joined: 03/04/2007

But win32gui.SetForegroundWindow is annoyingly unreliable (blinking app in taskbar but no activation)

 

Foreground activation permission is like love: You can't steal it, it has to be given to you | The Old New Thing (microsoft.com)

 

 



-------------------------



No need to buy if all you want to do is try ...

DragonCapture KB Download (Latest)
DragonCapture Homepage



 04/13/2021 11:09 AM
User is offline View Users Profile Print this message

Author Icon
quintijn
Top-Tier Member

Posts: 218
Joined: 07/28/2014

I prefer AutoHotkey for bringing windows to the foreground. Described on https://qh.antenna.nl/unimacro/features/autohotkey/index.html, and used a lot in Unimacro and Vocola.

The clue is, you have to write a tiny script with the handle of the window you want to bring into the foreground, and run that script with autohotkey.exe.

I use it also the bring for example the Messages window of Natlink macros to the foreground, by the script with contents:

```
SetTitleMatchMode, 1

WinActivate Messages from
```

I bit of setup work, but worth the trouble IMHO,
Quintijn

 04/13/2021 01:04 PM
User is offline View Users Profile Print this message

Author Icon
alexander
Top-Tier Member

Posts: 207
Joined: 07/31/2016

Do you by chance have a link to the deleted comments in that Microsoft post that show you how to override the "AllowForegroundWindow"? per Raymond's comment:

"Update (02/21): Deleted all comments that showed ways of circumventing the rules"

Quintijin, Does autohotkey work completely reliably for you? I always hesitate to add yet another layer of technology to my stack... I used to use autohotkey, but I made the decision a while back to try to stick to purely Vocola and Python extensions if possible. (Although I do have to use the occasional .bat and .vbs, but since those come with Windows preinstalled they don't require any extra set up)
 04/13/2021 06:10 PM
User is offline View Users Profile Print this message

Author Icon
R. Wilke
Top-Tier Member

Posts: 7809
Joined: 03/04/2007

Do you by chance have a link to the deleted comments in that Microsoft post that show you how to override the "AllowForegroundWindow"? per Raymond's comment:

"Update (02/21): Deleted all comments that showed ways of circumventing the rules"


No, and if I had, I wouldn't share them. I have had my fill fighting with SetForegroundWindow and trying to solve it with AllowForegroundWindow, to no avail. But then I read on and found Raymond showing a way that works, without circumventing the rules. As far as AutoHotKey, which I have never used and am not considering, doesn't it also fall back on the Win32 API after all?

-------------------------



No need to buy if all you want to do is try ...

DragonCapture KB Download (Latest)
DragonCapture Homepage

 04/15/2021 04:26 PM
User is offline View Users Profile Print this message

Author Icon
alexander
Top-Tier Member

Posts: 207
Joined: 07/31/2016

Originally posted by: R. Wilke  But then I read on and found Raymond showing a way that works, without circumventing the rules.

 

When I read his post, it seems like he pretty much says there will always be a case when you can't do it, unless I misunderstand what he says or unless he's joking and being snarky:

"In all cases, note that you can’t give away something that’s not yours. If you don’t have permission to take foreground, then calling AllowSetForegroundWindow (or one of its moral equivalents) will have no effect: You just told the window manager, “It’s okay; he’s with me,” and the window manager replied, “Who the hell are you?”"

 

In fact from what he says I'm surprised that it ever works at all. Given that we are running this from some background python process, presumably inside of dragons process space(?), A process that rarely if at all has the focus, how would it ever work?

 

Anyway searching around I found some stack overflow items but they come with warnings among other things.

 

I can of course understand the reason the OS is structured this way, but it really sucks for accessible applications as opposed to just malevolent applications...

 

In any case I will probably try some of those stack overflow suggestions at some stage, but my current hack seems to work well enough.  



 04/14/2021 02:11 AM
User is offline View Users Profile Print this message

Author Icon
kkkwj
Top-Tier Member

Posts: 865
Joined: 11/05/2015

RW, I read Chen's paper long ago, plus many others. If there was something in there that showed the way, I must have missed it. I even tracked down and watched his conference presentation on Windows and foreground and window owners and parents and a chunk of code that was supposed to "pick the right child window" out of a hierarchy of open windows. Despite tons of study, I never got anything out of his window-climbing code. I even interacted with him and he pointed me toward Microsoft's UI Automation technology. Not much help. If you know how (within the rules) to bring an app window to the foreground from a background thread that is not the foreground thread that has love to give away, I'm sure many people would like to know...

-------------------------

Win10/11/x64, AMD Ryzen 7 3700X/3950X, 64/128GB RAM, Dragon 15.3, SP 7 Standard, SpeechStart, Office 365, KB 2017, Dragon Capture, Samson Meteor USB Desk Mic, Amazon YUWAKAYI headset, Klim and JUKSTG earbuds with microphones, 3 BenQ 2560x1440 monitors, Microsoft Sculpt Keyboard and fat mouse

 04/14/2021 11:00 AM
User is offline View Users Profile Print this message

Author Icon
R. Wilke
Top-Tier Member

Posts: 7809
Joined: 03/04/2007

I even interacted with him and he pointed me toward Microsoft's UI Automation technology. Not much help.


Oh dear, Kevin. I would have been surprised if Raymond had given you a straightforward answer along the lines of "just give me the code to copy and paste", he is certainly a lot more funny than that. However, his blog also has a superbe search function, and if you copy and paste "foreground activation love" into it, and press enter, you might find it. Probably at the top of the list.



-------------------------



No need to buy if all you want to do is try ...

DragonCapture KB Download (Latest)
DragonCapture Homepage

 04/14/2021 11:00 PM
User is offline View Users Profile Print this message

Author Icon
kkkwj
Top-Tier Member

Posts: 865
Joined: 11/05/2015

Hi RW, I have had his paper, and his blog, and N comments about that article, and so on, for years. If you mean that the solution is at the top of his love article, I'll have another look at it. His best answer, given directly to me when I asked him directly about my voice application issue, was to consider the UIA (UI automation) interface. Ugh. That wasn't helpful at all. Oh well.

-------------------------

Win10/11/x64, AMD Ryzen 7 3700X/3950X, 64/128GB RAM, Dragon 15.3, SP 7 Standard, SpeechStart, Office 365, KB 2017, Dragon Capture, Samson Meteor USB Desk Mic, Amazon YUWAKAYI headset, Klim and JUKSTG earbuds with microphones, 3 BenQ 2560x1440 monitors, Microsoft Sculpt Keyboard and fat mouse

 04/20/2021 12:07 PM
User is offline View Users Profile Print this message

Author Icon
quintijn
Top-Tier Member

Posts: 218
Joined: 07/28/2014

autohotkey seems to be pretty reliable, but you also have to learn it, as each interface.

Greetings, Quintijn
 04/20/2021 02:28 PM
User is offline View Users Profile Print this message

Author Icon
kkkwj
Top-Tier Member

Posts: 865
Joined: 11/05/2015

Hi Quintijn, have you seen the thread on how experts use Dragon? I think it would be nice if some of your Natlink/Python crew made a video or two on how experts in your community use Dragon. Not many of us here know what a Python/Vocola/Unimacro/Dragonfly/Natlink setup looks like or feels like. I thought I would invite you. Thanks, Kevin

-------------------------

Win10/11/x64, AMD Ryzen 7 3700X/3950X, 64/128GB RAM, Dragon 15.3, SP 7 Standard, SpeechStart, Office 365, KB 2017, Dragon Capture, Samson Meteor USB Desk Mic, Amazon YUWAKAYI headset, Klim and JUKSTG earbuds with microphones, 3 BenQ 2560x1440 monitors, Microsoft Sculpt Keyboard and fat mouse

 04/20/2021 02:44 PM
User is offline View Users Profile Print this message

Author Icon
Edgar
Top-Tier Member

Posts: 1260
Joined: 04/03/2009

Originally posted by: kkkwj I thought I would invite you.

+1



-------------------------

-Edgar
DPI 15.3, 64-bit Windows 10 Pro, OpenOffice & Office 365, Norton Security, Shure X2U XLR to USB mic adapter with Audio Technica DB135 vocal mic, Asus X299-Deluxe Prime, Intel Core i9-7940X (14 core, 4.3 GHz overclocked to 4.9 GHz), G.SKILL TridentZ Series 64GB (4 x 16GB) DDR4 3333 (PC4 26600) F4-3333C16Q-64GTZ, NVIDIA GIGABYTE GeForce GTX 1060 GV-N1060G1 GAMING-6GD REV 2.0 6GB graphics card with 3 1920x1080 monitors

 04/20/2021 11:27 PM
User is offline View Users Profile Print this message


BigTech
Senior Member

Posts: 102
Joined: 11/25/2008

Originally posted by: alexander win32gui.SetForegroundWindow is annoyingly unreliable (blinking app in taskbar but no activation)


You must use the alt key for programmatically switching windows. Here's my code (ignore my variable casing, I'm not a programmer). Also don't see how to insert code in this post...

EnumWindows(EnumWinHandle,NULL);

//FND-NRM-ACT, press alt key

ZeroMemory(SI,sizeof(INPUT));

SI[0].type=INPUT_KEYBOARD;

SI[0].ki.wVk=VK_MENU;

SI[0].ki.dwFlags=0;

SendInput(1,SI,sizeof(INPUT));

if(IsIconic(WndoCurrent))

{//FND-NRM-ACT, restore destination window if minimized

OpenIcon((WndoCurrent));

}//FND-NRM-ACT, restore destination window if minimized

else

{//FND-NRM-ACT, switch to destination window

SetForegroundWindow(WndoCurrent);

}//FND-NRM-ACT, switch to destination window

//FND-NRM-ACT, release alt key

SI[0].ki.dwFlags=KEYEVENTF_KEYUP;

SendInput(1,SI,sizeof(INPUT));

GetTitle=false;

*KeyString='\0';
 04/22/2021 11:13 PM
User is offline View Users Profile Print this message


BigTech
Senior Member

Posts: 102
Joined: 11/25/2008

I posted that to the now defunct Yahoo forum many years ago. Quintijn, Mark, and maybe Rick were all present. Seems nobody picked up on it? Anybody home???
 04/28/2021 10:48 AM
User is offline View Users Profile Print this message

Author Icon
quintijn
Top-Tier Member

Posts: 218
Joined: 07/28/2014

I have not been on the Yahoo forum for many years...

Quintijn
 05/03/2021 11:04 PM
User is offline View Users Profile Print this message


BigTech
Senior Member

Posts: 102
Joined: 11/25/2008

Come to think of it... Holding down Alt while programmatically switching windows probably isn't a trick. In fact, we manually switch windows in Windows by holding the Alt key while tapping Tab. The reason holding Alt is required for programmatic window switching might be related to that normal UI operation.
 05/18/2021 03:01 PM
User is offline View Users Profile Print this message

Author Icon
kkkwj
Top-Tier Member

Posts: 865
Joined: 11/05/2015

@BigTech, yes, holding down the Alt key is a trick, and it is one that works. :-) Thank you for posting it and a code example.

-------------------------

Win10/11/x64, AMD Ryzen 7 3700X/3950X, 64/128GB RAM, Dragon 15.3, SP 7 Standard, SpeechStart, Office 365, KB 2017, Dragon Capture, Samson Meteor USB Desk Mic, Amazon YUWAKAYI headset, Klim and JUKSTG earbuds with microphones, 3 BenQ 2560x1440 monitors, Microsoft Sculpt Keyboard and fat mouse

 12/11/2021 05:22 PM
User is offline View Users Profile Print this message


BigTech
Senior Member

Posts: 102
Joined: 11/25/2008

Originally posted by: kkkwj @BigTech, yes, holding down the Alt key is a trick, and it is one that works. :-) Thank you for posting it and a code example.

Do you have an extension that includes holding down Alt for switching windows, to plug into Vocola, please?

I'm having trouble getting Mark's WindowGo to work for switching windows that are not minimized to the Taskbar. Apparently he does not use the ALTernative method...

I used Alt at one time, but not with Python. That method was disabled by an update to one of the utilities.

Thanks.

 05/18/2021 04:05 PM
User is offline View Users Profile Print this message

Author Icon
R. Wilke
Top-Tier Member

Posts: 7809
Joined: 03/04/2007

Kevin, indeed, pressing a hotkey is the route to getting the foreground love, and this is what I have been trying to point out to you along the messages in this thread. To no avai, unfortunately.


-------------------------



No need to buy if all you want to do is try ...

DragonCapture KB Download (Latest)
DragonCapture Homepage

 05/19/2021 10:25 AM
User is offline View Users Profile Print this message

Author Icon
dilligence
Top-Tier Member

Posts: 1499
Joined: 08/16/2010

Foreground love?

 

SP Application Activation© is not looking for love. Instead it places anything you see (or don't see) in the taskbar to the foreground and activates it. Doesn't matter if it's programs, child windows of programs, specific instances of programs, pictures, Explorer Windows, dialogs, MSG boxes, you name it.

 

Best of all, it will also allow you to use only part of the target name. How about that for ergonomics

 

Demonstration Video:

 

 

 



-------------------------

https://speechproductivity.eu


Turbocharge your Dragon® productivity with 40 Power Addons



 05/19/2021 03:19 PM
User is offline View Users Profile Print this message

Author Icon
R. Wilke
Top-Tier Member

Posts: 7809
Joined: 03/04/2007

Well, Rob, once again you are nowhere near to getting the picture, since the whole thread has been about the Win32 SetForegroundWindow API function not working as expected at all times.



-------------------------



No need to buy if all you want to do is try ...

DragonCapture KB Download (Latest)
DragonCapture Homepage



 05/20/2021 11:49 AM
User is offline View Users Profile Print this message

Author Icon
dilligence
Top-Tier Member

Posts: 1499
Joined: 08/16/2010

@Wilke

 

The above video obviously proves it can be done reliably, despite the limitations discussed in this thread. I guess Tom, SP PRO programmer knows what he's doing .

 

We invite you to watch it (and be amazed!).

 

Better yet, try before you buy! After all, there's a free SP 6 PRO Demo available .



-------------------------

https://speechproductivity.eu


Turbocharge your Dragon® productivity with 40 Power Addons



 06/17/2021 11:05 AM
User is offline View Users Profile Print this message

Author Icon
alexander
Top-Tier Member

Posts: 207
Joined: 07/31/2016

just a follow-up to this thread, I finally got around to trying pressing the alt button and it does seem to improve reliiability.  fwiw, here's some sample code in Vocola which uses the Window.Go_ from the window extension that Mark wrote.  you will notice I doubled up on  the  alt_release call, since I found that occasionally alt would be 'down' when sublimetext popped up.  but so far so good...

 

      # Sue switch to sublimetext Vocola commands

      Keys.SendInput({alt_hold}) # apparently this improves the reliability of activating Windows

      Window.Go_( RegularAnd("Sublime Vocola") "((?!extension).)*$" )

      Keys.SendInput({alt_release}) 

      Wait(800)

      Keys.SendInput({alt_release})

Statistics
32285 users are registered to the KnowBrainer Speech Recognition forum.
There are currently 0 users logged in.
The most users ever online was 12124 on 09/09/2020 at 04:59 AM.
There are currently 393 guests browsing this forum, which makes a total of 393 users using this forum.

FuseTalk Standard Edition v4.0 - © 1999-2022 FuseTalk™ Inc. All rights reserved.