Program Changes Class Names on each instance

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Michelle911
Posts: 4
Joined: 07 Sep 2018, 01:57

Program Changes Class Names on each instance

07 Sep 2018, 02:24

Hi guys,

First, please forgive my noob status :-L

I'm trying to make it so when I scroll the wheel on my mouse that Control is also held down, this is to simplify a zoom function in Ableton. I got that part ok, but when trying next to limit the 'Control Scroll' to the Ableton windows I find that I need to use a Class name instead of title because Abes has two windows, one window is named but the other is not, but both windows do share the same Class name.

I can Activate Ableton fine. I can WinGetClass fine. I can MgBox the Class name and it's correct, but I have something wrong after that that I can't figure out (been at this for a few hours now experimenting and reading these forums and the docs to no avail)

So here' what I have :

Code: Select all

SetTitleMatchMode,  2
WinGetClass, class, Ableton Live 10 Suite

MsgBox, Ableton's class is "%class%"

#IfWinActive, class

WheelUp::
^WheelUp

WheelDown::
^WheelDown

I've tried putting the hotkeys in a Subroutine, didn't work.

I tried experimenting with the Return command after finding my Class, also didn't work.

I've tried using AHK_Class instead of just Class, that totally didn't work. :crazy:

that's about all I can do at this point. thanks for taking a look.
Michelle911
Posts: 4
Joined: 07 Sep 2018, 01:57

Re: Program Changes Class Names on each instance

07 Sep 2018, 21:06

I keep trying to get this right, I read in an old thread where Engunneer replied
you can't use variables in #IfWinActive...

You can however add a variable to a group (GroupAdd), then have #IfWinActive trigger on ahk_group GroupName, where GroupName is whatever you used in GroupAdd.
so that's a good clue but I'm still messing this up :cry: I've used autoit for a long time, not that great with it but maybe it's over complicating my thinking. AHK seems so much more.... non-verbose. I can make this work using window title, but I need to use Class to be able to target both of Ableton's windows.

Code: Select all

SetTitleMatchMode,  2
WinGetClass, class, Ableton Live 10 Suite

GroupAdd, abes, class

#IfWinActive, ahk_group abes
	{
		WheelUp::
		^WheelUp
		WheelDown::
		^WheelDown
	return
	}
#IfWinActive

User avatar
Masonjar13
Posts: 1555
Joined: 20 Jul 2014, 10:16
Location: Не Россия
Contact:

Re: Program Changes Class Names on each instance

07 Sep 2018, 21:21

So, first off, you don't need to dynamically get the class. If you're going to do that, might as well just use the window name. Window classes are static, so grab it with the (AHK install) included WindowSpy script. You can bypass the weirdness with #IfWinActive by not using it at all. Instead, use #If. Directives, though, do not have literal code blocks, making the curly brackets pointless.

Hotkeys either need to be one line, or they need a return. If it's one line, such as WheelUp::send ^{WheelUp}, it performs an auto-return for you. If it's on the next line, it will continue until it hits a return, which means that when WheelUp is activated, it will bleed into WheelDown.

^WheelUp also isn't a valid statement. You'll need to send it, as I did in the previous paragraph, as I don't think a remap will work properly (though I could be wrong). A remap would look like WheelUp::^WheelUp. Though, WheelUp may need to be in brackets still, I'm not sure.

Another problem is that the ^WheelUp might trigger the hotkey again, creating a loop. To avoid this, you'll need to tell it to use a hook. There's a few ways to do so, but the most common is to prefix the hotkeys with $.

Putting that all together:

Code: Select all

#if winActive("ahk_class classNameHere") ; all hotkeys below this line must pass this statement
$WheelUp::send ^{WheelUp}
$WheelDown::send ^{WheelDown}
#if ; all hotkeys below this are no longer required to meet any previous #if statements
If there are more windows with different classes, you could create a group or add another argument to the directive: #if winActive("ahk_class className1") || winActive("ahk_class className2") (|| is a logical "or")
OS: Windows 10 Pro | Editor: Notepad++
My Personal Function Library | Old Build - New Build
Michelle911
Posts: 4
Joined: 07 Sep 2018, 01:57

Re: Program Changes Class Names on each instance

07 Sep 2018, 21:42

I'm getting the Class name dynamically because it changes each time I load Ableton. Then I'm using the Class name because the Window Title also changes to reflect which project is currently loaded. I.E. the Window Title is always " [ProjectName] - Ableton Live 10 Suite "

I going to try and make this work with the other changes you suggest and report back.

Thanks very much
User avatar
Masonjar13
Posts: 1555
Joined: 20 Jul 2014, 10:16
Location: Не Россия
Contact:

Re: Program Changes Class Names on each instance

07 Sep 2018, 21:47

Interesting, haven't seen the class name change like that before. You could also use the process/executable name: #if winActive("ahk_exe Ableton.exe")
OS: Windows 10 Pro | Editor: Notepad++
My Personal Function Library | Old Build - New Build
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Program Changes Class Names on each instance

07 Sep 2018, 22:01

I might structure it like this. Cheers.

Code: Select all

#IfWinActive Constant Title ahk_exe MyExe.exe
q::
MsgBox, % "window with constant title"
return
#IfWinActive ahk_exe MyExe.exe
q::
MsgBox, % "other window from the same exe"
return
#IfWinActive
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Michelle911
Posts: 4
Joined: 07 Sep 2018, 01:57

Re: Program Changes Class Names on each instance

07 Sep 2018, 22:33

Yay! Got it working using the exe name :dance:

Didn't see this method mentioned in the docs, just glad it works!

Thank you so much

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 89 guests