If you don't mind using AutoHotkey for the purpose, the project VirtualDesktopAccessor comes with an example which does exactly that:
hVirtualDesktopAccessor := DllCall("LoadLibrary", Str, "C:\Path\To\VirtualDesktopAccessor.dll", "Ptr")
MoveWindowToDesktopNumberProc := DllCall("GetProcAddress", Ptr, hVirtualDesktopAccessor, AStr, "MoveWindowToDesktopNumber", "Ptr")
GoToDesktopNumberProc := DllCall("GetProcAddress", Ptr, hVirtualDesktopAccessor, AStr, "GoToDesktopNumber", "Ptr")
MoveCurrentWindowToDesktop(number) {
global MoveWindowToDesktopNumberProc, GoToDesktopNumberProc, activeWindowByDesktop
WinGet, activeHwnd, ID, A
DllCall(MoveWindowToDesktopNumberProc, UInt, activeHwnd, UInt, number)
DllCall(GoToDesktopNumberProc, UInt, number)
}
+#1::MoveCurrentWindowToDesktop(1)
+#2::MoveCurrentWindowToDesktop(2)
+#3::MoveCurrentWindowToDesktop(3)
+#4::MoveCurrentWindowToDesktop(4)
+#5::MoveCurrentWindowToDesktop(5)
A collection of nice defaults that makes use of this library is available in https://github.com/yalibian/i3-windows:
Switch to virtual desktops 1-9 using ⊞-# and backfill # of desktops if needed
Move active windows to virtual desktops 1-9 using ⊞-shift-# and backfill desktops if needed
Close windows with ⊞-shift-q