Winactive not working right for me

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
amz67
Posts: 19
Joined: 08 Dec 2016, 16:26

Winactive not working right for me

Post by amz67 » 11 May 2021, 15:49

I recently posted a problem in getting my Word windows to open maximized when I cycled between them. Someone on this forum was kind enough to suggest script to use (I can't find the post anymore to thank him, though I did thank him at the time). However, while I want the script to run only if Word is the active window, it is running when other windows are open, including Excel, Dosbox, and Windows explorer. (At the least, it is disabling the functionality of F2 in those programs, so I assume it is running). I am just not familiar enough with Wintitle to understand what the problem is. Can anyone help me diagnose this? Thanks. Here's the script I was given:

Code: Select all

F2::
If WinActive(wTitle := "ahk_class OpusApp ahk_exe WINWORD.EXE") {
 WinSet, Bottom
 WinActivate, %wTitle%
 WinMaximize, A
} 
Return
[Mod edit: [code][/code] tags added.]

User avatar
boiler
Posts: 16771
Joined: 21 Dec 2014, 02:44

Re: Winactive not working right for me

Post by boiler » 11 May 2021, 16:38

To only have the F2 key be active as a hotkey only when Word is active so that it's not affected when other programs' windows are active, you need to use an #If or #IfWin... directive:

Code: Select all

#If WinActive("ahk_class OpusApp ahk_exe WINWORD.EXE")
F2::
 WinSet, Bottom
 WinActivate, ahk_class OpusApp ahk_exe WINWORD.EXE
 WinMaximize, A
Return

amz67
Posts: 19
Joined: 08 Dec 2016, 16:26

Re: Winactive not working right for me

Post by amz67 » 12 May 2021, 06:33

Thank you very much. But now, while the f2 has its original function in other programs, the script isn't working right - it's taking me to the previous open window I was in before Word, regardless of what program. In the other version, it was keeping me within Word. Sorry I'm so ignorant in this great program, but I just don't understand things at the level I would need to in order to fix this myself.

User avatar
boiler
Posts: 16771
Joined: 21 Dec 2014, 02:44

Re: Winactive not working right for me

Post by boiler » 12 May 2021, 08:18

Did you change the whole script to exactly what I posted, or did you just change the top couple lines? Notice that the WinTitle no longer uses the variable you assigned. Can you post your script?

Post Reply

Return to “Ask for Help (v1)”