Versuche dies
#NoEnv #SingleInstance Force SetBatchLines -1 SetWorkingDir %A_ScriptDir% main(), return ; Ctrl + number from 1 to 9 switch_to_desktop: switchToDesktop(StrReplace(A_ThisHotkey, "^",, , 1) - 1) Focus() return ; Ctrl + Win + number from 1 to 9 move_A_to_desktop: WinGet, active_id, ID, A If !IsWindowOnCurrentVirtualDesktop(active_id) return IniRead, active_desktop, active_desktop.ini, active_desktop, desktop WinHide ahk_id %active_id% switchToDesktop(StrReplace(A_ThisHotkey, "^#",, , 1) - 1) WinShow ahk_id %active_id% switchToDesktop(active_desktop - 1) return ; Ctrl + Shift + number from 1 to 9 move_A_and_switch_to_desktop: WinGet, active_id, ID, A If !IsWindowOnCurrentVirtualDesktop(active_id) return WinHide ahk_id %active_id% switchToDesktop(StrReplace(A_ThisHotkey, "^+",, , 1) - 1) WinShow ahk_id %active_id% WinActivate, ahk_id %active_id% Focus() return ; https://autohotkey.com/boards/viewtopic.php?f=6&t=14881&hilit=Virtual+Desktop switchToDesktop(idx) { global ppDesktopManager, IID_IVirtualDesktop DllCall(vtable(ppDesktopManager, 7), "Ptr", ppDesktopManager, "Ptr*", pDesktops) if (pDesktops) { DllCall(vtable(pDesktops, 4), "Ptr", pDesktops, "UInt", idx, "Ptr", &IID_IVirtualDesktop, "Ptr*", VirtualDesktop) if (VirtualDesktop) { DllCall(vtable(ppDesktopManager, 9), "Ptr", ppDesktopManager, "Ptr", VirtualDesktop) ObjRelease(VirtualDesktop) ; I assume these should be freed } ObjRelease(pDesktops) } If (idx = "") Index := 1 else Index := idx +1 IniWrite, %Index%, active_desktop.ini, active_desktop, desktop CoordMode, ToolTip, Screen ToolTip, Desktop %Index%, (A_ScreenWidth -20), 0 } main() { OnExit, cleanup OnMessage(DllCall("RegisterWindowMessage", Str, "TaskbarCreated"), "WM_TASKBARCREATED") static ImmersiveShell := ComObjCreate("", "") global IID_IVirtualDesktop, ppDesktopManager try ppDesktopManager := ComObjQuery(ImmersiveShell, "", "") if (!ppDesktopManager) ppDesktopManager := ComObjQuery(ImmersiveShell, "", "") GUID(IID_IVirtualDesktop, "") ObjRelease(ImmersiveShell) Loop 9 { Hotkey, ^%A_Index%, switch_to_desktop Hotkey, ^#%A_Index%, move_A_to_desktop Hotkey, ^+%A_Index%, move_A_and_switch_to_desktop } return cleanup: if (ppDesktopManager) ObjRelease(ppDesktopManager) ExitApp } WM_TASKBARCREATED() { Reload } vtable(ptr, n) { ; NumGet(ptr+0) returns the address of the object's virtual function ; table (vtable for short). The remainder of the expression retrieves ; the address of the nth function's address from the vtable. return NumGet(NumGet(ptr+0), n*A_PtrSize) } GUID(ByRef GUID, sGUID) { ; Converts a string to a binary GUID VarSetCapacity(GUID, 16, 0) DllCall("ole32\CLSIDFromString", "Str", sGUID, "Ptr", &GUID) } Focus() { ; Give focus to the foremost window on the desktop. WinGet, id, list Loop, %id% { this_ID := id%A_Index% If IsWindowOnCurrentVirtualDesktop(this_ID) { WinActivate, ahk_id %this_ID% break } } } ; 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 := "" IID := "" IVirtualDesktopManager := ComObjCreate(CLSID, IID) Error := DllCall(NumGet(NumGet(IVirtualDesktopManager+0), 3*A_PtrSize), "Ptr", IVirtualDesktopManager, "Ptr", hWnd, "IntP", onCurrentDesktop) ObjRelease(IVirtualDesktopManager) if !(Error=0) return false, ErrorLevel := true return onCurrentDesktop, ErrorLevel := false }