FuPeiJiang / VD.ahk

Windows Virtual Desktop, AutoHotkey, Windows 11 support, Windows Server 2022, switch desktop, move window(wintitle) to current desktop; createDesktop, PinWindow, getCount, getDesktopNumOfWindow -> mute all windows in Virtual Desktop
MIT License
319 stars 45 forks source link

can not change desktop #39

Open mmaukii opened 1 year ago

mmaukii commented 1 year ago

thank you first for your great tool!

I only have one issue and i do not know if i am doing wrong or if it should work that way. I open the example file. I then select a window, which is not shared on all desktops. The script produces a short blink in the screen an i stay on the orignal desktop. I only can change between the desktops if the active Windwo is shared between all desktops. Is this intended to be like that?

I would be happy if I could switch direktly to any desktop regardless which windwo is active.

greets Daniel

mmaukii commented 1 year ago

My system: Edition Windows 10 Pro Version 21H2 Leistung Windows Feature Experience Pack 120.2212.4190.0

FuPeiJiang commented 1 year ago

just to make sure: "shared on all desktops means" is a synonym for "Show this window on all desktops" or VD.PinWindow() ___ what's the active window you tried it with (notepad.exe?) ? what's the hotkey you tried it with (Numpad2?) ? ___

Is this intended to be like that?

no press Numpad2 to jump to desktop 2, regardless of which window is active but if the active window is admin, you need to run ahk as admin, but I don't think admin is the problem since it flashes but doesn't switch

I tried on a clean install of Win10 with the same Experience: Windows Feature Experience Pack 120.2212.4190.0 and Numpad1,Numpad2,Numpad3 worked do you have any apps installed ?

mmaukii commented 1 year ago

thank you for your answer. Maybe I have than something else running which causes this strange behaviour in combination with your script. I have tried it on my working PC. I will go back to work on monday and will try to find out what goes on!

mmaukii commented 1 year ago

to confirm: "shared on all desktops means" is a synonym for "Show this window on all desktops" or VD.PinWindow()

what i do: closed all other ahk scripts downloaded the files from your git start VD examples Press Numpad0, Numpad2, Numpad3, Numpad1-> VD.ahk window gets pinned, i can move to desktop 2, 3 and back to 1 Press Numpad0 and Numpad 3 -> VD.ahk window gets unpinned, I cant move to desktop 3. Screen seems to jump shortly there but at the end im am back on desktop 1

same behaviour with edtior window

Info: on startup of script only one desktop opened (the script produces the other ones) Also tried to changes setting of virtuell desktops in win without any effect.

if i start the CurrentVirtualDesktopChanged RegisterDesktopNotifications.ahk in other examples i get also normal results with pinned windows but stragen one if i do not pinn (example for moving from desktop 1 to 3): pinned: Tooltipp: "1,3" Deskotps get changed to desktop 3 upinnde: "3,1" I am back to desktop 1

FuPeiJiang commented 1 year ago

@mmaukii try the update ? after reading https://github.com/MScholtes/VirtualDesktop/issues/57#issuecomment-1546869770 the desktopBackground is "shared on all desktops", so I'm trying WinActivate desktopBackground before switching

mmaukii commented 1 year ago

Thanks for your efforts. I downloaded the new version. Unfortunatly did not work. I also found the strange behaviour start VD examples on Desktop 1 Press Numpad9, Numpad2-> VD.ahk window gets moved to desktop 3 but after pressing Numpad2 I end up on Desktop 3 (where VD.ahk is) and not on desktop 2

FuPeiJiang commented 1 year ago

I'm out of ideas, try running as admin ?

also try out this branch https://github.com/FuPeiJiang/VD.ahk/tree/debug39 I assume you're using AHK v1

the ToolTips are explained here: https://github.com/FuPeiJiang/VD.ahk/issues/40#issuecomment-1551633122 but that's not what's important, what's important in the branch https://github.com/FuPeiJiang/VD.ahk/tree/debug39 is : Pin and Activate before switching

FuPeiJiang commented 1 year ago

I'm not able to switch VD when

Microsoft Teams Chrome_WidgetWin_1 Teams.exe 0x14C20000 0x00000100

is active

I feel a fix is incoming to this issue because I'm able to reproduce something similar to the issue now

mmaukii commented 1 year ago

i also had at that time MSTeams active. My Browser is firefox, so it could be connected to MSteams.

FuPeiJiang commented 1 year ago

@mmaukii download the newest version again ? and run as admin ? the branch is : class_VD the commit is : {LShift Down} doesn't work, needs keybd_event

mmaukii commented 1 year ago

sorry i did not work out. But i found something strange. If i add a msgbox at the end of goToDesktopNum(desktopNum) {

       Sleep 25
    }
                msgbox %desktopNum%
}

