Shortcut for "audio inserts" tab of tracks connected to instruments with one keystroke? (solved)


Doesn’t do anything ! I don’t know why

Does it have to do with where the a.png file is stored ?

Pressing the “v” key certainly does something… but not what’s intended

As long as the image is in the same folder as the script, AHK should find it.

I’m thinking perhaps the resolution between the image file and your actual screen differs. Try recreating the image file.
You could also check what the ErrorLevel is by:

if ErrorLevel
   MsgBox, ErrorLevel
   return

I am having an error actually when starting the script

Sorry,

if (ErrorLevel) {
   MsgBox, ErrorLevel
   return
} else {
   SetMouseDelay, 3
   SendEvent {Click %X%, %Y%, down}{click %XPos%, %YPos%, up}
   Sleep, 75
}

#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.

#IfWinActive ahk_exe Cubase12.exe
v::
Winactivate, Cubase Pro Project
MouseGetPos, XPos, YPos
ImageSearch, X, Y, -600, -250, -300, 4000, *30 a.png
if (ErrorLevel) {
MsgBox, ErrorLevel
return
} else {
SetMouseDelay, 3
SendEvent {Click %X%, %Y%, down}{click %XPos%, %YPos%, up}
Sleep, 75
}
else
SetMouseDelay, 3
SendEvent {Click %X%, %Y%, down}{click %XPos%, %YPos%, up}
Sleep, 75
return

Thanks for taking the time

Double check you code.
You need to pull some of the weight here yourself.

Where you went wrong

Didn’t noticed that redundancy sorry. I am like using 100% of my IQ for this as my skill for coding are subzero

Script launch normally now

When hitting the “v” key, I am having this error now

image

#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.

#IfWinActive ahk_exe Cubase12.exe
v::
Winactivate, Cubase Pro Project
MouseGetPos, XPos, YPos
ImageSearch, X, Y, -600, -250, -300, 4000, *30 a.png
if (ErrorLevel) {
MsgBox, ErrorLevel
return
} else {
SetMouseDelay, 3
SendEvent {Click %X%, %Y%, down}{click %XPos%, %YPos%, up}
Sleep, 75
}
return

This is too difficult a script to write for a first one.

There is a simpler though way to do this though, if you’re interested.

A Key Command Macro like this:

image

For this to work, the Instrument tab must be just above the midi inserts tab.

Open the gif below in a new tab or window to see it correctly.
alt-shift-t

If I hit every key commands individually, it works
If I group them into a macro, it only opens the audio inserts 1 time out of 5. Sometimes it goes “previous section” only once or twice

Yeah, it’s not dependable… I think this problem has been around since the intro of Instrument tracks, I suppose they need to change a ton of other things for it to work.

I am optimistic though.

Mouse clicking with ahk would work, the disadvantage is it will only work when the elements to be clicked are in static positions. For that reason it’s not really viable.

That’s not really true. The coordinates can be relative to either the screen or the parent window. Then, as in the above attempt, it should be possible to “find” the element you wish to click by searching using a reference image.
I think the reason it is not working for OP is that the reference image was made by another user and their screen resolution and/or scaling differs.

and interface color too.

As far as coordinates, if the tab order changes, the xy coords are no longer valid.

Anyway, there’s no practical way to deal with this.

1 Like

All good points.
I would have to say I agree, no practical way. Only impractical workarounds.

It has been fixed thanks to @mlib
If anyone wondering how to do that, here is a copy of the script

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
#SingleInstance force	; Only one instance of this script can run at a time
#Persistent	; Keep the script running

#IfWinActive ahk_exe Cubase12.exe						;Make sure this Hot Key only operates when a specific application is in focus
F7::																;This is the "Hot Key" or keyboard shortcut, followed by two colons
MouseGetPos, XPos, YPos										;Store the current mouse position so we can restore it later
ImageSearch, X, Y, 28, 450, 250, 1250, *30 a.png		;Get the coordinates for matching the image to the active window. The image should be located in the same folder as this script.
																	;The *20 part means that there can be a color variance of 20 in the RGB matching. We need this because the shading of the button
																	;changes slightly when the section is expanded.
X += 10															;The ImageSearch function returns the top left corner of the image match
Y += 10															;...so we add 10 pixels to get more in the center of the target
if (ErrorLevel) {												;If something went wrong...
	if (ErrorLevel = 1) {									;1=image was not found
		ToolTip, Image not found							;You can use a MsgBox instead or just comment out this if you don't care.
		SetTimer, RemoveToolTip, -1000					;Lets make sure we hide that tooltip after 1000ms (one second).
	} else if (ErrorLevel = 2) {							;Something else went wrong. Yikes!
		MsgBox, General fault
	}
	return														;End this function. (Does not exit the script itself.)
} else {															;If an image match was found...
	SetMouseDelay, 0											;A mouse delay of 0 makes the mouse cursor jump directly to the target
	Click, %X% %Y% 1											;Perform the actual mouse click. The 1 at the end is for a single click. (2=double click)
	Click, %XPos% %YPos% 0	}							;Return the cursor to the original position. Note how we use 0 here for no click!
}
return
#IfWinActive 

RemoveToolTip:													;This subroutine is only for hiding the Tooltip
ToolTip
return

Change F7 with the hotkey you want
Adjust the coordinates in the “ImageSearch, X, Y, 28, 450, 250, 1250” by your own by opening “Windows Spy” (right click on an autohotkey running script) and you want to use the “Screen Mouse position”