Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Using the same #IfWinActive for multiple windows


  • Please log in to reply
7 replies to this topic
joeyespo
  • Members
  • 2 posts
  • Last active: Apr 02 2011 04:12 PM
  • Joined: 02 Apr 2011
I'm sure the answer exists, but I can't seem to find it anywhere.

I essentially want to do the following to run "cmd" without args when on the desktop. Unfortunately, there's two desktop windows on Windows XP.

; This is the desktop window
#IfWinActive ahk_class Progman
#c::Run, cmd
#IfWinActive

; WorkerW gets input when you "show desktop" by press Win+D
#IfWinActive ahk_class WorkerW
#c::Run, cmd
#IfWinActive

How can I combine the above to something like this? I feel like I'm close.

; This works, but only for the "ahk_class WorkerW" part
#IfWinActive ahk_class Progman || ahk_class WorkerW
#c::Run, cmd
#IfWinActive

Thanks!

nimda
  • Members
  • 4368 posts
  • Last active: Aug 09 2015 02:36 AM
  • Joined: 26 Dec 2010
#IfWinActive ahk_class Progman
#c::
#IfWinActive ahk_class WorkerW
#c::
Run cmd
return

To have the same hotkey subroutine executed by more than one variant, the easiest way is to create a stack of identical hotkeys, each with a different #IfWin directive above it.

Although this is actually longer than
#IfWinActive ahk_class Progman
#c::run cmd
#IfWinActive ahk_class WorkerW
#c::run cmd
#IfWinActive ; <<<< Optional


joeyespo
  • Members
  • 2 posts
  • Last active: Apr 02 2011 04:12 PM
  • Joined: 02 Apr 2011
Ok, well let's just pretend that Run cmd is a long script (so that it's not shorter to do your 2nd example).

#IfWinActive ahk_class Progman
#c::
#IfWinActive ahk_class WorkerW
#c::
Run cmd
return


Ahh, ok, I thought doing it this way would add scope, not replace it. In other words, I thought doing it this way would require the user to be over both windows. Guess this way is easy enough. There's no way to combine them into a single expression though, huh?

Thanks for the reply, it helps!

None
  • Members
  • 3199 posts
  • Last active: Nov 05 2015 09:55 PM
  • Joined: 28 Nov 2009
Ahk_l supports #If (expresion)
#If WinActive("ahk_class Progman") || WinActive("ahk_class WorkerW")
#c::Run cmd
Or (this works in basic)
GroupAdd, GroupName, ahk_class Progman
GroupAdd, GroupName, ahk_class WorkerW
#IfWinActive ahk_group GroupName
#c::Run cmd


parkour86
  • Members
  • 19 posts
  • Last active: Jul 10 2015 06:15 AM
  • Joined: 01 Sep 2010

I know this topic is old but searching google this was the first result it found. The way I got it working was like this:

#IfWinActive ahk_class Progman || ahk_class WorkerW


Oldman
  • Members
  • 2475 posts
  • Last active: Feb 18 2015 04:57 PM
  • Joined: 01 Dec 2013

 

I know this topic is old but searching google this was the first result it found. The way I got it working was like this:

#IfWinActive ahk_class Progman || ahk_class WorkerW

 

Are you sure it works for the Progman class ?


Si ton labeur est dur et que tes résultats sont minces, souviens toi du grand chêne qui avant n'était qu'un gland....comme toi ! (anonyme) ;)

L'art de lire, c'est l'art de penser avec un peu d'aide. (É. Faguet)

Windows 3.1. Collector's Edition.     (www.avaaz.org)


Aquinax
  • Members
  • 9 posts
  • Last active: Jun 18 2016 01:13 PM
  • Joined: 19 Oct 2012

#IfWinActive ahk_class Progman || ahk_class WorkerW

Thanks parkour86, this - the || handle - worked fine for me. I used it in the 'IfWinActive' statement with Notepad++ and WinWord.

IfWinActive, ahk_class TFormPowerGREP || ahk_class  OpusApp


Synetech
  • Members
  • 26 posts
  • Last active: Oct 05 2015 09:34 PM
  • Joined: 03 May 2013

 

Thanks parkour86, this - the || handle - worked fine for me. I used it in the 'IfWinActive' statement with Notepad++ and WinWord.

IfWinActive, ahk_class TFormPowerGREP || ahk_class  OpusApp

 

Are you sure it worked? When I tested it, it only worked for the second class, not the first.