commit f082e4ec6974b62c86cc7ddd8b294bcc28392cae Author: Joe Tretter Date: Sun May 3 12:47:56 2026 -0500 Initial checkin diff --git a/DesktopHotkeys.ahk b/DesktopHotkeys.ahk new file mode 100644 index 0000000..1119fa4 --- /dev/null +++ b/DesktopHotkeys.ahk @@ -0,0 +1,69 @@ +;#NoTrayIcon + +;Assume we start up on desktop 1 and the user doesn't perform any manual switching. +currentdesktop := 1 + +;You can change the hotkeys for switching desktops below. +;Hotkeys WIN+[1-0] for switching desktops. + +#1::GotoDesktop(1) +#2::GotoDesktop(2) +#3::GotoDesktop(3) +#4::GotoDesktop(4) +#5::GotoDesktop(5) +#6::GotoDesktop(6) +#7::GotoDesktop(7) +#8::GotoDesktop(8) +#9::GotoDesktop(9) +#0::GotoDesktop(10) + +GotoDesktop(desktop) +{ + global currentdesktop + desktopdiff := desktop - currentdesktop + + if (desktop > GetDesktopCount()) + { + ; The requested desktop is bigger than the number of desktops - create new desktops + numDesktopsToCreate := desktop - GetDesktopCount() + Loop %numDesktopsToCreate% + { + NewDesktop() + } + } + if (desktopdiff < 0) + { + desktopdiff *= -1 + Loop %desktopdiff% + { + Send ^#{Left} + } + } + else if (desktopdiff > 0) + { + Loop %desktopdiff% + { + Send ^#{Right} + } + } + currentdesktop := desktop +} + +NewDesktop() +{ + if (GetDesktopCount() > 9) + { + return + } + Send ^#d +} + +GetDesktopCount() +{ + ; In the registry, at Computer\HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VirtualDesktops + ; The Key VirtualDesktopIDs contains the Internal IDs of all desktops + RegRead, virtDesktopIDs, HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VirtualDesktops, VirtualDesktopIDs + + ; Each VirtualDesktopID is 32 characters long, dividing by 32 gives the number + Return StrLen(virtDesktopIDs)/32 +}