Ciantic / VirtualDesktopAccessor

DLL for accessing Windows 11/10 Virtual Desktop features from e.g. AutoHotkey
MIT License
782 stars 93 forks source link

switching to an uneditable window #69

Closed MichaRotstein closed 1 year ago

MichaRotstein commented 1 year ago

Here is the scenario:

This issue makes virtual desktops very annoying in heavy use, seems to be a windows bug, is there a way around it using this dll and AHK ?

Ciantic commented 1 year ago

You can save the active window by desktop, and when switching desktop and activate the window. It should be doable with AHK.

MichaRotstein commented 1 year ago

Thanks @Ciantic ! Sorry for late reply

My issue is the dll only provides RegisterPostMessageHookProc at which point I can no longer ask AHK for the currently activated window to save it !

Is there a way to get a hook before the VD changes ? Or any other idea ?

MichaRotstein commented 1 year ago

I did manage to solve this:

VDA_PATH := A_ScriptDir . "\VirtualDesktopAccessor.dll"
hVirtualDesktopAccessor := DllCall("LoadLibrary", "Str", VDA_PATH, "Ptr")
GetCurrentDesktopNumberProc := DllCall("GetProcAddress", "Ptr", hVirtualDesktopAccessor, "AStr", "GetCurrentDesktopNumber", "Ptr")
GoToDesktopNumberProc := DllCall("GetProcAddress", "Ptr", hVirtualDesktopAccessor, "AStr", "GoToDesktopNumber", "Ptr")
hWnd := Map()
capslock:: {
  current := DllCall(GetCurrentDesktopNumberProc, "Int")
  hWnd[current] := WinActive('A')
  next:= current = 0 ? 1 : 0
  DllCall(GoToDesktopNumberProc, "Int", next, "Int")
  Try WinActivate hWnd[next]
}