WinHide wihout Hotkey Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Lem2001
Posts: 127
Joined: 27 Jun 2017, 17:59

WinHide wihout Hotkey

11 Jun 2019, 06:40

I'm trying to hide an object that gets added to File Open / Save As dialogs.

If I use the following, it works fine when the hotkey is pressed (the added object disappears).

Code: Select all

#IfWinExist ahk_class #32770
^F2::
WinHide ahk_class Listary_WidgetWin_1
return
#If

However, I am trying to make the object hidden by default. But if I remove the hotkey (or even if I remove the conditional directive altogether so that object should be hidden regardless of the presence of an active file dialog) it doesn't work. The object still displays in all dialogs.

How can I get the WinHide command above to be carried out automatically without requiring a hotkey to trigger it?
Rohwedder
Posts: 7616
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: WinHide wihout Hotkey  Topic is solved

11 Jun 2019, 07:22

Hallo,
try a Timer:

Code: Select all

SetTimer, WinHide, 200
Return
WinHide:
IF WinExist("ahk_class #32770")
	WinHide ahk_class Listary_WidgetWin_1
Return
Lem2001
Posts: 127
Joined: 27 Jun 2017, 17:59

Re: WinHide wihout Hotkey

11 Jun 2019, 08:13

Thanks!

It works, but there's a bit of an issue that I'm trying to deal with:

The object appears briefly on the dialog before it disappears. I can get rid of this by reducing the duration of the timer, but I have to put it as low as 10ms before there is no visible 'flash' on the dialog.

I really don't want a function running constantly at 10ms intervals, so can this timer be activated only when ahk_class #32770 exists? (in other words, can I wrap your timer function code into a #IfWinExists directive without it breaking?). I tried a couple of ways of doing this, but it stopped the timer from working.
Rohwedder
Posts: 7616
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: WinHide wihout Hotkey

11 Jun 2019, 08:43

unfortunately not, see:
https://www.autohotkey.com/docs/Language.htm#not-control-flow
#IfWinExist can't trigger anything.
Rohwedder
Posts: 7616
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: WinHide wihout Hotkey

11 Jun 2019, 08:53

perhaps this?:

Code: Select all

SetTimer, WinHide, -200
Return
WinHide:
IF WinExist("ahk_class #32770")
{
	WinHide ahk_class Listary_WidgetWin_1
	SetTimer, WinHide, -10
}
Else
	SetTimer, WinHide, -200
Return
Lem2001
Posts: 127
Joined: 27 Jun 2017, 17:59

Re: WinHide wihout Hotkey

11 Jun 2019, 16:25

Rohwedder wrote:
11 Jun 2019, 08:43
unfortunately not, see:
https://www.autohotkey.com/docs/Language.htm#not-control-flow
#IfWinExist can't trigger anything.
Wow, thanks for this! I don't know how I have not seen this before.

I have spent so much time in the past trying to get this to work, and I assumed that it was my bad code writing that was the reason for it not working. It's disappointing that it doesn't have that functionality, but now at least I won't waste any more of my time trying.

Your last code suggestion above did not work, but I did manage to get an acceptable result by using a 'clunky' work-around added to your first code example. I slowed down the timer and switched the matching criteria from WinExist to WinActive. Then, for the part of the code where there is a match, I had the WinHide command run a few times with a very short sleep command in between.

It did the job, and completely got rid of the visible object flashing on the dialog box, and that short duration code only runs when a File dialog is active (rather than all the time while its checking and waiting for a match).

Thanks again for your help.
Lem2001
Posts: 127
Joined: 27 Jun 2017, 17:59

Re: WinHide wihout Hotkey

13 Jun 2019, 04:53

Hi,

I've just discovered another issue.

Today I started using my computer and the Listary object was back on all of my file dialogs. I had previously tested my script very thoroughly, and it had been working perfectly, so I had no idea what the problem could be.

I then checked the object using Window Spy, and I found that the object had changed its class name (despite it having used the same name for many days previously - even after multiple re-boots). However, it was now called Listary_WidgetWin_0 instead of Listary_WidgetWin_1.

I updated the class name in my script, and everything works perfectly again as it did before. But I don't know how often these kinds of changes will occur in the future. There are only a few occurrences of the Listary class name in my script, to it's easy to manually change it if the object changed its name once every week or two. But if it were to happen every day, then obviously this would become annoying.

I therefore wanted to ask, what would be the best way to "wildcard" the object's class name in a way that does not detrimentally affect the functioning of the script?

I have my TItleMatch mode for that particular script at default (i.e. Mode 1) so I tried just leaving out the last character of the class name (assuming that it would match on the previous characters) but it didn't work.

I suppose I could manually add some extra name variations using "or", but having a long list of different names doesn't seem like a very efficient way to deal with the issue

I'd be grateful if anyone could suggest an efficient way to achieve the effect of the script functions applying to ahk_class Listary_WidgetWin_* (where *star is any character, just in case it adds things other than a number) without making the scope so broad that it creates extra matching work for no reason.

Thanks!
Rohwedder
Posts: 7616
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: WinHide wihout Hotkey

13 Jun 2019, 07:00

Hallo,
try:

Code: Select all

SetTimer, WinHide, 200
Return
WinHide:
IF WinExist("ahk_class #32770")
{
	SetTitleMatchMode, RegEx
	WinHide ahk_class Listary_WidgetWin_*
}
Return
Lem2001
Posts: 127
Joined: 27 Jun 2017, 17:59

Re: WinHide wihout Hotkey

14 Jun 2019, 05:28

That was easier than I thought.

It works great on the currently assigned name, so it should obviously be fine for any alternative.

Thank you!

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Descolada, hiahkforum, jchestnut, mcd, Sem552 and 131 guests