• Become a Power user Intro to AutoHotkey Intermediate AutoHotkey Intermediate Objects GUIs are Easy w/AutoHotkey Painlessly switch from V1 to V2

Choosing the Right Way to Identify Windows in AutoHotkey

Hey there, fellow automation enthusiasts! Today, we’re diving into the wild world of AutoHotkey and exploring the different ways you can identify windows and programs. Don’t worry if you’re not a coding wizard – I’ll break it down in a way that’ll make you feel like a pro in no time.

Why Does This Even Matter?

Before we jump in, let’s talk about why identifying windows is such a big deal in AutoHotkey.

Imagine you’re trying to automate your daily grind – maybe you want to automatically organize your work files, or set up a shortcut to launch your favorite apps.

To do any of this cool stuff, AutoHotkey needs to know which window or program you’re talking about.

It’s like giving directions to a friend – you need to be specific, or they might end up at the wrong place!

The Fantastic Four: PID, HWND, AHK_class, and AHK_exe

AutoHotkey gives us four main ways to identify windows and programs. Think of them as different superpowers you can use to point at the exact window you want to control. Let’s break them down:

1. PID: The Unique ID Badge

PID stands for Process ID. Imagine every program running on your computer has a unique employee badge. That’s what a PID is – a unique number assigned to each running program.

When to use PID:

  • You need to target a specific instance of a program
  • You’re dealing with multiple instances of the same program and need to pick one

PID Pros:

  • Super specific – each PID is unique
  • Great for differentiating between multiple instances of the same program

PID Cons:

  • PIDs change each time you run a program, so your script might need updating

Learn more about using PIDs in the AutoHotkey documentation.

2. HWND: The Window’s Secret Codename

HWND (pronounced “H-wind”) stands for Handle to Window. If PID is like an employee badge, HWND is like a secret codename for each window. Every window gets its own HWND.

When to use HWND:

  • You need to target a specific window, not just a program
  • You’re working with complex applications that have multiple windows

HWND Pros:

  • Very precise – each window has its own HWND
  • Useful for applications with multiple windows

HWND Cons:

  • Like PIDs, HWNDs change each time a window is created
  • Can be overkill for simple scripts

Discover more about HWNDs in the AutoHotkey HWND documentation.

3. AHK_class: The Window’s Family Name

AHK_class is like a family name for windows. All windows created by the same type of program often share the same class name.

When to use AHK_class:

  • You want to target all windows of a certain type
  • You’re working with standard Windows applications

AHK_class Pros:

  • More stable than PIDs or HWNDs – doesn’t change between program launches
  • Can target multiple windows of the same type easily

AHK_class Cons:

  • May be too broad if you need to target a specific window
  • Some programs use generic class names, which can lead to confusion

Find out more about AHK_class in the AutoHotkey class documentation.

4. AHK_exe: The Program’s Name Tag

AHK_exe is probably the simplest to understand – it’s just the name of the program’s executable file (like “chrome.exe” for Google Chrome).

When to use AHK_exe:

  • You want to target all instances of a specific program
  • You’re writing simple scripts for well-known applications

AHK_exe Pros:

  • Super easy to use and understand
  • Doesn’t change unless the program is renamed or moved

AHK_exe Cons:

  • Can be too broad if you need to target a specific window
  • Might not work well with programs that have multiple executables (but you can use GroupAdd to help with this)

Learn how to use AHK_exe in the AutoHotkey executable documentation.

Choosing Your Superpower

So, how do you decide which method to use? Here’s a simple guide:

  1. If you’re just starting out or writing a simple script, go with AHK_exe. It’s the easiest to understand and use.
  2. If you need to target all windows of a certain type (like all Notepad windows), AHK_class is your friend.
  3. If you’re dealing with a complex application and need to target a specific window, HWND is the way to go.
  4. If you need to differentiate between multiple instances of the same program, PID is your best bet.

Remember, you can often combine these methods for even more precision. For example, you might use AHK_exe to target a specific program, and then use HWND to pick out a particular window within that program.

Real-World Examples

Let’s look at some everyday scenarios to see how you might choose between these methods:

  1. Scenario: You want to create a hotkey that always brings up your work email.
    Solution: Use AHK_exe to target your email client (e.g., “outlook.exe”).
  2. Scenario: You’re working with multiple Chrome windows and want to focus on a specific one.
    Solution: Use HWND to target the exact window you need.
  3. Scenario: You want to create a script that works with all open Notepad windows.
    Solution: Use AHK_class to target all Notepad windows at once.
  4. Scenario: You’re running two instances of a game and want to automate actions in one of them.
    Solution: Use PID to differentiate between the two instances.

Mixing and Matching: The Power Combo

Now, here’s where things get really exciting: you can mix and match these window identification methods! This is like combining superpowers to become the ultimate AutoHotkey hero. Let’s dive into how you can do this, with a special focus on combining ahk_exe and ahk_class.

Why Mix and Match?

Sometimes, using just one method isn’t enough to pinpoint exactly the window you want. By combining methods, you can be super specific and avoid any confusion in your scripts.

