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

Office 365 setup pops up unexpectedly #40

Open christodoulos opened 1 year ago

christodoulos commented 1 year ago

Hello, thanks a lot for your repository! I use Windows 11 Pro 22H2, and I am experiencing super strange behavior when I move a window for a second time using WinCtrlShift and the arrow keys: The window carries just fine between the virtual desktops, but after the second movement, the Office 365 setup pops up! Of course, I can quickly close the popup, and even with this glitch moving windows between desktops is super easy instead of clicking on the taskbar with dragging and dropping.

Office 365 is already installed, and I am using it through my university subscription. I wonder if I am the only one experiencing this strange behavior. Am I missing something here? I am not a Windows power user, and I miss the shortcuts of the Linux desktop.

Thanks again.

christodoulos commented 1 year ago

OK, I meant to post the issue to https://github.com/phazei/Win11AutoHotKeyFixes. But does this ring a bell?

FuPeiJiang commented 1 year ago

this is the minimum to reproduce it:

#SingleInstance force
ListLines 0
SendMode "Input"
SetWorkingDir A_ScriptDir
KeyHistory 0
#WinActivateForce

ProcessSetPriority "H"

SetWinDelay -1
SetControlDelay -1

keybd_eventDown("LWin")
keybd_eventDown("LCtrl")
keybd_eventDown("LShift")
WinActivate "ahk_class Progman ahk_exe explorer.exe" ;office 365 bug
;WinActivate "ahk_class WorkerW ahk_exe explorer.exe" ;no bug
;WinActivate "ahk_exe notepad.exe" ;no bug

keybd_eventDown(key)
{
  DllCall("keybd_event","UChar",GetKeyVK(key),"UChar",GetKeySC(key),"Uint",0,"Ptr",0)
}
keybd_eventUp(key)
{
  DllCall("keybd_event","UChar",GetKeyVK(key),"UChar",GetKeySC(key),"Uint",2,"Ptr",0)
}

f3::Exitapp

the above is v2 code ___ Office OfficeApp-Frame WebViewHost.exe 0x16CF0000 0x00000100 ___

@christodoulos does this bug only happen when the destination virtual desktop is empty ?

christodoulos commented 1 year ago

@christodoulos does this bug only happen when the destination virtual desktop is empty ?

After a reboot, when I manually start, say, a Windows explorer in both Virtual Desktop 1 and Virtual Desktop 2, and then start a terminal in Virtual Desktop 1, when I move it using WinCtrlShift-> then the terminal window moves just fine, and nothing else is happening (i.e., the bug does not happen).

Keeping both explorer windows open at Virtual Desktop 1 and Virtual Desktop 2, I can use WinCtrlShift-> and WinCtrlShift<-, and the terminal window keeps moving between the virtual desktops without any Office 365 window popping up. But if I close the Explorer Window before moving the terminal window from Virtual Desktop 2 to Virtual Desktop 1 using WinCtrlShift<-, the Office 365 setup window starts popping up again!

The Windows OS never stops to amaze me with awkward behaviors!

FuPeiJiang commented 1 year ago

this even happens on Windows 10

Help disabling Office hotkey of Ctrl + Win + Alt + Shift that leads to Office 365 Login Page

https://answers.microsoft.com/en-us/msoffice/forum/all/help-disabling-office-hotkey-of-ctrl-win-alt-shift/040ef6e5-8152-449b-849a-7494323101bb

this makes me suspect that WinActivate of AHK sends !{Tab}

https://github.com/AutoHotkey/AutoHotkey/blob/df84a3e902b522db0756a7366bd9884c80fa17b6/source/window.cpp#L260-L261

        KeyEvent(KEYDOWNANDUP, VK_MENU);
        KeyEvent(KEYDOWNANDUP, VK_MENU);

VK_MENU | 0x12 | ALT key

That's only ALT, but not ALT+TAB, I'm not even sure if the code execution reaches that line

FuPeiJiang commented 1 year ago

@christodoulos does this fix it ?

christodoulos commented 1 year ago

Hello, thanks for your suggestions. I pulled your last repository update:

C:\Users\christodoulos\VD.ahk>git log
commit 3cb24e3ea6c0223bed08c9c335d34b5c658da706 (HEAD -> class_VD, origin/class_VD, origin/HEAD)
Author: FuPeiJiang <42662615+FuPeiJiang@users.noreply.github.com>
Date:   Mon May 15 18:02:42 2023 -0400

    _activateDesktopBackground(); #40

