autohotkey to focus / open on google chromium - autohotkey

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)

Related

How to hold a modifier key so ahk sends keypresses to a different window

I'm pretty new to ahk.
Say I have two separate vlc windows open and playing videos.
If one of the vlc windows is active, then I want to be able to hold a key to make all keypresses go to the other vlc window.
ie if I press Left, then it sends Left to the active vlc window, but if I hold ALT+Left, then it sends Left to the other vlc window.
If no vlc window is active, then I don't want autohotkey to do anything.
This is so I can control two vlc windows without having to click and choose which one is active.
I looked up GroupAdd hoping I could use a group that includes both vlc windows, but couldn't find a way to target specific vlc windows from the group to send keys to it.
edit: I got a very basic version working, but I feel it's pretty ugly. I would like a way to send any key that's pressed if you hold Shift to the other vlc window. Also this seems a bit unreliable in switching focus if you use it a few times quickly in succession.
GroupAdd, vlcgroup, ahk_exe vlc.exe
return
#IfWinActive ahk_exe vlc.exe
+Left:: ; shift-left
GroupActivate, vlcgroup, r
Send {Left}
GroupActivate, vlcgroup, r
return
A simple approach could be done like this:
#IfWinActive, ahk_exe vlc.exe
+Left::
WinGet, WindowList, List, ahk_exe vlc.exe
BottomMostVlcHwnd := WindowList%WindowList%
ControlSend, , {Left}, % "ahk_id " BottomMostVlcHwnd
return
^+Left::
WinGet, WindowList, List, ahk_exe vlc.exe
BottomMostVlcHwnd := WindowList%WindowList%
ControlSend, , ^{Left}, % "ahk_id " BottomMostVlcHwnd
return
...
#IfWinActive
You'd write out each hotkey.
WinGet, , List(docs) returns a legacy pseudo-array(docs) of hwnds to Vlc windows.
The last element in that array will be the bottom most window.
You can get the last element of a pseudo array via a dynamic variable trick WindowList%WindowList%.
Essentially you're accessing a variable named WindowListN, where N is the number for the last element in the pseudo-array.
Then ControlSend(docs) is used to send keys to the background window without the need to activate it.
And you refer to the background window by a window name like ahk_id 0x1234567(docs).
Of course writing out the hotkey for each key is pretty repetitive, so we can do something much better:
#IfWinActive, ahk_exe vlc.exe
+Left::
^+Left::
+Right::
^+Right::
+PgUp::
+PgDn::
WinGet, WindowList, List, ahk_exe vlc.exe
ControlSend, , % StrReplace(A_ThisHotkey, "+", "{") "}", % "ahk_id " WindowList%WindowList%
return
#IfWinActive
The hotkey definitions are just stacked on top of each other.
(If there were even more definitions, a loop with the Hotkey(docs) command could be nicer)
A_ThisHotkey(docs) will contain the hotkey that was used, and StrReplace(docs) is used to automatically replace the + with a {.
And finally the closing brace } is appended to the end.

WinActivate on specific criteria (include / exclude windows)

I'm stumped on how to best re-write my hotkey. What I want to do is simple. I have a script that switches to File Explorer IF it's currently open Else it will open a new file explorer window.
Here's the catch - It's hard to "identify" if the Explorer window is open. I used to just do this by using WinActivate, 00123456 because that's the name of the folder (eight-digit random number). But the problem with that is that these are support ticket numbers. And that number will also be within the title of my current Chrome session and sometimes other windows too (Firefox, Snagit, notepad, etc). So it will inadvertently switch to those other programs. So that led me to exclude in this way:
Ticket_Out := clipboard
xclude:= Ticket_Out . " | Salesforce - Google Chrome"
WinActivate, % Ticket_Out, , % xclude
That's handy except for it only excludes 1 window at a time. How could I implement something that excludes a second application? OR --- another thought, how could I just say: look for Explorer.exe with window title "00123456" ?
You can use ahk_exe to filter by the process name too:
WinActivate, ahk_exe explorer.exe %Ticket_Out%
Another way would be to look for the window class - since depending on the Windows version Explorer can use either CabinetWClass or ExploreWClass, you can use a group, as shown in the docs:
; Define the group: Windows Explorer windows
GroupAdd, Explorer, ahk_class ExploreWClass ; Unused on Vista and later
GroupAdd, Explorer, ahk_class CabinetWClass
; Activate any window matching the above criteria and the title
WinActivate, ahk_group Explorer %Ticket_Out%
Note on CherryDT's answer the two WinActivate examples are missing a comma between the WinTitle, and WinText parameters...
Should be....
WinActivate, ahk_exe explorer.exe, %Ticket_Out%
Second example (when using GroupAdd)
WinActivate, ahk_group Explorer, %Ticket_Out%
Caught me out for awhile.
(I would comment on the answer, but as a new user don't have 50 reputation)

How to find OneNote windows 10 in AutoHotKey's if winexist?

I'm trying to build a script that allows me to open and use OneNote (The store app not OneNote 2016) with a hotkey, but I would like to use the same hotkey to switch the the app from another window. I have accomplished this with many other programs, but never with windows store app. Here is the code I'm trying to use.
#If WinExist("OneNote ahk_class ApplicationFrameWindow", "OneNote")
{
WinActivate,
}
Else
Run, C:\Users\ChrisCochrun\Documents\OneNote
#If
Unfortunately it's not detecting that the window exists and it'll only just launch a new instance of onenote. I've looked for answers, but I'm having trouble making it so that AHK actually sees the window already running and jumping to it.
Thanks very much for any help at all!
If the window's title doesn't start with "OneNote", you need to use
SetTitleMatchMode 2.
The #If-directive is only used for creating context-sensitive hotkeys and hotstrings.
F1:: ; or a hotkey of your choise
SetTitleMatchMode 2
If WinExist("OneNote ahk_class ApplicationFrameWindow", "OneNote")
WinActivate
Else
Run, C:\Users\ChrisCochrun\Documents\OneNote
return
rshfit::
SetTitleMatchMode 2
If WinExist("OneNote for Windows 10")
WinActivate return
;If I use rshift to activate Onenote for Windows 10

Autohotkey : Wildcard ahk_class match

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

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.