Automating keyboard shortcuts with AutoHotKey

Hi folks, I’ve been experimenting with using SC in conjunction with AutoHotKey (open source keyboard macro prog) to automate some SC keyboard shortcuts. Took a little while to get the hang of it but I tell you what - this is COOL!
To make AHK work, you have to write a short script to get it to do what you want.
First, I wrote 4 AHK simple scripts to make it so if you press the numberpad keys 1 or 2, or 4 or 5 in SC you automatically get:
Key 1: go to previous event (eg beginning of clip) (same as SC shortcut Alt+left arrow);
Key 2: go to next event (eg end of clip) (same as SC shortcut Alt+right arrow);
Key 4: select previous clip (same as SC shortcut Ctrl+left arrow);
Key 5: select next clip (same as SC shortcut Ctrl+right arrow).
OK, this may seem nonsensical to some (replacing one shortcut with another) but it can increase the workflow by only having to press one shortcut key instead of two. And numbers “1,2” and “4,5” are logically positioned next to each other.

But then… I wondered if I could ANIMATE some processes by combining shortcuts as a sequence.
So I came up with this:
If you select a clip on v1 (having already aded a V2 track) and press Numberpad 8, SC will:
a) Copy the clip, then b) paste it onto V2. All in one go! Like this:

Cool? Well there’s cooler! …
I wrote a script which automatically adds a 1-second transition to a row of clips on the timeline. You still have to drag the clips over each other, but the process is started by just pressing one key (number pad key 7).

You need several clips placed back to back on V1, and “ripple tracks” selected. Select the first clip, Press Number pad 7, and SC’s cursor will:
a) go to the end of the clip,
b) move back 1 second,
c) WAIT for 2.5 seconds (for you to drag clip 2 backwards over clip 1 to make a transition),
d) go to the end of clip 2 (in two movements),
e) move back 1 second,
c) WAIT for 2.5 seconds (for you to drag clip 3 backwards over clip 2 to make a transition),

etc etc etc… - with the LOOP function you can make it do this as amny times as you want…

Here’s a gif of me doing this. (I just pressed ONE key and the cursor moved on its own):

I’m happy to share the code for these scripts. I’ve put them into one text file below. To use, copy/paste into Notepad and save with the extension .ahk.

	            Numpad1::
                Loop, 1
				{
				Send ^{left}
				}
				return

				Numpad2::
				Loop, 1
			{
			Send ^{right}
			}
			return


			Numpad4::
			Loop, 1
			{
			Send !{left}{Alt Up}
			}
			return

			Numpad5::
			Loop, 1
			{
			Send !{right}{Alt Up}
			}
			return

			Numpad7::
			Loop, 4
			{
			Send !{right}
			Sleep 600
			send, {PgUp} 
			Sleep 2500
			Send !{right}{Alt Up}
			Sleep 600
			Send !{right}{Alt Up}
			Sleep 600
			send, {PgUp} 
			Sleep 2500
			send, {PgDn} 
			Sleep 600
			}
			return

			Numpad8::
			Loop, 1
			{
			Send ^{c}
			Sleep 600
			Send, {Up}
			Sleep 600
			Send, {b} 
			Sleep 2500
			}
			return

If I get a bit of free time I’ll make a quick tutorial showing how to set AutoHot Key up. Hopefully others here can make up some similar ahk scripts to do more cool animated tasks within SC!

2 Likes

Is this what you’re using?

Hi @Hudson555x, that’s it.

This is really cool! I took a look some time ago at the Contour Shuttle controller, but never actually bought one. Using your method and a USB accounting numeric keypad I have lying around, I could accomplish very nearly the same thing. Numeric keypad for my left hand with all the common functions mapped to it, and the mouse for my right hand… that could make for a very fast workflow. No hunting around a full-size keyboard for shortcut keys.

Thanks, @austin, yes, I think it’s cool too! Your idea sounds a good one.

Actually, I just thought of another useful little script. The following code works as follows:

Start Shotcut.
Press “s” then “u”.
Immediately 3 blank tracks are created (2 video tracks and 1 audio track).

That’s it. - designed to save time.

Here’s the AutoHotKey code. You can add it to the end of the code above, or save it as a separate .ahk file. :

:*:su:: ;(short for "setup" - gives 2 video tracks and 1 audio track).
send, ^{i}
send, ^{i}
send, ^{-}
send, ^{u}
return

