Autohotkey : Wildcard ahk_class match - autohotkey

I used winspy to grab an ahk_class for my autohotkey macro. Sometimes that application has 2+ ahk_classes associated with that program
Example:
HwndWrapper[program.exe;;1111-1111]
HwndWrapper[program.exe;;2222-2222]
How can I use winNotExist to simply just match both names? Or perhaps use a ||, OR etc?
E.g.
F12::
IfWinNotExist, ahk_class "HwndWrapper.+"
Run, AQ8.exe
GroupAdd, kjexplorers11, ahk_class "HwndWrapper.+" ;You have to make a new group for each application, don't use the same one for all of them!
if WinActive("ahk_exe AQ8.exe")
GroupActivate, kjexplorers11, r
else
WinActivate ahk_class ahk_class "HwndWrapper.+" ;you have to use WinActivatebottom if you didn't create a window group.
Return

I finally figured it out. SetTitleMatchMode, Regex.
This command affects the behavior of all windowing commands, e.g. WinExist and WinActivate
Then write some javascript-like regex statements as arguments.
The full list of window commands is on AHK site
Script, revised
F12::
SetTitleMatchMode,RegEx
IfWinNotExist, ahk_class HwndWrapper.+
Run, AQ8.exe
GroupAdd, kjexplorers11, ahk_class HwndWrapper.+ ;You have to make a new group for each application, don't use the same one for all of them!
if WinActive("ahk_exe AQ8.exe")
GroupActivate, kjexplorers11, r
else
WinActivate ahk_class ahk_class HwndWrapper.+ ;you have to use WinActivatebottom if you didn't create a window group.
Return
So now I can cycle through any application with more than 1 ahk_Class name. Example of what script does

Related

User Accounts window doesn't allow any hotkey

I want to create a hotkey when ahk_class #32770 windows are active, in my case, the User Accounts window opened by typing netplwiz in the Run. But, it seems that no hotkey works.
Here's what I did:
#NoEnv
#Warn
SendMode Input
SetWorkingDir %A_ScriptDir%
SetTitleMatchMode, 2 ; A window's title can contain WinTitle anywhere inside it to be a match.
#ifwinactive
#e::Run,%A_AppData%\Microsoft\Windows\Recent
;this doesn't work for ahk_class #32770, so I make the following workaround:
#if winactive("ahk_class #32770") or winactive("ahk_exe explorer.exe")
#e::Run,%A_AppData%\Microsoft\Windows\Recent
;but neither does this work. So I made the following test:
^p::msgbox,hi
;and it doesn't work.
Did I do something wrong, or any workaround?
It should work. End/Close the context with
#if or #ifwinactive as appropriate, if you have not.
Like in
#ifwinactive ahk_class #32770
#e::Run,%A_AppData%\Microsoft\Windows\Recent
#ifwinactive
#if winactive("ahk_class #32770")
#e::Run,%A_AppData%\Microsoft\Windows\Recent
#if

Activate Windows File Explroer

I thought this was easy but it seems not. I just want to activate File Explorer this way:
WinActivate ahk_exe Explorer.EXE
But it won't work. It seems that all others work just fine:
WinActivate ahk_exe chrome.exe ; works
WinActivate ahk_exe notepad++.exe ; works
WinActivate ahk_exe OUTLOOK.EXE ; works
I also tried
WinActivate "ahk_class CabinetWClass"
The second approach works, but you shouldn't use quotes. Try this:
WinActivate ahk_class CabinetWClass
You can also make it an expression and then you must use quotes, like this:
WinActivate % "ahk_class CabinetWClass"

autohotkey to focus / open on google chromium

