I am writing a script for Session Guitarist, a VST control that goes into a DAW music application. I'm using Reaper.
The most sure fire way to check the identity of the window is to do an image search based on the word "Session Guitarist". After this I have about 12 keystrokes I need to code for to allow the strumming pattern of the guitar to be selected via the keyboard.
I hope it is okay to quote my script below. It isn't working as I want currently and I think it is because I don't understand the control flow.
I want to do some tests before handling hot keys. I do two tests. One that the Sunburst logo file is present. Then I check this logo can be found. Only if these two pass would I then go on to handle hot keys.
I've put MsgBox commands in to tell me what happens. What appears to be happening is that the two tests run when I first start the script by hitting enter on the file from File Explorer as I get the message that the logo can't be found. This makes sense as the logo isn't in File Explorer.
When I navigate to the Sunburst window though and hit either one of my hotkeys, '1' or down cursor key,, it isn't telling me that the Sunburst logo is found or not. One of them should happen. So it looks like the two tests only get run the once. On reading about autoExec I thought the entire script was run every time it was called but perhaps the presence of the hot keys is making it a persistent script so the top section doesn't get run again?
So should I put the code I have at the top into a function and call this function in the code that handles each hot key?
sorry for the long winded message and the thinking as I go along bit.
Here is my code. Many thanks for any help,
Chessel
Code: Select all
; Script for keyboard access to Session Guitarist Electric Sunburst
; Test that the Sunburst logo file exists
IfNotExist, ElectricSunburstLogo.png
{
MsgBox Error: Your Sunburst logo file either doesn't exist or isn't in this location.
return
}
; Test the Sunburst window has the focus
ImageSearch, FoundX, FoundY, 0, 0, 2000, 1100, ElectricSunburstLogo.png
if (ErrorLevel = 2)
{
MsgBox Could not conduct the search for Sunburst logo.
return
}
else if (ErrorLevel = 1)
{
MsgBox Sunburst icon could not be found on the screen.
return
}
else
{
MsgBox The Sunburst icon was found at %FoundX%x%FoundY%.}
return
}
;Handle the 1 key being pressed which then shows pattern selection arrows for slot 1 (C1)
1::
ImageSearch, FoundX, FoundY, 0, 0, 2000, 1100, C1.png
if (ErrorLevel = 2)
{
MsgBox Could not conduct the search for C1 logo
return
}
else if (ErrorLevel = 1)
{
MsgBox C1 icon could not be found on the screen.
return
}
else
{
MsgBox The C1 icon was found at %FoundX%x%FoundY%.}
;Click, %FoundX% %FoundY%
}
Down::
ImageSearch, FoundX, FoundY, 0, 0, 2000, 1100, RightArrow.png
if (ErrorLevel = 2)
{
MsgBox Could not conduct the search for right arrow logo
return
}
else if (ErrorLevel = 1)
{
MsgBox Right arrow icon could not be found on the screen.
return
}
else
{
MsgBox The right arrow icon was found at %FoundX%x%FoundY%.}
;Click, %FoundX% %FoundY%
return
}
Esc::ExitApp ; Exit script with Escape key
return