and uninstalled the Office 365 application. Using your latest commit, the problem remains with a different nature:

  1. I boot my laptop and have no windows opened.
  2. I start a Terminal on Virtual Desktop 1
  3. By pressing WinCtrlShift->, the Terminal is moved to Virtual Desktop 2, and a Browser Window flashes and disappears.
  4. Moving to Virtual Desktop 1 using WinCtrl<- I see a Browser Window that I didn't open myself with a new tab opened at https://www.office.com/?from=OfficeKey
  5. I manually close the browser window and move to Virtual Desktop 2 using WinCtrl->. There I find the Terminal window from step 3, and using WinCtrlShift-> I move it to Virtual Desktop 3. The browser window flashes again and immediately disappears. Moving to Virtual Desktop 1 by pressing two times WinCtrl<-, I find the browser window with two tabs opened at https://www.office.com/?from=OfficeKey

Of course, the new behavior is much more tolerable as I can live with using Virtual Desktops 2 and 3 and letting the browser windows pop up at Virtual Desktop 1.

FuPeiJiang commented 1 year ago

before I bring in a proper fix, does this work ?

; move window to left and follow it
^#+left::
keybd_eventUp("LShift")
VD.goToDesktopNum(VD.MoveWindowToRelativeDesktopNum("A", -1))
Send % "{LShift down}"
return

; move window to right and follow it
^#+right::
keybd_eventUp("LShift")
VD.goToDesktopNum(VD.MoveWindowToRelativeDesktopNum("A", 1))
Send % "{LShift down}"
return

;functions
keybd_eventUp(key)
{
  DllCall("keybd_event","UChar",GetKeyVK(key),"UChar",GetKeySC(key),"Uint",2,"Ptr",0)
}

so in "VD-move-window-with-desktop.ahk", you replace the 2 hotkeys with the above

^#+Left::
    n := VD.getCurrentDesktopNum()
    if n = 1 ;at begining, can't go left
        Return

    n -= 1
    active := "ahk_id" WinExist("A")
    VD.MoveWindowToDesktopNum(active,n), VD.goToDesktopNum(n)
    WinActivate active ;once in a while it's not active
Return

^#+Right::
    n := VD.getCurrentDesktopNum()
    if n = % VD.getCount() ;at end, can't go right
        Return

    n += 1
    active := "ahk_id" WinExist("A")
    VD.MoveWindowToDesktopNum(active,n), VD.goToDesktopNum(n)
    WinActivate active
Return
FuPeiJiang commented 1 year ago

which version of AHK are you using ?

MsgBox % Clipboard:=A_AhkVersion

maybe the implementation for WinActivate has changed

christodoulos commented 1 year ago

Using your script above: image But in Apps > Installed apps: image My D-move-window-with-desktop.ahk:

;FROM https://superuser.com/questions/1685845/moving-current-window-to-another-desktop-in-windows-11-using-shortcut-keys

;#SETUP START
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
#SingleInstance force
ListLines Off
SetBatchLines -1
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
#KeyHistory 0
#WinActivateForce

Process, Priority,, H

SetWinDelay -1
SetControlDelay -1

;include the library
#Include ../VD.ahk/VD.ahk
; VD.init() ;COMMENT OUT `static dummyStatic1 := VD.init()` if you don't want to init at start of script

;you should WinHide invisible programs that have a window.
WinHide, % "Microsoft 365 App Host"
;#SETUP END

VD.createUntil(3) ;create until we have at least 3 VD

return

^#+Left::
    n := VD.getCurrentDesktopNum()
    if n = 1 ;at begining, can't go left
        Return

    n -= 1
    active := "ahk_id" WinExist("A")
    VD.MoveWindowToDesktopNum(active,n), VD.goToDesktopNum(n)
    WinActivate active ;once in a while it's not active
Return

^#+Right::
    n := VD.getCurrentDesktopNum()
    if n = % VD.getCount() ;at end, can't go right
        Return

    n += 1
    active := "ahk_id" WinExist("A")
    VD.MoveWindowToDesktopNum(active,n), VD.goToDesktopNum(n)
    WinActivate active
Return
christodoulos commented 1 year ago

I don't know if it is relevant but I installed AutoHotkey using scoop:

C:\Users\christodoulos>scoop list
Installed apps:

Name            Version    Source Updated             Info
----            -------    ------ -------             ----
autohotkey      2.0.2      extras 2023-01-02 20:11:29
FuPeiJiang commented 1 year ago

@christodoulos

try this script, I added keybd_eventUp("LShift")