I have this autohotkey script that opens chrome if its not already on windows, and if it is, cycles through tabs within it. It also puts that chrome window on top of any other windows (e.g. excel docs, word docs, etc)
IfWinNotExist, ahk_class Chrome_WidgetWin_1
Run, chrome.exe
if WinActive("ahk_class Chrome_WidgetWin_1")
Send ^{tab}
else
WinActivate ahk_class Chrome_WidgetWin_1
Return
I can't seem to figure out how to get this to work for google chromium though. Both exe names are "chrome.exe", so I'm not sure what the run commands is if there's an overlap.
Also, I ran winSpy but still am not 100% sure what ahk_class name is. Below is the information from winSpy
I ended up settling for a different solution
After 2 days of tweaking and testing some workflows, this is what I settled with. I ran a combination of both phrase-express (any macro program works here) and autohotkey here, so I can have an extremely flexible layout
F1 → Binded to WIN+1 key
F2 → Binded to WIN+2 key
F3 → Binded to Win+4 key
F4 → Binded to Win+4 key
For F5 to F7 keys, I used autohotkey
F5::
IfWinNotExist, ahk_class Chrome_WidgetWin_1
Run, chrome.exe
GroupAdd, kjexplorers5, ahk_class Chrome_WidgetWin_1 ;You have to make a new group for each application, don't use the same one for all of them!
if WinActive("ahk_exe chrome.exe")
GroupActivate, kjexplorers5, r
else
WinActivate ahk_class Chrome_WidgetWin_1 ;you have to use WinActivatebottom if you didn't create a window group.
Return
F6::
IfWinNotExist, ahk_class ConsoleWindowClass
Run, cmd.exe
GroupAdd, kjexplorers6, ahk_class ConsoleWindowClass ;You have to make a new group for each application, don't use the same one for all of them!
if WinActive("ahk_exe cmd.exe")
GroupActivate, kjexplorers6, r
else
WinActivate ahk_class ConsoleWindowClass ;you have to use WinActivatebottom if you didn't create a window group.
Return
F7::
IfWinNotExist, ahk_class QWidget
Run, anki.exe
GroupAdd, kjexplorers7, ahk_class QWidget ;You have to make a new group for each application, don't use the same one for all of them!
if WinActive("ahk_exe anki.exe")
GroupActivate, kjexplorers7, r
else
WinActivate ahk_class QWidget ;you have to use WinActivatebottom if you didn't create a window group.
Return
F5 to F7 uses the same variant autohotkey, I just changed up the groupnames, the .exe files , and the ahk_class names.
This is how I organize the structure of my windows taskbar
So I press
F5 (3 times), and it pushes each chrome window I have up to the top of each of my 3 monitors.
F6 and I can quickly pop out whatever command prompts I have open, one command prompt for gulp commands, and one for git, independent of any IDE.
F7 twice to quickly add some new flashcards
I can restructure F1 F2 F3 F4 to whatever app I'm currently using. Anything that goes here I only keep one window per app at a time. Like I only run one firefox window (to watch tutorial youtube videos), only one running application of PHPstorm, etc.
Demonstration of F6 key in action (command prompt)

Solution to a "dynamic"/"unstable" ahk_class name?

In AutoHotKey, ahk_class NAME has been a good identifier for programs. Typically, I now use it in the following two ways:
Simply calling the most recently called active instance:
; Pressing Win+Shift+X will bring up (or switch to) the Windows Journal
Application
#+x::
IfWinExist ahk_class JournalApp
WinActivate ahk_class JournalApp
else
Run C:\Program Files\Windows Journal\Journal.exe
return
Grouping windows with the same ahk_class and looping through them:
GroupAdd, FIRE, ahk_class MozillaWindowClass
; Pressing Win+3 will go through all open Firefox windows one by one.
#3::
IfWinExist ahk_class MozillaWindowClass
GroupActivate, FIRE, r
else
Run firefox
return
However, there are certain programs that do not have a stable ahk_class name. For example, the ArcMap.exe should
display the following information in the "Windows Spy" window of AHK:
>>>>>>>>>>( Window Title & Class )<<<<<<<<<<<
Untitled - ArcMap
ahk_class Afx:012F0000:b:00010003:00000006:001C0BB0
Any idea how could I refer to this application that has dynamic ahk_class?
I am aware that there is also something called ahk_exe. However, I did not find it compatible with the method GroupAdd,
GroupActivate or IfWinExist.
You definitely are on the right track trying to incorporate ahk_exe. GroupAdd (and every other command receiving a WinTitle parameter at that) is compatible with ahk_exe in AHK_L; this sample code works perfectly on my machine:
GroupAdd, notepad, ahk_exe notepad.exe
Run, notepad.exe
WinWaitActive, ahk_group notepad
Sleep, 1000
WinClose, ahk_group notepad
I suspect you're not using the most recent version of AHK. Get it here and have another try.

executing a script when at a specific classNN

How shouuld I tweak the following script so that the hotkey is activated not at ANY moment where I'm at the class shown (that is Outlook) but at a specific sub window ( the preview pane of the Inbox box (whose classNN is _WwG1 )) ?
#IfWinActive ahk_class rctrl_renwnd32
+!m::
ControlFocus, OutlookGrid1, ahk_class rctrl_renwnd32
if ErrorLevel ; i.e. it's not blank or zero.
MsgBox, You don't seem to be in context.
return
#IfWinActive
Make the hotkey look for active controls once it is activated. This way you can use the same hotkey for multiple commands, each command depending on the control. You can do this with several if/else statements to test for the subcontrols.
The hotkey only works in Outlook.
Each control has its own command
Each command is limited to that particular control
#ifwinactive, ahk_exe outlook.exe
{
+!m::
controlgetfocus, thiscontrol
if(thiscontrol = "_Wwg1"){
ControlFocus, OutlookGrid1, ahk_class rctrl_renwnd32
if ErrorLevel ; i.e. it's not blank or zero.
MsgBox, You seem to focused on %thiscontrol%
}else if(thiscontrol = "_Wsg2){
msgbox, you've discovered the second control!
}
return
}