And i run this without the focus on the ahk example window i can switch to the desktops. It seems to me, that the desktopswitching is woking (fast jump to the right desktop) but then something automatically moves the focus back to the starting desktop. That does not apply with this "experiment"

mmaukii commented 1 year ago

No idea what this "if" is doing. I think it get not even called by the code but if I comment it out everything seems to work in the first place: goToDesktopNum(desktopNum) {

... ; "ahk_class TPUtilWindow ahk_exe HxD.exe" instead of "ahk_class WorkerW ahk_exe explorer.exe" ;if (this._activateWindowUnder(VD_animation_gui_hwnd)==-1) { ; this._activateDesktopBackground() ;} ... }

FuPeiJiang commented 1 year ago

@mmaukii so the fix would be to remove

if (this._activateWindowUnder(VD_animation_gui_hwnd)==-1) {
    this._activateDesktopBackground()
}

inside goToDesktopNum ?

but before I do that, can you tell me if the code reaches the line this._activateDesktopBackground() ? place a msgbox 1234567 inside, and if it appears it reaches there

if (this._activateWindowUnder(VD_animation_gui_hwnd)==-1) {
    msgbox 1234567
    this._activateDesktopBackground()
}

___ so the function _activateWindowUnder is bringing you back to the desktop you were at, I need to know which window it is activating , can you place this inside the function _activateWindowUnder(excludeHwnd:=-1) {

                if (!(OutputVar_MinMax==-1)) { ;not Minimized
                    ; WinActivate % "ahk_id " theHwnd
                    WinGetTitle winTitle, % "ahk_id " theHwnd
                    WinGetClass className, % "ahk_id " theHwnd
                    WinGet processName, ProcessName, % "ahk_id " theHwnd
                    WinGet winStyle, Style, % "ahk_id " theHwnd
                    WinGet winExStyle, ExStyle, % "ahk_id " theHwnd
                    clipText:=winTitle "`n" className "`n" processName "`n" winStyle "`n" winExStyle
                    Clipboard:=clipText
                    ToolTip % clipText
                    Sleep 500
                    ToolTip

                    DllCall("SetForegroundWindow","Ptr",theHwnd)
                    returnValue:=theHwnd
                    break
                }
mmaukii commented 1 year ago

msgbox 1234567 is not reached when i put it in the code. not with pinned window and also not without it. I am not sure where inside of _activateWindowUnder(excludeHwnd:=-1) to put the code. Could you post the full _activateWindowUnder(excludeHwnd:=-1) function?

FuPeiJiang commented 1 year ago
    _activateWindowUnder(excludeHwnd:=-1) {
        bak_DetectHiddenWindows:=A_DetectHiddenWindows
        DetectHiddenWindows, off
        returnValue:=-1
        WinGet, outHwndList, List
        loop % outHwndList {
            theHwnd:=outHwndList%A_Index%
            if (theHwnd == excludeHwnd) {
                continue
            }
            if (pView:=this._isValidWindow(theHwnd)) {
                WinGet, OutputVar_MinMax, MinMax, % "ahk_id " theHwnd
                if (!(OutputVar_MinMax==-1)) { ;not Minimized
                    ; WinActivate % "ahk_id " theHwnd
                    WinGetTitle winTitle, % "ahk_id " theHwnd
                    WinGetClass className, % "ahk_id " theHwnd
                    WinGet processName, ProcessName, % "ahk_id " theHwnd
                    WinGet winStyle, Style, % "ahk_id " theHwnd
                    WinGet winExStyle, ExStyle, % "ahk_id " theHwnd
                    clipText:=winTitle "`n" className "`n" processName "`n" winStyle "`n" winExStyle
                    Clipboard:=clipText
                    ToolTip % clipText
                    Sleep 500
                    ToolTip

                    DllCall("SetForegroundWindow","Ptr",theHwnd)
                    returnValue:=theHwnd
                    break
                }
            }
        }
        DetectHiddenWindows % bak_DetectHiddenWindows
        return returnValue
    }
mmaukii commented 1 year ago

with firefox open i get the following tooltip can not change desktop . Issue '39 . FuPeiJian/VD.ahk-Mozilla Firefox MozillaWindowClass 0x17CF0000 0x000000100

FuPeiJiang commented 1 year ago

so firefox was the active window before switching ? or it is the active window in the desktop you're trying to switch to ? this is weird, because it isn't supposed to be detecting windows inside other virtual desktops

one fix is to filter the windows inside _activateWindowUnder using _desktopNum_from_Hwnd

what's your AHK version ?

MsgBox % Clipboard:=A_AhkVersion
FuPeiJiang commented 1 year ago

@mmaukii does this work now ? download the latest version, not the commit 7c0a466

mmaukii commented 1 year ago

it seems to work!!!!! thank you a lot. Now i can work happily. If it is of any concern: ahkversion 1.1.31.00

Thank again for your effort and the great tool!!