forked from TaranVH/2nd-keyboard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Almost_All_Premiere_Functions.ahk
2404 lines (1953 loc) · 91.8 KB
/
Almost_All_Premiere_Functions.ahk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
SetWorkingDir, C:\AHK\2nd-keyboard\support_files
;the above will supposedly set A_WorkingDir. It MUST be done in the autoexecute area, BEFORE the code below.
;SetWorkingDir, C:\Users\TaranWORK\Documents\GitHub\2nd-keyboard\2nd keyboard support files
;NOTE that I am now on Premiere 22.2.0 (Build 128)
;I was previously on Premiere 15.4.1. All the below scripts will work for that version, except for some instances where you need to change "2022" to "2021" for functions that are trying to target a specific window.
#NoEnv
Menu, Tray, Icon, shell32.dll, 283 ; this changes the tray icon to a little keyboard!
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
#SingleInstance force ;only one instance of this script may run at a time!
#MaxHotkeysPerInterval 2000
#WinActivateForce ;https://autohotkey.com/docs/commands/_WinActivateForce.htm
;-------------------------------------------------------------------------
; HELLO PEOPLES!
; IF YOU ARE NEW TO AUTOHOTKEY, YOU MUST AT LEAST TAKE THE FOLLOWING TUTORIAL:
; https://autohotkey.com/docs/Tutorial.htm
;
; You will need to know some basic scripting to custom tailor most
; of these scripts to your own machine, if you want to use them!
;
; CHECK OUT MY BIG TUTORIAL FOR SOME EXPLANATION OF HOW THESE
; AHK SCRIPTS WORK, AND HOW THEY COMMUNICATE WITH ONE ANOTHER.
; https://youtu.be/O6ERELse_QY?t=20m7s
;
; VERY IMPORTANT NOTE:
; This file works in tandem with ALL_MULTIPLE_KEYBOARD_ASSIGNMENTS.ahk.
; That script has this one
; All the functions from HERE are actually CALLED from keyboard shortcuts
; in THAT script. I had to do it this way because of the Stream Deck(s)...
; But you can put your key bindings and functions in the same script if
; you want.
;
; You also need to read from around line 90 of ALL_MULTIPLE_KEYBOARD_ASSIGNMENTS.ahk.
; to see which keybaord shortcut assignements are necessary to make these scripts work.
;
; I recommend that you only copy the functions that you need.
; Add one at a time or it will be overwhelming!
;
; All the code in my github repo is free for you to use and change as you please.
; Just don't try to sell it, and we cool.
;------------------------------------------------------------------------
;the variable below POSSIBLY exists for the purpose of communicaiton with gui.ahk if a script is launched from the Stream Deck.
TargetScriptTitle = "C:\AHK\2nd-keyboard\gui.ahk ahk_class AutoHotkey"
;but apparently I do not know for sure...
recallTransition(foo) ;this was a part of the luamacros scripts.
{
;Do nothing.
msgbox, the recallTransition function was deleted cause it never worked very well. %foo%
}
;;;;;;non luamacros stuff begins now.;;;;;
;;;;;;temporary tooltip maker;;;;;;
Tippy(tipsHere, wait:=-333)
{
ToolTip, %tipsHere% TIP,,,8
SetTimer, noTip, %wait% ;--in 1/3 seconds by default, remove the tooltip
;return
}
;um I am trying this because i think the tooltip was being deleted like every bazillionth of a second?
noTip:
ToolTip,,,,8 ;removes the tooltip
SetTimer, noTip, Off
;I REALLY need to figure out how subroutines work...
return ;hoey sit, i didn't have a return here for a long time
;;;;;;/temporary tooltip maker;;;;;;
#IfWinActive ahk_exe Adobe Premiere Pro.exe ;---EVERYTHING BELOW THIS LINE WILL ONLY WORK INSIDE PREMIERE PRO! (until canceled with a lone "#IfWinActive")
;however, that only applies to stuff like hotkey definitions. I'm pretty sure that functions can be defined anywhere.
monitorKeys(whichMonitor,shortcut,useSpace := 1)
{
;this function has proven to be shockingly robust.
keywait, %A_priorhotkey% ;hopefully that doesn't break it.
;msgbox,,, useSpace is %useSpace%,1
if WinActive("ahk_exe Adobe Premiere Pro.exe") ;AHA, it is better to use the EXE, because if you are in a secondary monitor window, then the CLASS is not active even though the EXE still is, mildly interesssstting.
{
;IDK if I need to set a coordmode here?
; coordmode, pixel, Window
; coordmode, mouse, Window
; coordmode, Caret, Window
if (whichMonitor = "source")
{
x := "1800"
y := "500"
;;tooltip, source here
;coordinates that are very likely to be within my Source Monitor's usual area
}
else
{
x := "3300"
y := "500"
;;tooltip, program here
whichMonitor = "program" ;just in case it was not defined properly, it becomes "program" by default.
;coordinates that are very likely to be within my Program Monitor's usual area
}
; tooltip, x y is %x% %y%
; sleep, 500
;testing some sheeit
x := "1800"
y := "500"
ActiveHwnd := WinExist("A")
windowWidth := CoordGetControl(x,y, ActiveHwnd)
; tooltip, ActiveHwnd is %ActiveHwnd%
; sleep, 500
; tooltip, windowWidth is %windowWidth%
; sleep, 500
if (windowWidth < 2000) ;this means that the monitor is NOT maximized
{
;tooltip, windowwidth is less than 2000
; sleep 500
if (whichMonitor = "source"){
prFocus("source") ;keep in mind, this FIRST brings focus to the Effects panel
;tooltip, u in SOURCE LAND
; sleep 500
}
else
{
prFocus("program") ;keep in mind, this FIRST brings focus to the Effects panel
;tooltip, u in program LAND
}
sleep 20
}
sleep 30 ;sometimes these shortcuts don't "take" without a bit of delay.
sendinput, %shortcut%
;so, the above would be translated to sendinput, ^+2 or something like that.
; if (shortcut = "^{numpad3}") or if (shortcut = "^+1")
; {
; sleep 30
; sendinput, %shortcut%
; ;Premiere 12.0.1 is SLOOOWWW to react to these shortcuts in particular. (Source monitor resolution to 1/4) and (program monitor res to 1/1) So I gotta WAIT AROUND and send this TWICE.
; }
; if (shortcut = "^{numpad2}")
; {
; send, {CTRL UP}
; sleep 10
; send, {CTRL DOWN}
; sleep 10
; send, {CTRL UP}
; sleep 10
; }
;THE CODE BELOW IS SUPER OPTIONAL
if (windowWidth > 2000) ;if the monitor in question IS maximized...
{
;tooltip, %shortcut% boy
;Then it's not obvious which monitor it is, and it's possible that I misremembered, and pressed the wrong button. Therefore, I will ALSO send the shortcut that corresponds to the alternative monitor.
;Also, it's possible that the window is not in focus. I want to send a middle click to it without moving the mouse, since coordinates arent well supported on other monitors. For this, controlfocus or controlclick MIGHT work...
;ControlClick , x1800 y500, WinTitle, WinText, MIDDLE, 1, Pos
if (shortcut = "^{numpad1}")
{
;sleep 30
sendinput, ^+1
}
if (shortcut = "^{numpad2}")
{
sendinput, ^+2
}
if (shortcut = "^{numpad5}")
{
;sleep 30
;tooltip, yeah ctrl numpad 5
sendinput, ^+2
}
if (shortcut = "^{numpad3}")
sendinput, ^+3
if (shortcut = "^+1")
{
;tooltip, taran whyyy
sendinput, ^{numpad1}
}
if (shortcut = "^+2")
{
;sleep 30
sendinput, ^{numpad2}
}
if (shortcut = "^+3")
{
;sleep 30
sendinput, ^{numpad3}
}
;and now for the safe margins
if (shortcut = "^!+[")
sendinput, ^!+]
if (shortcut = "^!+]")
sendinput, ^!+[
}
;THE CODE ABOVE IS SUPER OPTIONAL
;i might have to comment this back in vvvvv
if (windowWidth < 2000) ;again, if the monitor in question is NOT already maximized...
if not (whichMonitor = "source") ;stay on the source (program?) monitor if it is active
{
prFocus("timeline")
;tooltip, this is why
}
;;; that ^^^^^
;if (useSpace = "0")
;tooltip, we are NOT NOT NOT spacing
;;optional:
if (useSpace = "1")
{
;tooltip, we are spacing
sendinput, {space} ;if playing/paused, pause/play the video.
sleep 50
sendinput, {space} ;if playing/paused, pause/play the video.
;;this allows the new playback resolution to take effect.
}
}
;if you are not in Premiere Pro, the function is skipped
; if not WinActive("ahk_exe Adobe Premiere Pro.exe")
; msgbox,,, pr is not active,1
; ; ;if you use the ahk_class, even if you have an active Premiere window on another monitor, unless it is the MAIN monitor, it doesn't count.
}
;end of monitorKeys()
effectsPanelFindBox()
{
prFocus(effects)
sendinput, ^b ;select find box
}
effectsPanelType(item := "lol")
{
;THIS IS A VERY SIMPLE FUNCTION FOR JUST TYPING STUFF INTO THE SEARCH BAR
;but it doesn't apply them to the clips, unlike preset()
;MODSL() ;this is probably no longer needed, but IDK for sure.
;prFocus("effects") ;reliably brings focus to the effects panel. This is an alternative to the next line.
Sendinput, ^+!7 ;CTRL SHIFT ALT 7 -- set in premiere to "effects" panel
sleep 20
Sendinput, ^b ;CTRL B --set in premiere to "select find box." Makes a windows noise if you do it again.
;sleep 20
Sendinput, +{backspace} ;shift backspace deletes any text that may be present. It is much less dangerous than sending "delete" or "backspace" alone.
Sleep, 10
Sendinput, %item%
;now this next part re-selects the field in case you want to type anything different
;sleep 10
Sendinput, ^!b ;ctrl alt B is ALSO select find box, but doesn't have the annoying windows sound. I may wish to change this to something else, as ALT is inherently dangerous if it becomes stuck.
}
#if
MODSL()
{
;UNSTICK LEFT MODIFIERS. I don't really use this anymore.
sendinput, {blind}{SC0E2} ;scan code of an unassigned key. Used for debugging. Warning: may activate windows Game Bar if you didn't disable it.
sleep, 1 ;okay soooooooooo apparently this is always at LEAST 10 to 15 milliseconds no matter what i do. uuuuugh.
; ; https://www.autohotkey.com/docs/commands/Sleep.htm
sendinput,{blind}{LCtrl up}{LAlt up}{LShift up}
;sendinput, {blind}{SC0E3} ;scan code of an unassigned key. Used for debugging. Warning: may activate windows Game Bar if you didn't disable it.
}
MODSR()
{
;UNSTICK RIGHT MODIFIERS. I don't use this anymore.
sendinput, {blind}{SC0E3} ;scan code of an unassigned key. Used for debugging. Warning: may activate windows Game Bar if you didn't disable it.
sleep 1
sendinput, {blind}{RCtrl up}{RAlt up}{RShift up}
sendinput, {blind}{SC0E4} ;scan code of an unassigned key. Used for debugging. Warning: may activate windows Game Bar if you didn't disable it.
}
preset(item)
{
;******FUNCTION FOR DIRECTLY APPLYING A PRESET EFFECT TO A CLIP!******
; preset() is my most used, and most useful AHK function for Premiere Pro!
;===================================================================================
; NEW TO AHK? READ ALL THE BELOW INSTRUCTIONS BEFORE YOU TRY TO USE THIS.
; THIS WILL NOT WORK UNLESS YOU DO SOME SETUP FIRST!
; Fortunately,
; THERE IS A FULL VIDEO TUTORIAL THAT TEACHES YOU HOW TO USE THIS, STEP BY STEP.
; [[[[[LINK TBD, IT'S NOT FINISHED JUST YET.]]]]]
;
; Even if Adobe does one day add this feature to Premiere, this video tutorial will
; still be very useful to anyone who is learning how to use AHK with Premiere,
; especially if you're trying to use any of the other functions that I've created.
;
; To call the function, use something like
; F4::preset("crop 50")
; Where "crop 50" is the exact, unique name of the preset you wish to apply.
;
; For this function to work, you MUST go into Premiere's Keyboard Shortcuts panel,
; find the following commands, and add these keyboard shortcut assignments to them:
;
; Select Find Box ------- CTRL B
; Shuttle Stop ---------- CTRL ALT SHIFT K
; Window > Effects ----- CTRL ALT SHIFT 7
;
; (You can use different shortcuts if you like, as long
; as those are the ones you send with your AHK script.)
;
;====================================================================================
;Keep in mind, I use 100% UI scaling on my primary monitor, so if you use 125% or 150% or anything else, your pixel distances for commands like Mousemove WILL be different. Therefore, you'll need to "comment in" the message boxes, change some numbers, and keep saving and refreshing and retrying the script until you've got it working!
;To find out what UI scaling your screen uses, hit the windows key, type in "display," hit Enter, and then scroll down to "Scale and layout." Under "Change the size of text, apps, and other items," there will be a selection menu thing. Mine is set to "100%." I have NOT done anything in the "Advanced scaling settings" blue link just below that.
;To use this script yourself, carefully go through testing the script and changing the values, ensuring that the script works, one line at a time. use message boxes to check on variables and see where the cursor is. remove those message boxes later when you have it all working!
;NOTE: I built this under the assumption that your Effects Panel will be on the same monitor as your timeline. I can't guarantee that it'll work if the Effects Panel is on another monitor.
;NOTE: You also need to get the PrFocus() function.
;NOTE: To use the preset() function, your cursor must first be hovering over the clip that you wish to apply your preset to. It also works to select multiple clips, again, as long as your cursor is hovering over one of the selected clips.
keywait, %A_PriorHotKey% ;keywait is quite important.
;Let's pretend that you called this function using the following line:
;F4::preset("crop 50")
;In that case, F4 is the prior hotkey, and the script will WAIT until F4 has been physically RELEASED (up) before it will continue.
;https://www.autohotkey.com/docs/commands/KeyWait.htm
;Using keywait is probably WAY cleaner than allowing the physical key UP event to just happen WHENEVER during the following function, which can disrupt commands like sendinput, and cause cross-talk with modifier keys.
;;---------You do not need the stuff BELOW this line.--------------
sendinput, {blind}{SC0EC} ;for debugging. YOU DO NOT NEED THIS.
;Keyshower(item,"preset") ;YOU DO NOT NEED THIS. -- it simply displays keystrokes on the screen for the sake of tutorials...
; if IsFunc("Keyshower")
; {
; Func := Func("Keyshower")
; RetVal := Func.Call(item,"preset")
; }
ifWinNotActive ahk_exe Adobe Premiere Pro.exe ;the exe is more reliable than the class, since it will work even if you're not on the primary Premiere window.
{
goto theEnding ;and this line is here just in case the function is called while not inside premiere. In my case, this is because of my secondary keyboards, which aren't usually using #ifwinactive in addition to #if getKeyState(whatever). Don't worry about it.
}
;;---------You do not need the stuff ABOVE this line.--------------
;Setting the coordinate mode is really important. This ensures that pixel distances are consistant for everything, everywhere.
; https://www.autohotkey.com/docs/commands/CoordMode.htm
coordmode, pixel, Window
coordmode, mouse, Window
coordmode, Caret, Window
;This (temporarily) blocks the mouse and keyboard from sending any information, which could interfere with the funcitoning of the script.
BlockInput, SendAndMouse
BlockInput, MouseMove
BlockInput, On
;The mouse will be unfrozen at the end of this function. Note that if you do get stuck while debugging this or any other function, CTRL SHIFT ESC will allow you to regain control of the mouse. You can then end the AHK script from the Task Manager.
SetKeyDelay, 0 ;NO DELAY BETWEEN STUFF sent using the "send"command! I thought it might actually be best to put this at "1," but using "0" seems to work perfectly fine.
; https://www.autohotkey.com/docs/commands/SetKeyDelay.htm
Sendinput, ^!+k ;in Premiere's shortcuts panel, ASSIGN "shuttle stop" to CTRL ALT SHIFT K.
sleep 10
Sendinput, ^!+k ; another shortcut for Shuttle Stop. Sometimes, just one is not enough.
;so if the video is playing, this will stop it. Othewise, it can mess up the script.
sleep 5
;msgbox, ahk_class = %class% `nClassNN = %classNN% `nTitle= %Window%
;;This was my debugging to check if there are lingering variables from last time the script was run. You do not need that line.
MouseGetPos, xposP, yposP ;------------------stores the cursor's current coordinates at X%xposP% Y%yposP%
;KEEP IN MIND that this function should only be called when your cursor is hovering over a clip, or a group of selected clips, on the timeline. That's because the cursor will be returned to that exact location, carrying the desired preset, which it will drop there. MEANING, that this function won't work if you select clips, but don't have the cursor hovering over them.
sendinput, {mButton} ;this will MIDDLE CLICK to bring focus to the panel underneath the cursor (which must be the timeline). I forget exactly why, but if you create a nest, and immediately try to apply a preset to it, it doesn't work, because the timeline wasn't in focus...? Or something. IDK.
sleep 5
prFocus("effects") ;Brings focus to the effects panel. You must find, then copy/paste the prFocus() function definition into your own .ahk script as well. ALTERNATIVELY, if you don't want to do that, you can delete this line, and "comment in" the 3 lines below:
;Sendinput, ^+!7 ;CTRL SHIFT ALT 7 --- In Premiere's Keyboard Shortcuts panel, you nust find the "Effects" panel and assign the shortcut CTRL SHIFT ALT 7 to it. (The default shortcut is SHIFT 7. Because Premiere does allow multiple shortcuts per command, you can keep SHIFT 7 as well, or you can delete it. I have deleted it.)
;sleep 12
;Sendinput, ^!+7 ;you must send this shortcut again, because there are some edge cases where it may not have worked the first time.
sendinput, {blind}{SC0ED} ;for debugging. YOU DO NOT NEED THIS LINE.
sleep 15 ;"sleep" means the script will wait for 15 milliseconds before the next command. This is done to give Premiere some time to load its own things.
Sendinput, ^b ;CTRL B ------- set in premiere's shortcuts panel to "select find box"
sleep 5
;Alternatively, it also works to click on the magnifying glass if you wish to select the find box... but this is unnecessary and sloppy.
;The Effects panel's find box should now be activated.
;If there is text contained inside, it has now been highlighted. There is also a blinking vertical line at the end of any text, which is called the "text insertion point", or "caret".
if (A_CaretX = "")
{
;No Caret (blinking vertical line) can be found.
;The following loop is waiting until it sees the caret. THIS IS SUPER IMPORTANT, because Premiere is sometimes quite slow to actually select the find box, and if the function tries to proceed before that has happened, it will fail. This would happen to me about 10% of the time.
;Using the loop is also way better than just ALWAYS waiting 60 milliseconds like I was before. With the loop, this function can continue as soon as Premiere is ready.
;sleep 60 ;<—Use this line if you don't want to use the loop below. But the loop should work perfectly fine as-is, without any modification from you.
waiting2 = 0
loop
{
waiting2 ++
sleep 33
tooltip, counter = (%waiting2% * 33)`nCaret = %A_CaretX%
if (A_CaretX <> "")
{
tooltip, CARET WAS FOUND
break
}
if (waiting2 > 40)
{
tooltip, FAIL - no caret found. `nIf your cursor will not move`, hit the button to call the preset() function again.`nTo remove this tooltip`, refresh the script using its icon in the taskbar.`n`nIt's possible Premiere tried to AUTOSAVE at just the wrong moment!
;Note to self, need much better way to debug this than screwing the user. As it stands, that tooltip will stay there forever.
;USER: Running the function again, or reloading the script, will remove that tooltip.
;sleep 200
;tooltip,
sleep 20
GOTO theEnding
}
}
sleep 1
tooltip,
}
;The loop has now ended.
;yeah, I've seen this go all the way up to "8," which is 264 milliseconds
MouseMove, %A_CaretX%, %A_CaretY%, 0 ;this moves the cursor, instantly, to the position of the caret.
sleep 5 ;waiting while Windows does this. Just in case it takes longer than 0 milliseconds.
;;;and fortunately, AHK knows the exact X and Y position of this caret. So therefore, we can find the effects panel find box, no matter what monitor it is on, with 100% consistency!
;tooltip, 1 - mouse should be on the caret X= %A_CaretX% Y= %A_CaretY% now ;;this debugging line was super helpful in me solving this one! Connent this line in if you want to use it, but comment it out after you've gotten the whole function working.
;;;msgbox, caret X Y is %A_CaretX%, %A_CaretY%
MouseGetPos, , , Window, classNN
WinGetClass, class, ahk_id %Window%
;tooltip, 2 - ahk_class = %class% `nClassNN = %classNN% `nTitle= %Window%
;;;note to self, I think ControlGetPos is not affected by coordmode?? Or at least, it gave me the wrong coordinates if premiere is not fullscreened... IDK. https://autohotkey.com/docs/commands/ControlGetPos.htm
ControlGetPos, XX, YY, Width, Height, %classNN%, ahk_class %class%, SubWindow, SubWindow
;note to self, I tried to exclude subwindows but I don't think it works...?
;;my results: 59, 1229, 252, 21, Edit1, ahk_class Premiere Pro
;tooltip, classNN = %classNN%
;;Now we have found a lot of useful information about this find box. Turns out, we don't need most of it...
;;we just need the X and Y coordinates of the "upper left" corner...
;;Comment in the following line to get a message box of your current variable values. The script will not advance until you dismiss a message box. (Use the enter key.)
;MsgBox, xx=%XX% yy=%YY%
;; https://www.autohotkey.com/docs/commands/MouseMove.htm
;MouseMove, XX-25, YY+10, 0 ;--------------------for 150% UI scaling, this moves the cursor onto the magnifying glass
MouseMove, XX-15, YY+10, 0 ;--------------------for 100% UI scaling, this moves the cursor onto the magnifying glass
;msgbox, should be in the center of the magnifying glass now. ;;<--comment this in for help with debugging.
sleep 5
Sendinput, %item%
;This types in the text you wanted to search for, like "crop 50". We can do this because the entire find box (and any included text) was already selected.
;Premiere will now display your preset at the top of the list. There is no need to press "enter" to search.
sleep 5
;MouseMove, 62, 95, 0, R ;----------------------(for 150% UI.)
MouseMove, 41, 63, 0, R ;----------------------(for 100% UI)
;;relative to the position of the magnifying glass (established earlier,) this moves the cursor down and directly onto the preset's icon.
;;In my case, all of my presets are contained inside of folders, which themselves are inside the "presets" folder. Your preset's written name should be completely unique so that it is the first and only item.
;msgbox, The cursor should be directly on top of the preset's icon. `n If not, the script needs modification.
sleep 5
;;At this point in the function, I used to use the line "MouseClickDrag, Left, , , %xposP%, %yposP%, 0" to drag the preset back onto the clip on the timeline. HOWEVER, because of a Premiere bug (which may or may not still exist) involving the duplicated displaying of single presets (in the wrong positions) I have to click on the Effects panel AGAIN, which will "fix" it, bringing it back to normal.
;+++++++ If this bug is ever resolved, then the lines BELOW are no longer necessary.+++++
MouseGetPos, iconX, iconY, Window, classNN ;---now we have to figure out the ahk_class of the current panel we are on. It might be "DroverLord - Window Class14", but the number changes anytime you move panels around... so i must always obtain the information anew.
sleep 5
WinGetClass, class, ahk_id %Window% ;----------"ahk_id %Window%" is important for SOME REASON. if you delete it, this doesn't work.
;tooltip, ahk_class = %class% `nClassNN = %classNN% `nTitle= %Window%
;sleep 50
ControlGetPos, xxx, yyy, www, hhh, %classNN%, ahk_class %class%, SubWindow, SubWindow ;;-I tried to exclude subwindows but I don't think it works...?
MouseMove, www/4, hhh/2, 0, R ;-----------------moves to roughly the CENTER of the Effects panel. Clicking here will clear the displayed presets from any duplication errors. VERY important. Without this, the script fails 20% of the time. This is also where the script can go wrong, by trying to do this on the timeline, meaning it didn't get the Effects panel window information as it should have.
sleep 5
MouseClick, left, , , 1 ;-----------------------the actual click
sleep 5
MouseMove, iconX, iconY, 0 ;--------------------moves cursor BACK onto the preset's icon
;tooltip, should be back on the preset's icon
sleep 5
;;+++++If this bug is ever resolved, then the lines ABOVE are no longer necessary.++++++
MouseClickDrag, Left, , , %xposP%, %yposP%, 0 ;---clicks the left button down, drags this effect to the cursor's pervious coordinates and releases the left mouse button, which should be above a clip, on the TIMELINE panel.
sleep 5
MouseClick, middle, , , 1 ;this returns focus to the panel the cursor is hovering above, WITHOUT selecting anything. great! And now timeline shortcuts like JKL will work.
blockinput, MouseMoveOff ;returning mouse movement ability
BlockInput, off ;do not comment out or delete this line -- or you won't regain control of the keyboard!! However, CTRL ALT DELETE will still work if you get stuck!! Cool.
;;----remove the code below if it makes no sense to you.----
IfInString, item, CROP
{
if IsFunc("cropClick") ;This checks to see if you have a function named "cropClick"
{
Func := Func("cropClick")
sleep 320 ;because it might take awhile to appear in Premiere, and I'm not gonna do another loop think liek I did above...
RetVal := Func.Call()
}
;;If you don't have cropClick, then nothing happens. That's good!
;;This code below is what I had used before, but it will complain that you haven't defined the function "cropClick", whereas, the code above will NOT!
;sleep 320
;cropClick()
;;msgbox, that had "CROP" in it.
}
;;----remove the code above if it makes no sense to you----
;The line below is where all those GOTOs are going to.
theEnding:
}
;END of preset(). The two lines above this one are super important.
; https://github.com/Drakeyn/AdobeMacros/blob/master/Premiere%20Pro/Functions/ApplyPreset.ahk
; this is a sort of preset2() I am testing.
DrakeynPreset(item)
{
SendMode Event
;Waits to make sure any previous hotkeys have been released
;keywait, %A_PriorHotKey%
;Just in case we're not in Premiere Pro
if(WinActive("ahk_exe Adobe Premiere Pro.exe") = 0)
goto apEnd
;Sets up the coord modes, making sure our pixel distances are consistent
coordmode, pixel, Window
coordmode, mouse, Window
coordmode, Caret, Window
;Disables mouse and keyboard input to make sure the function runs properly
BlockInput, SendAndMouse
BlockInput, MouseMove
BlockInput, On
;Sets the keypress delay for Send/Sendinput commands to be zero.
SetKeyDelay, 0
;Gets the current position of the mouse and stores it in ox and oy (Original X and Original Y)
MouseGetPos, oX, oY
; ;Selects the Effects Panel -> Find Box
; SendInput, %kbSelectEffectsPanel%
; SendInput,%kbSelectFindBox%
effectsPanelFindBox()
;Types the preset we're looking for into the find box
Send %item%
;this is where we'd usually need to wait for premiere to update the presets list.
;If, however, it's pre-opened like mine (and reset to be pre-opened at the end of this function)
;then premiere will update the list instantly
;however, if not, or we want it to be reliable no matter what the current state is, we need to delay
;70 ms seems to be about right for my system, you may want to increase/decrease for your own
sleep 70
;get effects panel position
ControlGetPos, cX, cY, cW, cH, %wdEffectsPanel%, ahk_class Premiere Pro
msgbox, %cX%, %cY%, %cW%, %cH%
;find top preset icon
;ImageSearch, iX, iY, cX, cY, cX + cW, cY + cH, %A_WorkingDir%\preset.png
ImageSearch, iX, iY, cX, cY, cX + cW, cY + cH, C:\AHK\2nd-keyboard\support_files\preset.png
msgbox, %ErrorLevel%
if(ErrorLevel == 1)
goto apEnd
if(ErrorLevel == 2)
goto apEnd
;move mouse to preset
MouseMove, iX, iY + 5, 0
;drag preset back
MouseClickDrag, Left, , , oX, oY, 0
apEnd:
;Resets and pre-opens the presets list for easier editing - this is just for how [Draken] works
;SendInput, %kbSelectEffectsPanel%
prFocus(effects)
;SendInput, %kbSelectFindBox%
sendinput, ^b ;select find box
;;could use effectsPanelType() but it's not really the same thing because it deletes whatever is in there.
;;could use
;effectsPanelFindBox()
;;and i might later.
Send AAA Taran
;Puts the mouse back where it started
MouseMove oX, oY, 0
;Re-selects the timeline panel
MouseClick, middle, , , 1
;Re-enables input
BlockInput, MouseMoveOff
BlockInput, off
}
prFocus(panel)
{
;READ ALL THE COMMENTS BELOW OR SUFFER THE CONSEQUENCES.
;PrFocus() allows you to have ONE place where you define your personal shortcuts to "focus" panels in Premiere. It also ensures that panels actually get into focus, and don't rotate through the sequences or anything like that.
; THERE IS A FULL VIDEO TUTORIAL THAT TEACHES YOU HOW TO USE THIS, STEP BY STEP.
; [[[[[LINK TBD, IT'S NOT FINISHED JUST YET.]]]]]
;For this function to work, you MUST Go to Premiere's Keyboard Shortcuts panel, and add the following keyboard shortcuts to the following commands:
; KEYBOARD SHORTCUT PREMIERE COMMAND
; ctrl alt shift 3 .....Application > Window > Timeline (The default is shift 3)
; ctrl alt shift 1 .....Application > Window > Project (Sets the focus onto a BIN.) (the default is SHIFT 1)
; ctrl alt shift 4 .....Application > Window > Program Monitor (Default is SHIFT 4)
; ctrl alt shift 5 .....Application > Window > Effect Controls (Default is SHIFT 5)
; ctrl alt shift 7 .....Application > Window > Effects (NOT the Effect Controls panel!) (Default is SHIFT 7)
;(Note that ALL_MULTIPLE_KEYBOARD_ASSIGNMENTS.ahk has the FULL list of keyboard shortcuts that you need to assign in order for my other functions to work.)
;EXPLANATION: In Premiere, panel focus is very important. Many shortucts will only work if a specific panel is in focus. That is why those panels must be put into focus FIRST, which is what I built PrFocus() to do. (It's not always as simple as sending just the one keyboard shortcut to activate that panel.)
;Right now, we do NOT know which panel is in focus, (or "active.") and AHK has no way to tell (that I know of.)
;If a panel is ALREADY in focus, and you send the shortcut to bring it into focus again, that panel might then switch to a different sequence in the case of the timeline or program monitor,, or a different item in the case of the Source panel. IT's a nightmare!
;Therefore, we must start with a clean slate. For that, I chose the EFFECTS panel. Sending its focus shortcut multiple times, has no ill effects.
Sendinput, ^!+7 ;bring focus to the effects panel... OR, if any panel had been maximized (using the `~ key by default) this will unmaximize that panel, but sadly, that panel will still be the one in focus.
;Note that if the effects panel is ALREADY maximized, then sending the shortcut to switch to it will NOT un-maximize it. This is OK, though, because I never maximize the Effects Panel. If you do, then you might want to switch to the Effect Controls panel first, and THEN the Effects panel after this line.
;note that sometimes I use ^+! instead... it makes no difference compared to ^!+
sleep 12 ;waiting for Premiere to actaully do the above.
Sendinput, ^!+7 ;Bring focus to the effects panel AGAIN. Just in case some panel somewhere was maximized, THIS will now guarantee that the Effects panel is ACTAULLY in focus.
sleep 5 ;waiting for Premiere to actaully do the above.
sendinput, {blind}{SC0EC} ;scan code of an unassigned key. Used for debugging. You do not need this.
if (panel = "effects")
goto theEnd ;do nothing. The shortcut has already been sent.
else if (panel = "timeline")
Sendinput, ^!+3 ;if focus had already been on the timeline, this would have switched to the "next" sequence (in some unpredictable order.)
else if (panel = "program") ;program monitor. If focus had already been here, this would have switched to the "next" sequence.
Sendinput, ^!+4
else if (panel = "source") ;source monitor. If focus had already been here, this would have switched to the next loaded item.
{
Sendinput, ^!+2
;tippy("send ^!+2") ;tippy() was something I used for debugging. you don't need it.
}
else if (panel = "project") ;AKA a "bin" or "folder"
Sendinput, ^!+1
else if (panel = "effect controls")
Sendinput, ^!+5
theEnd:
sendinput, {blind}{SC0EB} ;more debugging - you don't need this.
}
;end of prFocus()
;;;Personal notes below:
;panel := """" . panel . """" ;This adds quotation marks around the parameter so that it works as a string, not a variable.
; ; ; if (panel = "effect controls")
; ; ; {
; ; ; Send ^!+5
; ; ; return
; ; ; }
;;;Personal notes above^^
;;you do NOT need the following function. Even I don't use it anymore.
savepreset(presetname){
SendInput, {Shift Down}{Shift Up}{Ctrl Down}{c Down}
sleep 20
SendInput, {c up}{Ctrl up}
sleep 20
msgbox, text in clipboard = %clipboard%
presetname = %clipboard%
msgbox, presetname = %presetname%
return presetname
}
insertSFX(leSound)
{
ifWinNotActive ahk_exe Adobe Premiere Pro.exe
goto sfxEnding
;keyShower(leSound, "insertSFX") ;the following is used instead of this line.
if IsFunc("Keyshower") ;checks to see if you have the Keyshower function defined.
{
Func := Func("Keyshower")
RetVal := Func.Call(leSound, "insertSFX")
}
CoordMode, mouse, Screen
CoordMode, pixel, Screen
coordmode, Caret, screen
BlockInput, mouse
blockinput, MouseMove
BlockInput, On
SetKeyDelay, 0 ;for instant writing of text
MouseGetPos, xpos, ypos
send ^+x ;ctrl shift x -- shortcut in premiere for "remove in/out points.
sleep 10
send ^+9 ;ctrl shift 6 - source assignment preset 4. (sets it to A3.)
sleep 10
; Send ^!+1 ;premiere shortcut to open the "project" panel, which is actually a bin. Only ONE bin is highlightable in this way.
; ;Send F11
; sleep 100
;msgbox, you in the panel now?
send ^!+1 ;CTRL ALT SHIFT 1 -- ;shortcut for application>window>project (highlights a single bin. In my case, it's on my left monitor.)
tooltip, waiting for premiere to select that bin....
;msgbox, waiting for premiere to select that bin....
sleep 20
;msgbox how about naow?
;
Send ^b ;CTRL B -- set this in premiere's shortcuts panel to "select find box." Make sure there are NO OTHER conflicting shortcuts on this key, like "create new bin," which would stop it from working.
; send +{backspace} ;to delete anything that might be written in the bin, so that the caret coordinates are always accurate.
; msgbox, okay now what
Send %leSound% ;types in the name of the sound effect you want - should do so instantaneously.
tooltip, waiting for premiere to load......
send ^+9 ;source assignment preset 4, again.
sleep 400 ;we are waiting for the search to complete....
;sleep 400 ;we are still waiting for the search to complete....
MouseMove, -6000, 250, 0 ;moves the mouse to the expected location of the bin that becomes highlighted from the "project" keyboard shortcut command in Premiere.
;msgbox, wheres de mouse?
; MouseGetPos, lol, lel
; PixelGetColor, zecolor, lol, lel, alt slow rgb
; msgbox, %zecolor%
MouseClick, left
tooltip, CLICK!!!
sleep 10
send ^+9 ;source assignment preset 4, again.
sleep 5
Send ^b ;CTRL B -- set this in premiere's shortcuts panel to "select find box."
sleep 10
Send +{backspace} ;deletes the search text so that the bin returns to normal view with all SFX visible.
sleep 10
MouseMove, %xpos%, %ypos%, 0 ;move mouse back to original coordinates.
sleep 20
tooltip, so did that work?
;msgbox, clicked, mouse should be back at original coordinates.
;send ^!+4 ;select program monitor
sleep 10
;send ^!+3 ;select timeline
sleep 10
send ^+9 ;my shortcut for "assign source assignment preset 4" in Premiere. The preset has V3 and A4 selected as sources. I may end up only using F18, since it does not use the CTRL and SHIFT keys, which can cause problems sometimes.
sleep 50
Send ^/ ;CTRL FORWARD SLASH -- SET TO "OVERWRITE" in premiere. Premiere's default shortcut for "overwrite" is a period. I use modifier keys for THIS, so that a period is never typed accidentally.
sleep 30
; Send mbutton ;this will MIDDLE CLICK to reselect whatever panel your cursor was hovering over before you engaged this function.
send ^!+7 ;highlight effects panel
sleep 30
send ^!+3 ;this is set in premiere to highlight/switch to the timeline. important so that you aren't still stuck in the bin. If this is used more than once, it will unfortunately cycle thorugh all available sequences...
tooltip,
BlockInput, off
BlockInput, MouseMoveOff
sfxEnding:
}
;;end of insertSFX()
;you can select something inside of premiere (like a group of clips, or a transition) and then, with this code, you can COPY it and SAVE that clipboard state. I use this in conjunction with my secondary keyboard.
;You need to have insideclipboard.exe installed, and all the file paths properly comfigured.
;Keep in mind that you must RESTART your computer before the clipboard states become usable. IDK why.
#ifwinactive ahk_exe Adobe Premiere Pro.exe
saveClipboard(int) {
StringReplace, int, int, +, , All ;replace + with nothing. This is just in case A_thishotkey contains + if shift was used!
StringReplace, int, int, !, , All ;replace ! with nothing. This is just in case A_thishotkey contains ! if alt was used!
StringReplace, int, int, ^, , All ;replace ^ with nothing. This is just in case A_thishotkey contains ^ if ctrl was used!
;msgbox, , , saving as %int%, 0.6
tooltip, saving as`n"clip" . %int% . ".clp"
sleep 10
SendInput, {Shift Down}{Shift Up}{Ctrl Down}{c Down}
sleep 20
ClipWait, 0.25 ; this line might not be needed.
SendInput, {c up}{Ctrl up}
sleep 20
saveToFile("clip" . int . ".clp")
sleep 1000
saveToFile("clip" . int . ".clp")
tooltip,
}
;This is the real magic. With this script, you can PASTE those previously saved clipboard states, at any time.
#ifwinactive ahk_exe Adobe Premiere Pro.exe
recallClipboard(int, transition := 0) {
;deactivate keyboard and mouse
;keyShower(int, "recallClipboard")
if IsFunc("Keyshower") {
Func := Func("Keyshower")
RetVal := Func.Call(int, "recallClipboard")
}
WinActivate, Adobe Premiere Pro
prFocus("timeline")
;Send ^!d ;this is to deselect any clips that might be selected in the timeline.
;tooltip, "now loading random text into the clipboard."
loadFromFile("clipTEXT.clp") ;to create this file, just highlight some plain text, copy it, and use insideclipboard.exe to save it as clipTEXT.clp. The clipboard MUST have some text inside; it CANNOT be completely empty. This has the effect of DELETING all the aspects of the clipboard, EXCEPT for text.
sleep 15
; ; WinActivate, Adobe Premiere Pro ;IDK if this is needed here.
; ; loadFromFile("clipTEXT.clp") ;The clipboard must be loaded twice, or it won't work about 70% of the time! I don't know why...
; ; sleep 15
;Autohotkey can now delete that string of text, so that no text is accidentlaly pasted into premiere. It doesn't seem to be able to delete EVERYTHING, so the above code is definitely necessary!
clipboard =
;The clipboard is now completely empty.
sleep 10
;tooltip, now pasting NOTHING into premiere....
WinActivate, Adobe Premiere Pro ;extremely important to ensure you are still active/focused on Premiere
SendInput, {Shift Down}{Shift Up}
sleep 10
SendInput, {Ctrl Down}{v Down} ;this is a MUCH more robust way of using the keyboard shortcuts to PASTE, rather than just using "Send ^v"
sleep 5
SendInput, {v Up}{Ctrl Up}
sleep 20
;It is necessary to PASTE this COMPLETELY BLANK clipboard into premiere, or Premiere won't "know" that the clipboard has been completely emptied.
;If you don't do this, Premiere will just use whatever thing you had previously copied inside of Premiere.
clipboard =
;the above line is another method for clearing the clipboard that must also be done to ensure a totally empty clipboard
sleep 30
;tooltip, "clip" . %int% . ".clp" ;this code doesn't work
;tooltip, now preparing to paste %int%
;msgbox, %int%
WinActivate, Adobe Premiere Pro
loadFromFile("clip" . int . ".clp") ;now we are loading the previously saved clipboard file!
sleep 15
; ; loadFromFile("clip" . int . ".clp") ;This must be done twice, or it doesn't work! I don't know why!! :D ;ADENDUM - i tried it with only 1 load and NOW it IS working??? IDK why
; ; sleep 15
WinActivate, Adobe Premiere Pro ;this is extremely important.... otherwise, it will try to paste into the command prompt or something. You must ensure the correct program is pasted into.
; ; ; if (transition = 0)
; ; ; {
; ; ; target("v1", "off", "all", 5) ;this will disable all video layers, and enable only layer 5.
; ; ; tooltip, only layer 5 was turned on should be
; ; ; sleep 150
; ; ; }
tooltip, now PASTING into premiere...
WinActivate, Adobe Premiere Pro
SendInput, {Shift Down}{Shift Up}{Ctrl Down}{v Down}
sleep 5
SendInput, {v Up}{Ctrl Up}
sleep 10
;the below code doesn't work very well.
; sleep 100
;If (transition = 1){
; ;now if we want an accurate label colorwe have to DELETE what we just did, since none of the label colors will be correct due to a premiere bug.
; ;tooltip,,,gonna delete now,1
; tooltip,gonna delete now
; WinActivate, Adobe Premiere Pro
; prFocus("timeline")
; WinActivate, Adobe Premiere Pro
; SendInput, +{delete} ;ripple delete
; sleep 100
; ;now to paste again, now that the label colors have been loaded.
; ;REDO might also work. must test that.
; WinActivate, Adobe Premiere Pro
; prFocus("timeline")
; sleep 30
; SendInput, {Shift Down}{Shift Up}{Ctrl Down}{v Down}
; ClipWait, 0.50
; SendInput, {v Up}{Ctrl Up}
; sleep 10
;}
if (transition = 0)
target("v1", "on", "all")
sleep 10
; send ^{F9} ;toggle video tracks (hopefully off)
; send ^+{F9} ;toggle audio tracks (hopefully off)
tooltip,
Send, ^!{F11} ;this is to deselect any clips that might be selected in the timeline. WAS ctrl alt D. might be unreliable.
} ;end of recall Clipboard()
#ifwinactive ;everything below this line can happen in any application!
;;target() is a script to TARGET or UNTARGET any arbitrary track.
;it doesn't work well, and I don't really use it.
Target(v1orA1, onOff, allNoneSolo := 0, numberr := 0)
{
;tooltip, now in TARGET function
; BlockInput, on
; BlockInput, MouseMove
; MouseGetPos xPosCursor, yPosCursor
prFocus("timeline") ;brings focus to the timeline.
wrenchMarkerX := 400
wrenchMarkerY := 800 ;the upper left corner for where to begin searching for the timeline WRENCH and MARKER icons -- the only unique and reliable visual i can use for coordinates.
targetdistance := 98 ;Distance from the edge of the marker Wrench to the left edge of the track targeting graphics
CoordMode Pixel ;, screen ; IDK why, but it only works like this...
CoordMode Mouse, screen
;tooltip, starting
ImageSearch, xTime, yTime, wrenchMarkerX, wrenchMarkerY, wrenchMarkerX+600, wrenchMarkerY+1000, %A_WorkingDir%\timelineUniqueLocator2.png
if ErrorLevel = 0
{
;MouseMove, xTime, yTime, 0
;tooltip, where u at son. y %ytime% and x %xtime%
;do nothing. continue on.
xTime := xTime - targetdistance
;MouseMove, xTime, yTime, 0
}
else
{
tooltip, image search failed
goto resetTrackTargeter
}
;tooltip, continuing...
ImageSearch, FoundX, FoundY, xTime, yTime, xTime+100, yTime+1000, %A_WorkingDir%\%v1orA1%_unlocked_targeted_alone.png
if ErrorLevel = 1
ImageSearch, FoundX, FoundY, xTime, yTime, xTime+100, yTime+1000, %A_WorkingDir%\%v1orA1%_locked_targeted_alone.png
if ErrorLevel = 2
{
tippy("TARGETED v1 not found")
goto trackIsUntargeted
}
if ErrorLevel = 3
{
tippy("Could not conduct the TARGETED v1 search!")
goto resetTrackTargeter
}
if ErrorLevel = 0