Title

Message

Confirm

Want to earn a free DisplayFusion Pro license? We're looking for DisplayFusion translators!
<< DiscussionsReply

hotkeys to focus windows

Frank99's profile on WallpaperFusion.com
I have two monitors, one of which is split into three virtual monitors. Call them 1, 2.1, 2.2, and 2.3. Almost always, I have one window maximized in each of these four locations. I would like to set up hotkeys that will bring focus to the currently maximized, top z-position window of my choice immediately - something like Win+1, Win+2, etc. I know I could bring focus to the window of my choice relatively quickly with something like Alt+Tab, but I often have many other windows open in the background so I want to set it up for focusing on any of the visible windows in one step. Is there a way to use DisplayFusion to accomplish this? Thanks.
Jul 29, 2019  • #1
Keith Lammers (BFS)'s profile on WallpaperFusion.com
You can do this with scripted functions. I've attached a sample one. If you import it 4 times and modify the names and the window title in the script itself, you can use those to focus specific windows.

Hope that helps!
• Attachment: Focus Window 1.dfscript [620 bytes]
Jul 30, 2019  • #2
Frank99's profile on WallpaperFusion.com
Thank you. It seems that this script will let be bring focus to certain windows by connecting a shortcut to a window title. But I want to do this based on the window location, not the title (in case, e.g., I have four .pdfs open, but only one in the foreground). Is that possible?

Another way to ask is, can I bring focus to whatever window happens to be in the foreground on a specific (virtual) monitor?
Jul 30, 2019  • #3
Keith Lammers (BFS)'s profile on WallpaperFusion.com
Ah I see. I've added a new script to the repository. Could you try downloading this one? You'll need to set the monitor ID on line 17.

"Focus Topmost Window on Specific Monitor"
Jul 30, 2019 (modified Jul 30, 2019)  • #4
Frank99's profile on WallpaperFusion.com
Hi, I'm not able to get this to work. My monitors are 1 and 2. I only changed line 17 as in the comment. So the script is:

// Set the monitor ID here
uint monitorID = 1;

// Find the topmost window on the next monitor
IntPtr window = GetTopmostWindowOnMonitor(monitorID);

// Focus the next window on the next monitor
BFS.Window.Focus(window);

Do I also need to change the 2nd monitorID?

Also, I'm not sure what the "next monitor" thing is about. I have 2 monitors, one of which is split into 3. So I have monitor 1, 2.1, 2.2, 2.3. I want to be able to press Control+Win+1 to bring focus to the topmost window on monitor 1, Control+Win+2 to bring focus to the topmost window on monitor 2.1, etc. I don't want to toggle through the monitors.

Thanks for the help!
24 days ago  • #5
Jon Tackabury (BFS)'s profile on WallpaperFusion.com
That script should work, that comment is just incorrect. Just specify the monitor number you want to focus the window on and it should work fine.
21 days ago  • #6
Frank99's profile on WallpaperFusion.com
If the comment is wrong, what should it say?

When I changed the 2nd instance of "monitorID" to "1", it did work. But when I changed both "monitorID"s to "2.1", it didn't. How can I specify the 3 virtual monitors on my 2nd physical monitor so I can bring focus to their topmost window?

Also, do I need a separate script for each of the monitor shortcuts? Or can I do something to put all of them in one script?
20 days ago (modified 20 days ago)  • #7
Jon Tackabury (BFS)'s profile on WallpaperFusion.com
Instead of this:
// Find the topmost window on the next monitor

It should say this:
// Find the topmost window on the given monitor ID

For split monitors you need to use the syntax 201 or 202 instead of 2.1 or 2.2. Thanks!
20 days ago  • #8
Frank99's profile on WallpaperFusion.com
Works great, thanks!
19 days ago  • #9
Frank99's profile on WallpaperFusion.com
Hi,I now realize that this is actually only working sometimes. Can you help me troubleshoot it?