The Dynamic Duo: ahk_exe and ahk_class

The combination of ahk_exe and ahk_class is particularly powerful. Here’s why:

  • ahk_exe narrows down to a specific program
  • ahk_class helps you target a specific type of window within that program

For example, let’s say you’re working with Microsoft Word and want to target only the document windows, not the splash screen or dialog boxes. You could use:

ahk_exe winword.exe ahk_class OpusApp

This tells AutoHotkey: “Find me a window that belongs to Microsoft Word (winword.exe) and is a document window (OpusApp class).”

More Mixing Examples

  1. Chrome with a specific title:
    ahk_exe chrome.exe ahk_class Chrome_WidgetWin_1 MySpecificTabTitle
    This targets a Chrome window with a specific tab title.
  2. Notepad with specific content:
    ahk_exe notepad.exe ahk_class Notepad MySpecificTextContent
    This looks for a Notepad window containing specific text.
  3. File Explorer in a specific location:
    ahk_exe explorer.exe ahk_class CabinetWClass C:\MyFolder\
    This targets a File Explorer window open to a specific folder.

Tips for Mixing and Matching

  • Start broad, then narrow down: Begin with ahk_exe to select the right program, then use ahk_class or other identifiers to be more specific.
  • Use Window Spy: AutoHotkey comes with a tool called Window Spy that can help you identify the correct ahk_exe and ahk_class for any window. You can access it by right-clicking on the AutoHotkey icon in your system tray and selecting “Window Spy”.  Or get the-Automator Spy which is our version but jazzed-up!
  • Test, test, test: Always test your combined identifiers to make sure they’re targeting exactly what you want.
  • Be as specific as necessary: Only add as many identifiers as you need to uniquely identify your target window. Too many can make your script brittle.

Remember, you’re not limited to just combining ahk_exe and ahk_class.

You can mix and match any of the window identification methods we’ve discussed. The key is to experiment and find the combination that works best for your specific automation needs.

For more detailed information on combining window identification methods, check out the AutoHotkey documentation on combining criteria.

Wrapping Up

Choosing the right method to identify windows in AutoHotkey is like picking the right tool for a job. Sometimes a hammer (AHK_exe) is all you need, but other times you might need a more specialized tool (like HWND or PID).

Don’t be afraid to experiment with different methods. The more you play around with AutoHotkey, the better you’ll get at choosing the right identification method for each task. Before you know it, you’ll be an AutoHotkey window-whisperer, commanding your computer to do your bidding with just a few lines of code.

Remember, the goal is to make your life easier and your work more efficient. So go forth, my fellow automation adventurer, and may your scripts be ever bug-free and your windows always identifiable!

Happy scripting!

For more information and tutorials, check out the official AutoHotkey documentation.

AutoHotkey News 2024-06-27- Claude is King❗

Howdy,

Back in early 2023, Chat GPT 3.5 was taking off, we tried getting AutoHotkey v2 code out of it however, after lots of prompting, it just wasn’t going to happen.

I was confident that, given some time, we’d be able to use AI for writing v2 code.

Then, over the last year, Chat GPT kept upgrading it’s models and others like Bard/Gemini, Perplexity, Claude, joined in I was sure we could get reliable v2 code.

Sadly that was not the case.

No matter what prompt we provided, it would never offer up valid v2 code.  And this has remained the case for the past year.

Well that’s just changed !

Late Monday night I was watching videos Claude’s new Sonnet model and that it was better than Chat GPT 4.o.  One thing in particular was that it was “very good at programming”.

So I made a reminder on my calendar to test if Claude could provide AutoHotkey v2 code.

Because GUIs are objects in v2, but commands in v1, it’s my “go to” example to quickly check if a model is providing me with v1 or v2 code.   Sure enough, not only did it provide me with v2 code but, more importantly, it provided WORKING v2 Code that did exactly what I asked (and more!)

Also, Claude created a new feature called an “ artifact ”.  If you go to your Claude settings à “Feature Preview” you can enable “artifacts” and you can get your suggested code in a separate window (see below however it is now located on bottom left of screen)

Amazingly you can access the Sonnet model without having a paid plain (although they do limit your prompts.  Apparently paying customers get 5X the amount of questions for $20 a month)

I’m pretty sure we’ll be getting valid v2 code out of the other AI models in the future however I’m just so excited we finally have one that really helps us now.   This means our clients will get even more from our done-for-you work and tutoring sessions!

To celebrate this monumental event I’m putting two of our classes on sale!   The first 5 people to purchase either course below save 50% on their purchase

Don’t forget, our courses come with a Double your money back Guarantee!

Now on with the show…

Learn how to Master VSCode Make the switch to v2 Intro to AutoHotkey Intermediate AutoHotkey Intermediate Objects GUIs are Easy w/AutoHotkey Access all our Courses; Quit when you want

Tips for using Claude to write your AutoHotkey code

Last week we released two videos.  The first one was really just an announcement that the Sonnet model from Claude was writing valid v2 code.   The second one we showed a few cool features of Claude that you’ll want to use/enable.

