I'm looking for a autohotkey function, system shortcut or dll call to cycle between all windows on the current virtual desktop.

Windows 10 has this option (Pressing Alt+Tab shows windows that are open to only the desktop I'm using), but that is a global setting that will affect normal alt+tab use. I want to keep that as multi-desktop switch.


Try this:

F1:: WinMenuOnCurrentVirtualDesktop()

    list := ""
    Menu, windows, Add
    Menu, windows, deleteAll
    WinGet, id, list
    Loop, %id%
        this_ID := id%A_Index%
        WinGetTitle, title, ahk_id %this_ID%
        If (title = "")
        If !IsWindow(WinExist("ahk_id" . this_ID))
        If !IsWindowOnCurrentVirtualDesktop(this_ID)
        Menu, windows, Add, %title%, ActivateTitle      
        WinGet, Path, ProcessPath, ahk_id %this_ID%
            Menu, windows, Icon, %title%, %Path%,, 0
            Menu, windows, Icon, %title%, %A_WinDir%\System32\SHELL32.dll, 3, 0 
    CoordMode, Mouse, Screen
    MouseMove, (0.4*A_ScreenWidth), (0.35*A_ScreenHeight)
    CoordMode, Menu, Screen
    Xm := (0.25*A_ScreenWidth)
    Ym := (0.25*A_ScreenHeight)
    Menu, windows, Show, %Xm%, %Ym%

    SetTitleMatchMode 3
    WinActivate, %A_ThisMenuItem%

; Check whether the target window is activation target
    WinGet, dwStyle, Style, ahk_id %hWnd%
    if ((dwStyle&0x08000000) || !(dwStyle&0x10000000)) {
        return false
    WinGet, dwExStyle, ExStyle, ahk_id %hWnd%
    if (dwExStyle & 0x00000080) {
        return false
    WinGetClass, szClass, ahk_id %hWnd%
    if (szClass = "TApplication") {
        return false
    return true

; https://autohotkey.com/boards/viewtopic.php?p=64295#p64295

;Indicates whether the provided window is on the currently active virtual desktop.
IsWindowOnCurrentVirtualDesktop(hWnd) {
    onCurrentDesktop := ""
    CLSID := "{aa509086-5ca9-4c25-8f95-589d3c07b48a}" 
    IID := "{a5cd92ff-29be-454c-8d04-d82879fb3f1b}"
    IVirtualDesktopManager := ComObjCreate(CLSID, IID)  
    Error := DllCall(NumGet(NumGet(IVirtualDesktopManager+0), 3*A_PtrSize), "Ptr", IVirtualDesktopManager, "Ptr", hWnd, "IntP", onCurrentDesktop)
    if !(Error=0)
        return false, ErrorLevel := true
    return onCurrentDesktop, ErrorLevel := false
  • This indeed finds all windows in the current virtual destop (with two unwanted ones - Microsoft Text Input Application and Microsoft Store - probably can filter them out). Thanks, accepting answer. – Krzysztof Bociurko Jul 10 at 14:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.