jpginc / windows10DesktopManager

An autohotkey desktop manager
Apache License 2.0
165 stars 22 forks source link

Detect Virtual Desktop location of a given WinTitle #25

Closed pidgeon777 closed 5 years ago

pidgeon777 commented 5 years ago

Hello, first of all, thanks for your script. I would like to ask if it could be possible with your library to detect the index of the Virtual Desktop hosting a certain window identified through WinTitle (for example, by providing its ahk_id, or ahk_exe, etc.).

Thank you

jpginc commented 5 years ago

There isn't an function setup to do it but you can utilise the VirtualDeskopManagerClass and DesktopMapperClass to do it. Here is an example

hwnd := WinExist("ahk_exe notepad.exe")
vDManager := new VirtualDesktopManagerClass()
virtualDesktopGuid := vDManager.getDesktopGuid(hwnd)
dManager := new DesktopMapperClass("ignore this")
dManager.mapVirtualDesktops()
virtualDesktopId := dManager._idFromGuid(virtualDesktopGuid)
virtualDesktopNumber := dManager._indexOfId(virtualDesktopId)
msgbox % "hwnd: " hwnd "`ndesktop guid: " virtualDesktopGuid "`ndesktop id: " virtualDesktopId "`ndesktop number: " virtualDesktopNumber