Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is ahk_class? How can I use it for window matching?

Tags:

autohotkey

The AutoHotkey Beginner Tutorial includes a sample script to demonstrate window specific hotkeys and hotstrings.

#IfWinActive ahk_class Notepad
::msg::You typed msg in Notepad
#IfWinActive

#IfWinActive untitled - Paint
::msg::You typed msg in MSPaint!
#IfWinActive

The second example is fairly self-explanatory: Check for a window named "untitled - Paint". It's the first example's use of ahk_class that has me confused.

I haven't been able to find any explanation of the variable in the AHK documentation. According to an AHK forum post, ahk_class is the name of a window as given by Windows Spy, the post didn't go into any more detail.

Would there be any difference between using ahk_class Notepad and Untitled - Notepad? Would the second example work if replaced with #IfWinActive ahk_class Paint?

What is ahk_class and how can I use it for window matching?

like image 719
Stevoisiak Avatar asked Aug 11 '17 19:08

Stevoisiak


People also ask

What is Ahk_class?

Ahk_class is the class that is given to you when you use the WindowSpy tool. This tool should be in the same folder as your AutoHotkey executable. Follow this answer to receive notifications.

How do I use an AutoHotkey window spy?

Meet Window SpyRun your empty script to have the AHK icon appear in the Windows tray. Right-click on it and choose Window Spy from the menu that pops up. Now, whenever you click on any other window, AutoHotkey's Window Spy will present you information about it.

How do I find my AHK window ID?

Re: How do i get a window id You can use https://autohotkey.com/docs/misc/WinTitle.htm to find the window info.

What is Ahk_exe?

ahk_exe (Process Name/Path) [v1. Use ahk_exe ProcessNameOrPath in WinTitle to identify a window belonging to any process with the given name or path. While the ahk_pid criterion is limited to one specific process, the ahk_exe criterion considers all processes with name or full path matching a given string.


1 Answers

From https://autohotkey.com/docs/misc/WinTitle.htm#ahk_class

A window class is a set of attributes that the system uses as a template to create a window. In other words, the class name of the window identifies what type of window it is.

In other words you can use it to identify windows of the same type, if you open notepad the title will be Untitled - Notepad if you save it to temp.txt the title will become temp - Notepad. ahk_class on the other hand will always remain Notepad.

The second example will work if you replace it with #IfWinActive ahk_class MSPaintApp because that's the class of mspaint.

Usually you find ahk_class using Window Spy and then use it in your scripts. If you don't have Window Spy you can use the following hotkey:

#1::WinGetClass, Clipboard, A ; Will copy the ahk_class of the Active Window to clipboard

After you found it you can use it in any place you can use window title for example instead of writing WinActivate, Untitled - Notepad you can write WinActivate, ahk_class Notepad.

like image 100
Oleg Avatar answered Oct 07 '22 21:10

Oleg