Quick explanation of how it works:
Line 1 :*:su:: - tells AutoHotKey to trigger when the keys “s” and “u” are pressed.
(the text after the ; is just a comment, it’s not read by AutoHotKey).
Line 2:send, ^{i} - presses Ctrl+i (add new video track) in Shotcut. (^ = Ctrl, {i} = letter “i”}.
Line 3:send, ^{i} - gives the 2nd video track.
Line 4:send, ^{-} - makes the tracks shorter.
Line 4:send, ^{u} - adds an audio track (Ctrl+u).
Line 5:return - ends the process.
(“send” just tells AHK to press keys).
Simple, but effective!

Hey hey hey HEY! There’s more …

Just discovered AutoHotKey also allows you to automate mouse positions and mouse clicks!

So - I just made these 4 AHK scripts. They use x and y co-ordinates of the mouse to enable buttons/icons to be pressed.

How they work:
#1 - add a “size/position” filter to a clip:

  1. Select a clip on the timline in SC.
  2. Press Ctrl+1
    Done!

#2 - add a “rotate/scale” filter to a clip:
Select clip, press Ctrl+2. Done!

#3 - add a “fade in video (adjust opacity instead of fade with black (1 second)” filter to a clip:
Select clip, press Ctrl+3. Done!
(Yes I know you can add a fade in by double-clicking the balck throbber, but this automactically ticks the "adjust opacity … checkbox).

#4 - add a “fade out video (adjust opacity instead of fade with black (1 second)” filter to a clip:
Select clip, press Ctrl+4. Done!

Code:

 ^1:: ;(shortcut for "size and position filter (add to clip)" ).
 Click, left, 160, 760
 Click, left, 30, 300
 Click, left, 22, 150
 SendInput, size
 Click, left, 90, 214
 return
 
 
 ^2:: ;(shortcut for "rotate and scale" filter (add to clip)" ).
 Click, left, 160, 760
 Click, left, 30, 300
 Click, left, 22, 150
 SendInput, rotate
 Click, left, 90, 214
 return
 
 ^3:: ;(shortcut for "fade in video (adjust opacity)" filter (add to clip)" ).
 Click, left, 160, 760
 Click, left, 30, 300
 Click, left, 22, 150
 SendInput, fade in video
 Click, left, 90, 214
 Click, left, 20, 360
 return
 
 ^4:: ;(shortcut for "fade out video (adjust opacity)" filter (add to clip)" ).
 Click, left, 160, 760
 Click, left, 30, 300
 Click, left, 22, 150
 SendInput, fade out video
 Click, left, 90, 214
 Click, left, 20, 360
 return

PS the co-ordinates work on my screen - I suspect they may not work exactly on all systems, due to different screen resolutions etc. Co-ords can be edited though.

EDIT: And by combining the last two scripts you get it to add a fade IN AND a fade OUT to a clip by only pressing Ctrl+5:

^5:: ;(shortcut for "fade IN and OUT video (adjust opacity) filter (add to clip)" ).
Click, left, 160, 760
Click, left, 30, 300
Click, left, 22, 150
SendInput, fade in video
Click, left, 90, 214
Click, left, 20, 360
Click, left, 160, 760
Click, left, 30, 300
Click, left, 22, 150
SendInput, fade out video
Click, left, 90, 214
Click, left, 20, 360
return

Hi Jonray,

Checking out your other scripts. I really like this one! Question for you.

So from what I am understanding a person would have to manually drag a clip over another clip and then hit the designated hotkey in order to have the 1 second transition automatically added. This would have to be repeated for how many transitions are needed.

Doing this is all well and good for a few clips, but what if you have 25 clips or 50 clips or more?

I am wondering have you ever considered writing a script to automate the process of dragging each clip over a certain number of spaces to equal the 1 second transition or a 0.5 second transition or what ever time length a person needs?

Would be major if you did!

Hi Treuben, I thought of doing that but I actually couldn’t think of a way of automating a clip being dragged. Hmm, wonder if anyone else on here has any ideas how to do this? I agree, it would be cool :smiley:

There are a lot of great tips here already.
I have one more thing that I want to see if someone knows how to make it happen.
Right now, Shotcut doesn’t support splitting multiple clips at once. What I do now is hit ‘s’ to split a track, hit up or down arrow to go to the next track, hit ‘s’ and so on.
Can you folks think of a way to automate this so that all tracks get split at once if I press shift + s??

I tried a few times bit of tinkering but couldn’t figure out how to know the number of tracks present in the project and which track is currently selected.

Try this method by using Ripple Across All Tracks:

Can i split all tracks with ‘s’ if I have ‘Ripple All Tracks’ selected?

I am on my phone now. So, I can’t test it out immediately but I don’t think that suffices for my case here.

Split the clip of one track then move it back a bit so that the other tracks will follow thanks to the two ripple buttons. Here’s a demo I made:

4 Likes

Cool technique!! :+1: