1
votes

I'm an AHK beginner, been trying it out for a day. I've had some success but I'm stuck.

I want to use ahk to automate repetitive tasks done by existing keyboard shortcuts in a program called Shotcut (a video editor). So, in Shotcut I have a series of clips arranged one after the other on the timeline (I'll call them clip1, clip2, clip3 etc).

At present, using Shotcut's keyboard shortcuts, I press:

  1. Alt+right arrow (to move cursor to end of clip 1)
  2. Page Up (to move cursor backwards by 1 second)

..then I drag Clip 2 backwards over clip 1, to create a transition (no keyboard shortcut for this in Shotcut).. Then..

  1. and 4. Alt+right arrow TWICE (to move cursor to end of clip 2)
  2. Page Up (to move cursor back by 1 second). ...etc etc (repeat this process).

So what I'd like to know is, how can I script ahk to:

  1. Just automate steps 1 and 2 above (ie. Alt+right arrow then Page Up), by pressing, say, Ctrl+h in Shotcut....

and/or:

  1. Just automate steps 3,4 and 5 above (ie Alt+right arrow TWICE, then Page Up)...

or, even better, could I:

  1. automate steps 1, 2, then Pause ahk (while I drag the clips)... then continue with steps 3,4 and 5...?

I used the following to successfully just to get "PageUp" when Ctrl+h was pressed:

^h::
send, {PgUp} 
return

However I tried the following just for a solution just to get "Alt+right arrow" on pressing Ctrl+g but it didn't work -the cursor stayed still:

^g::
send, {!alt}
return

Where am I going wrong?

3
EDIT: I just solved the alt+right problem (above) by using^g:: SendInput !{right} Return .. now I just need to find out how to get the shortcuts to run in succession.JSR

3 Answers

2
votes

For sure you are on the right track. Use the help, especially the "Tutorial for beginners" also at https://www.autohotkey.com/docs/Tutorial.htm#s1

So, just add them all together and optionally add some wait time between the steps to make sure the first one finishes, as follows:

^h::
    Send, {PgUp} 
    Sleep, 100  ;  optional delay (in milliseconds)
    SendInput, !{right}
return

Or try something like this:

^g::doSomething(A_ThisHotkey) ; ctrl+g presses alt+left
^h::doSomething(A_ThisHotkey) ; ctrl+h presses alt+right

doSomething(me){
    msgbox success! You pressed %me%
    Send, {PgUp} 
    Sleep, 100  ;  optional delay (in milliseconds)
    IfEqual, me, "^g", SendInput, {Alt Down}{left}{Alt Up}
    IfEqual, me, "^h", SendInput, {Alt Down}{right}{Alt Up}
return
}

Hth,

1
votes

PGilm provided a good example of how to combine the hotkeys. For the Sleep, 100 in his setup you may want to replace it with KeyWait, LButton, U https://www.autohotkey.com/docs/commands/KeyWait.htm

By implementing this you could cause the SendInput !{right} to trigger after releasing the mouse 1 button. You could add more KeyWait, LButton, D and KeyWait, LButton, U for however many total clicks it takes for you to drag clip 2 over clip 1 in your example.

0
votes

Thanks to @PGilm and @ilhom - your replies gave me the kickstart I needed. My final code was

^h::
Send !{right}
Sleep 600
send, {PgUp} 
Sleep 2000
Send !{right}{Alt Up}
Sleep 600
Send !{right}{Alt Up}
Sleep 600
send, {PgUp} 
return

Works like a dream! I found I needed {Alt Up} after !{right} or it didn't work. (The code is pretty simple I know, but to me (a newbie), this has opened up a whole lot of creative possibilities for automating processes in Shotcut and other progs). Thks!!

PS sorry if it's not etiquette to answer on my own question......