WinExist() issue - not working

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
dzur
Posts: 71
Joined: 15 Jul 2016, 10:44

WinExist() issue - not working

18 Jan 2018, 14:09

Hi,
Please help me with the following script which aim is to:
1.Detect Active Window
2. Move Active Window to x,y position
3. Activate the window

;Active Window Info:
;------------------------------
;Window Title, Class and Process
;-------------------------------
;New notification (Window Title)
;ahk_class Windows.UI.Core.CoreWindow
;ahk_exe ShellExperienceHost.exe

;Script: Does Not Detect Active Window ! :cry:

Please Help, Thank You.

dzur

Code: Select all

;
Menu, MyMenu, Add, Detect Move and Activate Window, MenuHandler
Menu, MyMenu, Add  ; Add a separator line.
Menu, MyMenu, Add, Exit Menu, MenuHandler
;
MenuHandler:
;
if (A_ThisMenuItem = "Detect Move and Activate Window")
; Goal: Detect, Move and Activate an existing New Notification Window
if WinExist, New notification or WinExist("ahk_class Windows.UI.Core.CoreWindow") or WinExist ("ahk_exe ShellExperienceHost.exe")
{
 MsgBox,64,New Notification Window Detected... about to be Moved and Activated !
 ;
 WinMove, 10, 10
 WinActivate, ahk_exe ShellExperienceHost.exe
;-------------------------------------------
}

else
{
MsgBox, Notification Window Not Detected !
}

if (A_ThisMenuItem = " Exit Menu")
{
Exit App
}
;
;Assign Auto Hot Key: (F9)
F9::Menu, MyMenu, Show ; i.e. press the F9 hotkey to show the menu.
;
Osprey
Posts: 453
Joined: 18 Nov 2017, 05:50

Re: WinExist() issue - not working

18 Jan 2018, 16:34

Your first reference to "WinExist" should be a function call, like the rest, and you have a space in the middle of your last WinExist() function call.

Re-write it as the following:

Code: Select all

if WinExist("New notification") or WinExist("ahk_class Windows.UI.Core.CoreWindow") or WinExist("ahk_exe ShellExperienceHost.exe")
BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: WinExist() issue - not working

19 Jan 2018, 01:54

Osprey wrote:Your first reference to "WinExist" should be a function call, like the rest, and you have a space in the middle of your last WinExist() function call.

Re-write it as the following:

Code: Select all

if WinExist("New notification") or WinExist("ahk_class Windows.UI.Core.CoreWindow") or WinExist("ahk_exe ShellExperienceHost.exe")
As you can see at your own post that useless space-char is added from the forum software by mistake (let's call it a bug) even if you find out that it's displayed correctly within the forums editor. :silent:
Noesis
Posts: 301
Joined: 26 Apr 2014, 07:57

Re: WinExist() issue - not working

19 Jan 2018, 02:26

WinExist() doesn't work with these window types unless you also specify the "ahk_id". It's basically a limitation of the way WinExist() works with these windows, (see:https://autohotkey.com/boards/viewtopic ... 14&t=42517 for context).

You could try using WinActive() instead. This may or may not work I'm not sure if notifications force themselves active like other windows of this type.

Another alternative could possibly be found by researching some of the api functions/flags Lexicos mentions in his reply in the linked thread above.
glitchyme
Posts: 1
Joined: 28 Oct 2020, 12:10

Re: WinExist() issue - not working

28 Oct 2020, 12:16

I ran into this issue when I wanted to automatically close a window, but first check if the window was still open. Here was my workaround:

Code: Select all


; Fetch ahk_id of window
WinGet, BrowserID, ID, TitleOfWindowIWasTryingToFind

; Do stuff

; Fetch ahk_id of window using the ahk_id
; Either this will output the same value (if the window is open) or null
WinGet, NewBrowserID, ID, ahk_id %BrowserID%

if %NewBrowserID% {
    WinClose, ahk_id %BrowserID%,, 2
}

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Descolada, Google [Bot] and 242 guests