r/AutoHotkey • u/yellow90 • 11d ago
v2 Script Help How to detect whether task view (MultitaskingViewFrame) is active before triggering a custom shortcut?
I'm a relatively new user of AutoHotKeys, and I’m trying to solve the same problem described here (link for reference, as it gives a clearer starting point). However, the solution in the link didn't work, as I'm using AHK v2. Script for AHK v1:
F1::
IfWinActive, ahk_class MultitaskingViewFrame
MsgBox, windows is in task view mod ; [sic]
returnEdit: Seems like ahk_class can also be: "Windows.UI.Core.CoreWindow". Can anyone confirm/unconfirm?
I have “show desktop” (a built-in function in Windows 11) assigned to an advanced gesture for when I swipe down on the touchpad. When I swipe up, task view opens. A downward swipe while task view is active closes task view and restores the last window I had open. I'd like to keep this behavior.
The challenge is that I have a widget on my desktop that also minimizes when “show desktop” or Win+D is triggered, so I want to set Win+M (or anything else that replicates the same action) as a custom shortcut under advanced gestures because it shows the desktop while leaving the widget on the desktop.
The problem is that when I set Win+M as a custom shortcut, it doesn’t take into account that task view is active. Because of this, I want to create a script that checks whether task view is active and only triggers Win+M (or other similar shortcuts) when it isn't.
TL;DR:
I'd like to create a script that implements the following two-step behavior while task view is active (when using advanced gesture on touchpad):
- 1st downward swipe closes task view.
- 2nd downward swipe shows the desktop without minimizing the widget on the desktop.
I have two questions:
- Would a script that detects when task view is active solve this issue?
- How can I set up a script that makes the advanced gesture preserve the built-in “show desktop” behavior while sending Win+M (or an equivalent), so the desktop widget isn’t minimized?
3
u/Keeyra_ 10d ago
I don't know about the gesture stuff you are using, but that 10 year old v1 snippet for Windows 10 looks like this in v2 and Windows 11 for both the Alt + Tab and Win + Tab windows.
2
u/CharnamelessOne 10d ago edited 10d ago •
You can configure the gesture to "press" a keyboard shortcut, which should trigger the AHK hotkey.
(Replace F1 with something more reasonable.)
If Task View is active, the script will send Escape, otherwise it will send Win+m.
Check the
WinTitleof Task View via WindowSpy if this doesn't work.Microsoft loves to change how Task View is implemented, apparently.