![Photo](https://secure.gravatar.com/avatar/f6019c48fc1cec3f2a076560d0ec1467?s=100&d=%2F%2Fwww.autohotkey.com%2Fboard%2Fpublic%2Fstyle_images%2Fortem%2Fprofile%2Fdefault_large.png)
Using the same #IfWinActive for multiple windows
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!
![Using the same #IfWinActive for multiple windows: post #1](http://www.autohotkey.com/board/public/style_images/ortem/icon_share.png)
#IfWinActive ahk_class Progman #c:: #IfWinActive ahk_class WorkerW #c:: Run cmd return
Although this is actually longer thanTo 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.
#IfWinActive ahk_class Progman #c::run cmd #IfWinActive ahk_class WorkerW #c::run cmd #IfWinActive ; <<<< Optional
![Using the same #IfWinActive for multiple windows: post #2](http://www.autohotkey.com/board/public/style_images/ortem/icon_share.png)
#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!
![Using the same #IfWinActive for multiple windows: post #3](http://www.autohotkey.com/board/public/style_images/ortem/icon_share.png)
#If WinActive("ahk_class Progman") || WinActive("ahk_class WorkerW") #c::Run cmdOr (this works in basic)
GroupAdd, GroupName, ahk_class Progman GroupAdd, GroupName, ahk_class WorkerW #IfWinActive ahk_group GroupName #c::Run cmd
![Using the same #IfWinActive for multiple windows: post #4](http://www.autohotkey.com/board/public/style_images/ortem/icon_share.png)
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
![Using the same #IfWinActive for multiple windows: post #5](http://www.autohotkey.com/board/public/style_images/ortem/icon_share.png)
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 ?
![Using the same #IfWinActive for multiple windows: post #6](http://www.autohotkey.com/board/public/style_images/ortem/icon_share.png)
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)
#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
![Using the same #IfWinActive for multiple windows: post #7](http://www.autohotkey.com/board/public/style_images/ortem/icon_share.png)
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.
![Using the same #IfWinActive for multiple windows: post #8](http://www.autohotkey.com/board/public/style_images/ortem/icon_share.png)