Hotkey vs Win Activate Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
rikoski
Posts: 3
Joined: 10 Jul 2020, 02:19

Hotkey vs Win Activate

10 Jul 2020, 02:38

Hi, can someone please explain me why having hotkey does not activate the window??
The below code does not work and it drives me nuts.
If I comment lines 4-6 it opens the Adobe Acrobat without any issues. I tried different hotkeys - same @#$%

Weird bug?

Code: Select all

DetectHiddenWindows, On
SetTitleMatchMode 2

#F1::
MsgBox, Test
Return

SwitchAdobeAcrobat()
{
tt = PDFDocument.pdf - Adobe Acrobat Reader DC ahk_class AcrobatSDIWindow
WinWait, %tt%
IfWinNotActive, %tt%,, WinActivate, %tt%
}

SwitchAdobeAcrobat()
Rohwedder
Posts: 3252
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Hotkey vs Win Activate  Topic is solved

10 Jul 2020, 03:02

Hallo,
perhaps:

Code: Select all

DetectHiddenWindows, On
SetTitleMatchMode 2
SwitchAdobeAcrobat()
Return

#F1::
MsgBox, Test
Return

SwitchAdobeAcrobat()
{
	tt = PDFDocument.pdf - Adobe Acrobat Reader DC ahk_class AcrobatSDIWindow
	WinWait, %tt%
	IfWinNotActive, %tt%,, WinActivate, %tt%
}
rikoski
Posts: 3
Joined: 10 Jul 2020, 02:19

Re: Hotkey vs Win Activate

10 Jul 2020, 03:22

Rohwedder wrote:
10 Jul 2020, 03:02
Hallo,
perhaps:

Code: Select all

DetectHiddenWindows, On
SetTitleMatchMode 2
SwitchAdobeAcrobat()
Return

#F1::
MsgBox, Test
Return

SwitchAdobeAcrobat()
{
	tt = PDFDocument.pdf - Adobe Acrobat Reader DC ahk_class AcrobatSDIWindow
	WinWait, %tt%
	IfWinNotActive, %tt%,, WinActivate, %tt%
}

Hi, yes I just figured few moments later, thank you.
Actually it does not have to be return in row 4.

This works which is basically same as you answered:

Code: Select all

Sleep, 2000

SwitchNotepad()

#F1::
MsgBox, Test
Return

SwitchNotepad()
{
WinActivate ahk_class Notepad
}

So, does anyone know why Hotkey definition must be AFTER any function call with WinActivate? That looks weird to me.
Rohwedder
Posts: 3252
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Hotkey vs Win Activate

10 Jul 2020, 04:03

See: https://www.autohotkey.com/docs/Scripts.htm#auto
Note: While the script's first hotkey/hotstring label has the same effect as return, other hotkeys and labels do not.

Code: Select all

DetectHiddenWindows, On
SetTitleMatchMode 2
;Here is a hidden Return which ends the Auto-Execute Section.
;Everything below will only be executed when it is called.

#F1::
MsgBox, Test
Return

SwitchAdobeAcrobat()
{
tt = PDFDocument.pdf - Adobe Acrobat Reader DC ahk_class AcrobatSDIWindow
WinWait, %tt%
IfWinNotActive, %tt%,, WinActivate, %tt%
}

SwitchAdobeAcrobat()
rikoski
Posts: 3
Joined: 10 Jul 2020, 02:19

Re: Hotkey vs Win Activate

11 Jul 2020, 02:01

Rohwedder wrote: See: https://www.autohotkey.com/docs/Scripts.htm#auto
Note: While the script's first hotkey/hotstring label has the same effect as return, other hotkeys and labels do not.

Thank you ! I read that manual page but misunderstood it!
Thank you so much.
Rohwedder
Posts: 3252
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Hotkey vs Win Activate

11 Jul 2020, 02:39

Without this hidden Return the first hotkey/hotstring would be executed immediately at startup.
With a (dirty) trick you can skip it.
Try:

Code: Select all

DetectHiddenWindows, On
SetTitleMatchMode 2
IF False
;skips the hidden return
#F1::
MsgBox, Test
Return

Return to “Ask For Help”

Who is online

Users browsing this forum: 4k3or3et, boiler, doubledave22, Google [Bot], JaydeNpie, jeongrak2, jvlz, keanpteamos, kevlea, loek6000, NatK, Sabestian Caine and 52 guests