#If WinActive() shorthand? Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
leo007
Posts: 50
Joined: 26 Oct 2019, 04:56

#If WinActive() shorthand?

18 Jan 2020, 04:30

Hi Everyone,

I got follow script to select full line depending on activity.

Code: Select all

 #If WinActive("ahk_exe notepad.exe") OR WinActive("ahk_exe notepad++.exe") OR WinActive("ahk_exe Code.exe") OR WinActive("ahk_exe studio64.exe") OR WinActive("ahk_exe idea64.exe") OR WinActive("- OneNote ahk_class ApplicationFrameWindow", "OneNote")
  $!LButton:: ; SELECT FULL TEXT LINE IN TEXT
  {
    KeyWait, Alt
    SendInput, {Esc}{LButton}
    SendInput, {HOME}{ShiftDown}{End}{ShiftUp}
    return
  }
  #IfWinActive
  
 #If WinActive("ahk_exe chrome.exe") OR WinActive("ahk_exe firefox.exe")
  $!LButton:: ; SELECT FULL TEXT LINE IN TEXT
  {
    KeyWait, Alt
    SendInput, {Esc}{LButton 3}
    Return
  }
  #IfWinActive
  
is there a shorter way to write this if select activity that repeat itself with "OR WinActive("") each time?

Thanks in advance
blad4
Posts: 222
Joined: 07 Oct 2015, 11:06

Re: #If WinActive() shorthand?

18 Jan 2020, 04:40

Code: Select all

SetTitleMatchMode, REGEX
#IfWinActive "ahk_exe notepad.exe")|("ahk_exe notepad++.exe") ...
leo007
Posts: 50
Joined: 26 Oct 2019, 04:56

Re: #If WinActive() shorthand?

18 Jan 2020, 05:17

blad4 Thanks for your Reply
yes its look exactly as I wanted it but of some reason it doesn't trigger anything.
could you please check if all the syntax is correct please

modified script

Code: Select all

SetTitleMatchMode, REGEX
#IfWinActive "ahk_exe chrome.exe")|("ahk_exe firefox.exe")
  $!LButton:: ; SELECT FULL TEXT LINE IN TEXT
{
    MsgBox,  Triggered
    Return
}
Last edited by leo007 on 18 Jan 2020, 05:20, edited 1 time in total.
User avatar
Xtra
Posts: 1833
Joined: 02 Oct 2015, 12:15

Re: #If WinActive() shorthand?  Topic is solved

18 Jan 2020, 05:19

See: GroupAdd
Example:
Spoiler
User avatar
boiler
Posts: 5909
Joined: 21 Dec 2014, 02:44

Re: #If WinActive() shorthand?

18 Jan 2020, 07:00

blad4 wrote:
18 Jan 2020, 04:40

Code: Select all

SetTitleMatchMode, REGEX
#IfWinActive "ahk_exe notepad.exe")|("ahk_exe notepad++.exe") ...
Can’t use #IfWinActive that way. Has to be #If followed by multiple WinActive() function calls like the OP had. Changing to the other “or” operator alone won’t save any characters, especially because:

A single | (vertical bar) character is for bit-wise operations and doesn’t apply here. The alternative to or to be used here is || (double vertical bar).

You’re also missing an open parenthesis.

Edit: A properly formed regular expression may allow you to do something more along these lines, but the syntax show is not a regular expression.
blad4
Posts: 222
Joined: 07 Oct 2015, 11:06

Re: #If WinActive() shorthand?

18 Jan 2020, 07:17

boiler wrote:
18 Jan 2020, 07:00
blad4 wrote:
18 Jan 2020, 04:40

Code: Select all

SetTitleMatchMode, REGEX
#IfWinActive "ahk_exe notepad.exe")|("ahk_exe notepad++.exe") ...
Can’t use #IfWinActive that way. Has to be #If followed by multiple WinActive() function calls like the OP had. Changing to the other “or” operator alone won’t save any characters, especially because:

A single | (vertical bar) character is for bit-wise operations and doesn’t apply here. The alternative to or to be used here is || (double vertical bar).

You’re also missing an open parenthesis.

Edit: A properly formed regular expression may allow you to do something more along these lines, but the syntax show is not a regular expression.
Thank you boiler
Helgef
Posts: 4459
Joined: 17 Jul 2016, 01:02
Contact:

Re: #If WinActive() shorthand?

18 Jan 2020, 07:21

#ifwinactive regex example,

Code: Select all

setTitleMatchMode regex
#ifwinactive ahk_exe (notepad|opera)\.exe
a::msgbox
Matches either notepad or opera exe.

Cheers.
leo007
Posts: 50
Joined: 26 Oct 2019, 04:56

Re: #If WinActive() shorthand?

18 Jan 2020, 07:59

blad4, boiler, Xtra, Helgef Thank you all guy for great scripts and valued explanation.
I learned by all of your examples thing I haven't know before.

in this particular case the most minimal script I guess would be out of Helgef example

Code: Select all

 setTitleMatchMode regex
 #ifwinactive ahk_exe (notepad|notepad++|Code|studio64|idea64|Everything)\.exe
     $!LButton::
     MsgBox, triggered
     return

only one small question how to add

Code: Select all

 OR WinActive("- OneNote ahk_class ApplicationFrameWindow", "OneNote") 
to this script?

thanks in advance
Helgef
Posts: 4459
Joined: 17 Jul 2016, 01:02
Contact:

Re: #If WinActive() shorthand?

18 Jan 2020, 08:05

I recommend you use Xtra's suggestion (regardless) and just add or WinActive(...) to it.

Edit, I see it already covers that, so just use it as is :thumbup:. You could change it to #ifwinactive ahk_group groupone, though.

Cheers.

Return to “Ask For Help”

Who is online

Users browsing this forum: kintar0e, kiwiboost, mikeyww, mslonik, teadrinker and 66 guests