When it doesn't work, I hit the trigger and the currently focused window loses focus but the window I want to focus on doesn't get focus. No visible window gets focus. So the problem might be that I have hidden windows open that are not listed in the script exclusion list. Do you have any idea how I can find a list of currently open windows to test excluding some other ones? Or can you provide any other suggestions on how to troubleshoot it?

I have AutoHotKey "WindowSpy" to find window classes, but not sure how to get a list of all windows.
5 days ago  • #10
Keith Lammers (BFS)'s profile on WallpaperFusion.com
Could you export the Scripted Function as-is on your machine? I'll add a line into it that will show the window title, class, and process name of the window that it's focusing. That way the next time it doesn't work, you can see which one it is and we can add it to the list of exclusions.

Thanks!
3 days ago  • #11
Frank99's profile on WallpaperFusion.com
Hi, unfortunately I have to export them as four functions because I have four monitors. If there is a way to combine them into one script, all the better, but I don't think there is because I need a different key combination for each monitor.
• Attachment [protected]: Focus Topmost Window on Monitor 1.dfscript [4,120 bytes]
• Attachment [protected]: Focus Topmost Window on Monitor 2.1.dfscript [4,134 bytes]
• Attachment [protected]: Focus Topmost Window on Monitor 2.2.dfscript [4,134 bytes]
• Attachment [protected]: Focus Topmost Window on Monitor 2.3.dfscript [4,134 bytes]
2 days ago  • #12
Keith Lammers (BFS)'s profile on WallpaperFusion.com
Ok, I've attached a ZIP file with updated functions that include logging. You'll need to enable L1 logging on the DisplayFusion Settings > Troubleshooting tab.

When you run one of those functions, and it doesn't seem to focus anything, you can open the %localappdata%\DisplayFusion\DisplayFusion.log file, and search for "Focusing topmost", find the most recent line that matches that, and it will show the Window Text, Process Path, and Class.
• Attachment: Functions with Logging.zip [6,336 bytes]
1 day ago  • #13
Frank99's profile on WallpaperFusion.com
I did not get any hits for "Focusing topmost". I did get the following lines, but I'm not sure how to interpret them.

> 2019/09/19
> 09:08:10.7124##_##INFO:L1##_##displayfusion.exe:1232##_##BFWindow:FocusWindow##_##-##_##Focus
> Window:SwitchToThisWindow [Scripting:FocusWindow]: Window: 0x00011162 • Class: "MSO_BORDEREFFECT_WINDOW_CLASS" • Rect: {X=1146,Y=-8,Width=8,Height=1416} • Style: 0x96000000 • StyleEx: 0x00080080 • Min: False • Max: False • PID: 3376 • Path: "C:\Program Files (x86)\Microsoft Office\Office16\EXCEL.EXE"##_##-

> 2019/09/19 09:08:10.7124##_##INFO:L1##_##displayfusion.exe:1232##_##BFScriptCode:RunWORKER##_##-##_##Done: Focus Topmost Window on Monitor 2.2 [TIMER:2ms]##_##-
2019/09/19 09:08:10.7124##_##INFO:L1##_##displayfusion.exe:1232##_##BFScriptCodeRun:Focus Topmost Window on Monitor 2.2:RunCodeTHREAD##_##-##_##Done: Focus Topmost Window on Monitor 2.2 [2ms, Return: 'null']##_##-
> 2019/09/19 09:11:06.6141##_##INFO:L1##_##displayfusion.exe:1232##_##BFScriptCodeRun:Focus Topmost Window on Monitor 1:RunCodeTHREAD##_##-##_##Done: Focus Topmost Window on Monitor 1 [2ms, Return: 'null']##_##-

These are selections, the log file is attached.
• Attachment [protected]: DisplayFusion.log [287,817 bytes]
17 hours ago  • #14
Keith Lammers (BFS)'s profile on WallpaperFusion.com
Well, that's strange! Those logging entries were working for me when I tested here. I noticed the log lines you pasted below don't have "(with logging)" in the function name. Did you rename them when you imported them, or are you maybe running the old function still, instead of the new "(with logging)" ones?
4 hours ago  • #15
Was this helpful?  Login to Vote  Login to Vote
<< DiscussionsReply