;#SETUP START
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
#SingleInstance force
ListLines Off
SetBatchLines -1
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
#KeyHistory 0
#WinActivateForce

Process, Priority,, H

SetWinDelay -1
SetControlDelay -1

;include the library
#Include ../VD.ahk/VD.ahk
; VD.init() ;COMMENT OUT `static dummyStatic1 := VD.init()` if you don't want to init at start of script

VD.createUntil(3) ;create until we have at least 3 VD

return

^#+Left::
    n := VD.getCurrentDesktopNum()
    if n = 1 ;at begining, can't go left
        Return

    n -= 1
    active := "ahk_id" WinExist("A")
    keybd_eventUp("LShift")
    VD.MoveWindowToDesktopNum(active,n)
    VD.goToDesktopNum(n)
    WinActivate active ;once in a while it's not active
    keybd_eventDown("LShift")
Return

^#+Right::
    n := VD.getCurrentDesktopNum()
    if n = % VD.getCount() ;at end, can't go right
        Return

    n += 1
    active := "ahk_id" WinExist("A")
    keybd_eventUp("LShift")
    VD.MoveWindowToDesktopNum(active,n)
    VD.goToDesktopNum(n)
    WinActivate active
    keybd_eventDown("LShift")
Return

;functions
keybd_eventDown(key)
{
  DllCall("keybd_event","UChar",GetKeyVK(key),"UChar",GetKeySC(key),"Uint",0,"Ptr",0)
}
keybd_eventUp(key)
{
  DllCall("keybd_event","UChar",GetKeyVK(key),"UChar",GetKeySC(key),"Uint",2,"Ptr",0)
}

I'm pretty sure it will work, but it's not the correct way to fix it , I'll need your help to test/debug a bit more because I can't reproduce the issue anymore

FuPeiJiang commented 1 year ago

in order to debug, checkout the branch https://github.com/FuPeiJiang/VD.ahk/tree/tooltip-debug, use your unedited D-move-window-with-desktop.ahk script, not the ones I sent
there are 3 possible ToolTips: 1. ToolTip % "WinActivate % ""ahk_class WorkerW ahk_exe explorer.exe""" 2. ToolTip % "WinActivate % ""ahk_class Progman ahk_exe explorer.exe""" 3. Command Prompt ConsoleWindowClass cmd.exe 0x14EF0000 0x000C0110

what ToolTips do you see when pressing the hotkeys ?

you may want desktop switching animations to be enabled for the ToolTip to last longer, but I think animations are enabled by default so it's not a problem

FuPeiJiang commented 1 year ago

nvm, there Are no VD animations in Win11

great news, I've been able to reproduce the issue again

christodoulos commented 1 year ago

After receiving the GitHub notification, I rebooted my laptop to start from a clear state. Then I started a Terminal and could happily move it across all my virtual desktops without any other, at least noticeable, unintended behavior! Well, just like that, the bug is not present anymore! I did nothing regarding AutoHotKey or your repository!

To follow your instructions above, I checked out the branch you proposed:

C:\Users\christodoulos\VD.ahk>git branch
  class_VD
* origin/tooltip-debug

Using the unedited script, I see no ToolTips of any kind when I press the hotkeys. Do I get it right? I checkout your branch and then move a window around the virtual desktops, and some tooltips should appear? Unfortunately, they don't. Nevertheless, the bug does not happen using the class_VD branch or the tooltip-debug branch.

I realize that bugs don't heal themselves. If you'd like to help you more, please don't hesitate to ask.

FuPeiJiang commented 1 year ago

I see no ToolTips of any kind when I press the hotkeys.

some tooltips should appear I suspect that you have 2 VD.ahk folders delete to recycle bin the files C:\Users\christodoulos\VD.ahk\VD.ahk and C:\Users\christodoulos\VD.ahk\_VD.ahk if your script still runs then you have 2 VD.ahk folders

___

I'm not able to change the VD of: Microsoft Teams Chrome_WidgetWin_1 Teams.exe 0x14C20000 0x00000100 (using VD.MoveWindowToDesktopNum)

this is a huge bug, it's also linked to the office 365 problem because if the window below active window is Teams.exe, then even if I removed all WinActivate in _VD.ahk and your script, office 365 still pops up

christodoulos commented 1 year ago

I deleted everything to make sure that I have only one VD.ahk folder. Then I double-clicked on the VD-move-window-with-desktop.ahk file, and the error message popped up: image Then I checked out the tooltip-debug branch and double-clicked again on the VD-move-window-with-desktop.ahk file. This time the script ran, and the icon appeared in my taskbar. Then I can move any window around the virtual desktops, and the bug is not present anymore! Like it never happened! Unfortunately, though, I can see no tooltips. Perhaps I am missing something.

