handling Edge with WinShow/WinActivate

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
vaderetro
Posts: 16
Joined: 12 May 2017, 09:22

handling Edge with WinShow/WinActivate

06 May 2021, 16:08

hi,

I use a script to manage my windows (make them visible/invisible). I target them with the title/class/exe and:

WinShow
WinActivate

etc.

Works very well, but there is one app that only works in
Spoiler
certain circumstances (which I am not sure which are they): Edge. Anyone has a clue what could be going on?
Im in win10 20h2, with a very recent ahk (probably last).
User avatar
mikeyww
Posts: 26951
Joined: 09 Sep 2014, 18:38

Re: handling Edge with WinShow/WinActivate

06 May 2021, 16:18

You can post your script for feedback about it.
vaderetro
Posts: 16
Joined: 12 May 2017, 09:22

Re: handling Edge with WinShow/WinActivate

09 May 2021, 07:19

OK, I made a small reproducible script:

Code: Select all

toggleAppExe(class){
    DetectHiddenWindows, on
    ;MsgBox, %class%
    IfWinExist ahk_exe %class%
    {
        IfWinActive ahk_exe %class%
        {
            WinHide ahk_exe %class%
            WinActivate ahk_class Shell_TrayWnd
        }
        else
        {
                ; MsgBox, showbegin: 
            WinShow ahk_exe %class%
            WinActivate ahk_exe %class%
        }
    }
    DetectHiddenWindows, off
}

;Edge
CapsLock & ]::
toggleAppExe("msedge.exe")
; toggleAppExe("WindowsTerminal.exe")
return
If you uncomment Wt line, and commnet out Edge one, this works perfectly for Wt. But for Edge, it's very unreliable. It works just after starting Edge, but as soon as I open a tab with Gmail and a second tab. It does not work anymore,nothing happens. I move focus around, click stuff, and suddenly it works again...till when it does not.

I have not been able to identify what makes this work or not.

many thanks in advance
User avatar
mikeyww
Posts: 26951
Joined: 09 Sep 2014, 18:38

Re: handling Edge with WinShow/WinActivate

09 May 2021, 07:40

The following seemed to work.

Code: Select all

CapsLock & ]::toggleAppExe("msedge.exe")

toggleAppExe(proc) {
 DetectHiddenWindows, On
 Sleep, 200
 If WinExist(wTitle := "ahk_exe " proc) {
  If WinActive(wTitle) {
   WinHide
   WinActivate, ahk_class Shell_TrayWnd
  } Else {
   WinShow
   WinActivate
  }
 }
 DetectHiddenWindows, Off
}
vaderetro
Posts: 16
Joined: 12 May 2017, 09:22

Re: handling Edge with WinShow/WinActivate

23 May 2021, 11:50

hey,

I deployed this. It goes integrated in my longer scripts that do many other things, but I think it does alleviate the problem, it does go away completely, but it certainly happens less often. So it is an improvement. I don't understand what is happening and how your code differs from mine, but thanks!!

Oh I removed the sleep, did not seem to do anything anyway.
vaderetro
Posts: 16
Joined: 12 May 2017, 09:22

Re: handling Edge with WinShow/WinActivate

24 May 2021, 08:02

Ok, I have found one issue easy to reproduce...

- launch Edge
- C-F to search for something in the page
- close search window
- now hit the hostring to hide/show Edge, and see how the window that is shown is the search window!!
2021-05-24 14_55_57-Window.png
2021-05-24 14_55_57-Window.png (4.9 KiB) Viewed 1484 times
User avatar
mikeyww
Posts: 26951
Joined: 09 Sep 2014, 18:38

Re: handling Edge with WinShow/WinActivate

24 May 2021, 08:25

You can try adding the class name to the WinTitle.
vaderetro
Posts: 16
Joined: 12 May 2017, 09:22

Re: handling Edge with WinShow/WinActivate

24 May 2021, 12:14

mikeyww wrote:
24 May 2021, 08:25
You can try adding the class name to the WinTitle.
not sure how that would look in your ahk snippet, care to show please?

But anyway, I don't think it would work as both the 'main' Edge window and the tiny search windows share the same class: Chrome_WidgetWin_1. The main one has a title, the search one does not though, could that be used somehow?

thank you
User avatar
mikeyww
Posts: 26951
Joined: 09 Sep 2014, 18:38

Re: handling Edge with WinShow/WinActivate

24 May 2021, 13:24

Yes. The following idea worked to distinguish the main window from the "Find" dialog.

Code: Select all

SetTitleMatchMode, RegEx
F3::
If WinActive(".+ ahk_exe msedge.exe")
 SoundBeep, 1500
Return
An alternative is just getting the active window title.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Joey5, just me and 219 guests