Tips on Using Claude to write AutoHotkey code
Tips on Using Claude to write AutoHotkey code


Updating our Voice Access GUI

While we were developing our Voice Access GUI, Irfan and I were realizing something wasn’t quite right.  We decided to hold off until our inhouse GUI Wizard (Isaias) was available.  I decided to record the session in case there were some learnings and, not surprisingly, there were.  You can get some good GUI tips by watching this video.

Updating the GUI of our Voice Access Script / the-Automator Team Meeting
Updating the GUI of our Voice Access Script / the-Automator Team Meeting


Adding a CoPilot key

I recently read that the built-in Windows 11 hotkey for pulling up Copilot (Win+C) is going away.  Apparently the plan is to have Copilot entangled in the Taskbar.  ☹

In this video I show how you can use AutoHotkey to add a “Copilot” key which remaps the Win+Shift+{F23} key.  Hopefully this will still work after they remove the above functionality but no promises.

How to Create your own CoPilot Hotkey without buying a new Keyboard
How to Create your own CoPilot Hotkey without buying a new Keyboard


Improving People’s Lives: Story #5 Exploding a Radiologist’s Productivity

One of our Radiologist mentioned that 70 billable units is the norm for his industry and 80 is considered burn-out.
Before working with us 101 was his highest he’d ever achieved.  After working with us he hit a new high of 140!
He literally did double what others are doing without sacrificing quality or getting burned-out.


What we’re reading


AI / Chat GPT-3 News / Usage

What Is an AI Anyway? | Mustafa Suleyman | TED
What Is an AI Anyway? | Mustafa Suleyman | TED


⚡️Productivity tips: Embrace AI

If you’re one of those people that are putting your head in the sand regarding AI advancement, I understand many of your fears however:

AI is Here and Changing the World Faster Than Ever!

The world is filled with examples where entire populations of people were devastated by not “keeping up”  (China during 15th to 19th Century, Japan 1603-1868, Islamic World 16th to 19th century).   Each of these cultures were at he forefront then decided to isolate themselves only to later pay enormous prices.

I’ve known many people that make a contious decision to “stop learning”.  Sooner or later they end up severly regretting that decision!


A spot of Humor

This video from Columbo is even funnier when we consider where AI is these days!

Are you using AutoHotkey wrong?
Are you using AutoHotkey wrong?


What we utomated this week with AutoHotkey #50

This was a “light week” as Irfan and Rizwan were out most of it.  We only worked on 29 AutoHotkey scripts!  I walk through them in this video.

What we automated with AutoHotkey #50
What we automated with AutoHotkey #50


Testimonial

With The-Automator, I learned to use AutoHotkey, in order to automate otherwise tedious and repetitive tasks.

Thanks to Joe Glines and all his guests, I am now able to automate boring tasks, “if only my mower could respond to AutoHotkey”.  — Claude P.


AHK Hero

Consider joining the AHK Hero club! Members receive 25% off courses, consultations, tutoring, done for you project work, etc.    Currently we have over 276 hours of recordings teaching AutoHotkey that is exclusive to AHK Hero members❗

During this Friday’s call we’re planning to discuss:

  • Having hidden icons in scripts- ability to “toggle” their visibilty
  • Running Scripts as UI Access (instead of Admin)
  • Voice Access / Voice Shortcuts
  • Listviews: Selecting & getting values

They also have access to exclusive & pre-released content and a 3 hours a week where we help people with their AHK issues (the Saturday calls are geared towards people new to AutoHotkey.)


️ Quotable quotes

  • Find & hire people that are over-performing in crappy jobs Dan Kennedy
  • S.Y.S.T.E.M. Save Your Self Time Energy & Money
  • If you think education is expensive, try ignorance — Derek Bok

AHK Newsletter⏩SHARE WITH A FRIEND⏩

Do you know someone that would benefit from learning useful automation tips like the gems in today’s issue?  Take a second and forward this newsletter and bask in the glow of their undying gratitude.  Was this email forwarded to you?

Sign up for this Newsletter hereWe never share your email with anyone.  Ever!


The-Automator

Joe, Isaias, Irfan, Rizwan and staff


P.S. With v1 being deprecated, and not expecting any updates, I highly encourage you to switch to v2.

Our v1 to v2 course helps make the transition painless!  If you act now with this link you’ll probably be one of the first 5 to purchase which means you’ll save 50%!

How to get Valid AutoHotkey v2 code out of AI tools like Chat GPT, Claude, Bard, etc.

As usual I was watching a lot of videos on AI.  One that caught my eye was the recent upgrade to Claude.   Sonnet is testing very high so I decided to give it a try.

Sure enough, it was providing Valid AutoHotkey V2 code right out of the box!
In the below video we demonstrate this and provide some additional tips on how to get better answers from AI tools.

While Sonnet from Claude is the only tool we know of that writes solid AHK V2 code, I do think Chat GPT & others will be doing the same very soon!

How to get AI to provide solid AutoHotkey V2 code

How to get AI to provide solid AutoHotkey V2 code orig