Can Vegas script send keyboard shortcuts or run a file?

cadudesun wrote on 6/23/2020, 7:35 AM

Hi,

 

a) Can Vegas script send keyboard shortcuts?

For instance:

Script 1: Send Ctrl+C

Script 2: Send Alt+C

Script 3: Send Shift+C

Script 4: Send Ctrl+Alt+C

I use AutoHotkey for sending shortcuts and interact with Vegas, but I would like to add in Vegas toolbar, through script, some keyboard shortcuts.

 

b) An alternative could be to run a file from Vegas script. Is it possible?

In that direction, I could simply set the Vegas script to run an AHK script.ahk file. 

For instance:

Run C:\Scripts\File.ahk

 

Thank you!

Comments

Marco. wrote on 6/23/2020, 7:41 AM

Imho, scripts can't send keystrokes, but scripts can run AHK files. I used that method in my Vegas2HandBrake workflow. Actually I used compiled AHK scripts, so that other users were able to use the method without the need to install AHK.

cadudesun wrote on 6/23/2020, 7:50 AM

Imho, scripts can't send keystrokes, but scripts can run AHK files.

@Marco.

Thanks for the prompt reply.

Could you please provide an example of a script syntax which runs a file?

Marco. wrote on 6/23/2020, 7:52 AM

I could later this day.

cadudesun wrote on 6/23/2020, 7:56 AM

Take your time. Thank you so much!

Marco. wrote on 6/23/2020, 8:18 AM

I just found it. In the Vegas Pro script I run a BAT command file:

import System;
import ScriptPortal.Vegas;
import System.IO;
import System.Diagnostics;
import System.Windows.Forms;

var cmd = "c:\\mb_script\\Enter.bat";
var start : Process = Process.Start(cmd);

And in that BAT file I run the compiled AHK script ("Enter.exe" in this case).

timeout /t 1 /nobreak
start "" "C:\mb_script\Enter.exe"
timeout /t 2 /nobreak

 

cadudesun wrote on 6/26/2020, 8:22 AM

Many thanks @Marco.

Just the first part of your script did the job, since I'm running the AHK script directly:

import System;

import ScriptPortal.Vegas;

import System.IO;

import System.Diagnostics;

import System.Windows.Forms;



var cmd = "C:\\Program Files\\VEGAS\\VEGAS Pro 17.0\\Script Menu\\AHKScript.exe";

var start : Process = Process.Start(cmd);

=> Do you know if it is possible to use an environment variable to refer directly to the script folder, without the need of stating the full path?

I'm storing both the AHKScript.exe and the VegasAHKScript.js that refers to the AHK one in the default Vegas "Script Menu" folder, in order I can add and access the scripts from the toolbar.

Since both related files are stored in the same folder, which is the default one, I was wondering if I could simplify the file path to make the scripts independent of the Vegas version that is explicit part of the default file path. Doing so, it wouldn't be necessary to update the file path for each different version of Vegas. 

Hypothetically, I'm looking for something like that:

var cmd = "\\%Script Menu%\\AHKScript.exe";

 

jetdv wrote on 6/26/2020, 9:24 AM

How about something like: Path.GetDirectoryName(ScriptFile)

var cmd = Path.Combine(Path.GetDirectoryName(ScriptFile),"AHKScript.exe")

cadudesun wrote on 6/26/2020, 9:41 AM

How about something like: Path.GetDirectoryName(ScriptFile)

var cmd = Path.Combine(Path.GetDirectoryName(ScriptFile),"AHKScript.exe")

Many thanks for the prompt reply @jetdv 👍

It worked!

For reference, here the full script syntax improved for working with any version of Vegas:

import System;

import ScriptPortal.Vegas;

import System.IO;

import System.Diagnostics;

import System.Windows.Forms;



var cmd = Path.Combine(Path.GetDirectoryName(ScriptFile),"AHKScript.exe");

var start : Process = Process.Start(cmd);

 

Marco. wrote on 6/26/2020, 9:52 AM

Now we all are curious what's in your AHK script …

jetdv wrote on 6/26/2020, 10:12 AM

And you could shorten it further to a single line:

var start : Process = Process.Start(Path.Combine(Path.GetDirectoryName(ScriptFile),"AHKScript.exe"));

cadudesun wrote on 6/26/2020, 3:09 PM

@jetdv

Wow. Now the script is neater yet. Tested and working 👍

import System;

import ScriptPortal.Vegas;

import System.IO;

import System.Diagnostics;

import System.Windows.Forms;



var start : Process = Process.Start(Path.Combine(Path.GetDirectoryName(ScriptFile),"AHKScript.exe"));

@Marco.

Now we all are curious what's in your AHK script …

I'm working on scrips, for instance to:

- show the properties for media/events directly, without the need of the context menu.

- open media in trimmer or select timeline events from the ProjectMedia/Explorer interfaces (for which there is no command available for shortcut customization).

- access directly the fade types.

- add the right amount of pitch compensation when speeding up/slowing down the playback using the JogFoward/JogReverse for clearer listening the speech (I edit video for educational purposes, mainly interviews). It would be simpler if Vegas just playbacks like Premiere when the speed rate is changed, adjusting the pitch automatically. Since we are in the digital times, I see no point in Vegas emulating analog tapes when using JogFoward/JogReverse, JKL, scrubbing...

... and eventually other functionalities that I'm just starting to think about now that I got from this thread the information to interconnect Vegas and AHK scripts. Thanks, all of you for the directions!

I guess that Vegas API Script provides those functionalities natively, but I'm not familiar with it yet. So for now, it's easier for me to find out workarounds using AHK.

Soon I'm going to share with the community the scripts that come to work properly.

Cheers.

Glyn-D wrote on 7/22/2020, 10:21 AM

Hi all, just wondering how I can use Process.Start in C# code please? Been digging through the API and help pages I downloaded and can't find an example anywhere.

Got the path to my Executable by the following

string scriptDirectory = Path.GetDirectoryName(ScriptPortal.Vegas.Script.File);
string AHK_TC_CP = "AHK_TC_CP.exe";
myEXE = scriptDirectory + "\\" + AHK_TC_CP;

Thanks in advance :)

jetdv wrote on 7/22/2020, 3:44 PM

You need this at the top:

        using System.Diagnostics;

Then just do it the same as above:

Process.Start(myEXE);

For MANY more details, see here:

https://www.dotnetperls.com/process