Just so you know, when I delete the files you propose (without exiting from the icon in the taskbar), the script continues to run, and I can move windows to other virtual desktops. After exiting from the icon in the taskbar, I cannot start the VD-move-window-with-desktop.ahk, and I am getting the same error message as above. Restoring from the recycle bin, the script runs again successfully, and everything works again just fine, with no bugs and, unfortunately, no tooltips.

I don't know if it is relevant, but I also run two other AutoHotKey scripts:

For changing input language using Caps Lock:

sel := 0

#if (sel=0)
capslock::
    send {lwin down}{Space}
    sel := 1
return
#if

capslock up::
    send {lwin up}
    sel := 0
return

And for hiding the cursor while typing:

; AutoHotkey Version: 1.x
; Language:       English
; Platform:       Win9x/NT
; Author:         Stefan Z Camilleri - stefan@camilleri.me

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

; Initialize the mouse cursor
SystemCursor("Init")

; Get the current mouse position, and store its coordinates
MouseGetPos mX0, mY0

; Set a timer to check if the mouse is still idle every 250ms
SetTimer, CheckIdle, 250

; Register the keys you want to listen on
keys = ``1234567890-=qwertyuiop[]\asdfghjkl;'zxcvbnm,./

; For every defined key, register a call to hide the mouse cursor
Loop Parse, keys
   HotKey ~*%A_LoopField%, Hoty
return

; Checks if the mouse has moved, and if so, shows it and records the new position
CheckIdle:
MouseGetPos mX, mY
if (mX0 != mX && mY0 != mY)
{
    SystemCursor("On")
    mX0 := mX, mY0 := mY
}
return

; Hides the mouse cursor
Hoty:
   SystemCursor("Off")
return

; Ensure the cursor is made visible when the script exits.
#Persistent
    OnExit, ShowCursor
return

; Shows the mouse cursor
ShowCursor:
SystemCursor("On")
ExitApp

; Function to hide or show the mouse cursor
SystemCursor(OnOff=1)   ; INIT = "I","Init"; OFF = 0,"Off"; TOGGLE = -1,"T","Toggle"; ON = others
{
    static AndMask, XorMask, $, h_cursor
        ,c0,c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13 ; system cursors
        , b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,b13   ; blank cursors
        , h1,h2,h3,h4,h5,h6,h7,h8,h9,h10,h11,h12,h13   ; handles of default cursors

    if (OnOff = "Init" or OnOff = "I" or $ = "")       ; init when requested or at first call
    {
        $ = h                                          ; active default cursors
        VarSetCapacity( h_cursor,4444, 1 )
        VarSetCapacity( AndMask, 32*4, 0xFF )
        VarSetCapacity( XorMask, 32*4, 0 )
        system_cursors = 32512,32513,32514,32515,32516,32642,32643,32644,32645,32646,32648,32649,32650
        StringSplit c, system_cursors, `,
        Loop %c0%
        {
            h_cursor   := DllCall( "LoadCursor", "uint",0, "uint",c%A_Index% )
            h%A_Index% := DllCall( "CopyImage",  "uint",h_cursor, "uint",2, "int",0, "int",0, "uint",0 )
            b%A_Index% := DllCall("CreateCursor","uint",0, "int",0, "int",0
                , "int",32, "int",32, "uint",&AndMask, "uint",&XorMask )
        }
    }

    if (OnOff = 0 or OnOff = "Off" or $ = "h" and (OnOff < 0 or OnOff = "Toggle" or OnOff = "T"))
        $ = b  ; use blank cursors
    else
        $ = h  ; use the saved cursors

    Loop %c0%
    {
        h_cursor := DllCall( "CopyImage", "uint",%$%%A_Index%, "uint",2, "int",0, "int",0, "uint",0 )
        DllCall( "SetSystemCursor", "uint",h_cursor, "uint",c%A_Index% )
    }
}

Unfortunately, I don't have the time to understand the scripts, and I blindly copy them.

FuPeiJiang commented 1 year ago

more a note to myself:

Loading Microsoft Teams ahk_class Chrome_WidgetWin_1 ahk_exe Teams.exe Style:0x1CC00000 ExStyle:0x00000100

moving pView from hwnd of "Loading Microsoft Teams" works, pView from hwnd of "Microsoft Teams" doesn't