0
votes

I am new to AHK and would like to find the number of windows of a certain program open at any time and store that in a variable.

I have a script that opens an Opera window when I press the caps lock key, but I would only like three of these windows open at any one time, so when there are more than three Opera windows open and I press the caps lock key it does nothing.

I would also like the caps lock button never to capitalise text (in other words, to have caps lock state always off)

How do I do this?

1

1 Answers

1
votes

You can use WinGet with the Count operation (see docs) to get the number of windows matching a certain filter.

You need to find the right filter of course. You can use the Window Spy utility for that which comes with AutoHotkey.

In this case I already did it: You'll see that the window class (ahk_class) of the Opera windows is Chrome_WidgetWin_1. However, this would be true for Chrome, Chromium, etc. as well, so we further have to filter for the program EXE filename (ahk_exe) of opera.exe. (The reason we don't just filter by ahk_exe is that we don't want to include things like an "there are updates available" box or whatever other non-main window Opera may have open, I guess.)

The final result is:

WinGet cnt, Count, ahk_exe opera.exe ahk_class Chrome_WidgetWin_1
MsgBox There are %cnt% Opera windows open