pmb6tz / windows-desktop-switcher

An AutoHotKey script for Windows that lets a user change virtual desktops by pressing CapsLock + <num>.
MIT License
1.21k stars 229 forks source link

No session required on Windows 11 #90

Open ethouris opened 1 year ago

ethouris commented 1 year ago

I found this script here and it was kinda outdated on Windows 11. The location for the currently selected desktop is to be read by

        RegRead, CurrentDesktopId, HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VirtualDesktops, CurrentVirtualDesktop

I can see the version here is fixed, but this is kinda incorrect - the condition to check for SessionId only makes sense if you want to extract the key dependent on the SessionId - while the latest verison here reads the key with the path as above under this condition. Before looking here I fixed it myself this way (just to show you an example):

    IdLength := 32
    SessionId := getSessionId()
    if (SessionId) {
        RegRead, CurrentDesktopId, HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\SessionInfo\%SessionId%\VirtualDesktops, CurrentVirtualDesktop
        if (CurrentDesktopId) {
            IdLength := StrLen(CurrentDesktopId)
        }
    }
    if !CurrentDesktopId {
        RegRead, CurrentDesktopId, HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VirtualDesktops, CurrentVirtualDesktop
        if (CurrentDesktopId) {
            IdLength := StrLen(CurrentDesktopId)
        }
    }

(The problem with your version is that when there weren't SessionId, this script won't work, even though SessionId is not needed)