HeartlessS Usurer
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
|
SawBones.au3 source
Code:
#cs ----------------------------------------------------------------------------
This program is free software; you can redistribute it and/or modify it under any terms terms you like.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Use at you own risk.
#ce ----------------------------------------------------------------------------
; SawBones v1.09 by StainlessS ... compiled with AutiIt v3.3.14.5
#include <MsgBoxConstants.au3>
#include <Misc.au3>
Opt("MustDeclareVars", 1)
;;;
Global Const $Version = "SawBones v1.09"
Global Const $APP_NAME = "SawBones.Exe"
Global Const $APP_INI = "SawBones.ini"
Global Const $Watching = " SawBones is WATCHING "
Global Const $APPTitle = "VirtualDub2" ; VirtualDub2 matches as "VirtualDub2" with traiiling "Build number" on title bar.
Global Const $ScriptTitle = "VirtualDub2 Script Editor" ; VirtualDub2 Script Editor Window
Global Const $ScriptControl = "[CLASS:Scintilla; INSTANCE:1]"
Global Const $VdFrameNo = "[CLASS:Edit; INSTANCE:1]" ; Frame Indicator box (bottom middle of window, just above status line)
Global Const $VDRange = "[CLASS:msctls_statusbar32; INSTANCE:1]" ; Frame Range (bottom Left of window, 'Selecting Frames...' when range selected)
;
; CAN CHANGE below "Notepad" and "Edit" to change editor, use AutoIt Au3Info program to get names (try 1st with NotePad.exe to see how to use it).
Global Const $EdTitle = "[CLASS:Notepad]" ; NotePad Window name.
Global Const $EditControl = "[CLASS:Edit; INSTANCE:1]" ; NotePad text editor window control.
;
;
Global Const $Doze = 250
Global Const $ShowCntLimit = 3000 / $Doze ; Show 'Sawbones is WATCHING' for about 3 secs
Global $InAPP = False
Global $ShowCnt = 0
Global $HotkeyMods= 0
; SAVED to / GOTTEN from ini file
Global $USER_RangeEndIsExclusive=0 ; 0=Avisynth, 1=VDub : Will Get from SawBones.ini if exists
; User keys, change and re-build executable (Quite difficult to find keys that are not used by VirtualDub or System and available on international keyboards)
Global $USER_Comment="QWERTY_UK"
;
; Get some defaults from ini file (if exists).
$USER_RangeEndIsExclusive = Int(IniRead(@ScriptDir & "\" & $APP_INI, "Default", "RangeEndIsExclusive", $USER_RangeEndIsExclusive))
$USER_Comment = IniRead(@ScriptDir & "\" & $APP_INI, "UserComment", "Comment", $USER_Comment)
Global Const $AllKeys = 34
Global const $KeyName = 0
Global const $KeyDefault = 1
Global const $KeyFuncName = 2
Global const $KeyUserSet = 3
Global $KEYS[$AllKeys][4] = [ _
["KEY_TerminateProgram", "^+!{PAUSE}", "Fn_Terminate", ""], _
["KEY_DeleteFrame", "^{DELETE}", "Fn_DeleteFrame", ""], _
["KEY_DeleteRange", "^+{DELETE}", "Fn_DeleteRange", ""], _
["KEY_CopyFrameFromSourcePrevious", "^{F1}", "Fn_CopyFromPrev", ""], _
["KEY_CopyFrameFromSourceNext", "^{F2}", "Fn_CopyFromNext", ""], _
["KEY_ReplaceFrameWith_FX1", "^{1}", "Fn_DigitKey_C_1", ""], _
["KEY_ReplaceFrameWith_FX2", "^{2}", "Fn_DigitKey_C_2", ""], _
["KEY_ReplaceFrameWith_FX3", "^{3}", "Fn_DigitKey_C_3", ""], _
["KEY_ReplaceFrameWith_FX4", "^{4}", "Fn_DigitKey_C_4", ""], _
["KEY_ReplaceFrameWith_FX5", "^{5}", "Fn_DigitKey_C_5", ""], _
["KEY_ReplaceFrameWith_FX6", "^{6}", "Fn_DigitKey_C_6", ""], _
["KEY_ReplaceFrameWith_FX7", "^{7}", "Fn_DigitKey_C_7", ""], _
["KEY_ReplaceFrameWith_FX8", "^{8}", "Fn_DigitKey_C_8", ""], _
["KEY_ReplaceFrameWith_FX9", "^{9}", "Fn_DigitKey_C_9", ""], _
["KEY_ReplaceRangeWith_FX1", "^+{1}", "Fn_DigitKey_CS_1", ""], _
["KEY_ReplaceRangeWith_FX2", "^+{2}", "Fn_DigitKey_CS_2", ""], _
["KEY_ReplaceRangeWith_FX3", "^+{3}", "Fn_DigitKey_CS_3", ""], _
["KEY_ReplaceRangeWith_FX4", "^+{4}", "Fn_DigitKey_CS_4", ""], _
["KEY_ReplaceRangeWith_FX5", "^+{5}", "Fn_DigitKey_CS_5", ""], _
["KEY_ReplaceRangeWith_FX6", "^+{6}", "Fn_DigitKey_CS_6", ""], _
["KEY_ReplaceRangeWith_FX7", "^+{7}", "Fn_DigitKey_CS_7", ""], _
["KEY_ReplaceRangeWith_FX8", "^+{8}", "Fn_DigitKey_CS_8", ""], _
["KEY_ReplaceRangeWith_FX9", "^+{9}", "Fn_DigitKey_CS_9", ""], _
["KEY_Interpolate_1", "^+!{1}", "Fn_Interp_1", ""], _
["KEY_Interpolate_2", "^+!{2}", "Fn_Interp_2", ""], _
["KEY_Interpolate_3", "^+!{3}", "Fn_Interp_3", ""], _
["KEY_Interpolate_4", "^+!{4}", "Fn_Interp_4", ""], _
["KEY_Interpolate_5", "^+!{5}", "Fn_Interp_5", ""], _
["KEY_Interpolate_6", "^+!{6}", "Fn_Interp_6", ""], _
["KEY_Interpolate_7", "^+!{7}", "Fn_Interp_7", ""], _
["KEY_Interpolate_8", "^+!{8}", "Fn_Interp_8", ""], _
["KEY_Interpolate_9", "^+!{9}", "Fn_Interp_9", ""], _
["KEY_InterpolateRange", "^+!{/}", "Fn_InterpRange", ""], _
["KEY_NotepadSaveAndRefresh", "^+!{,}", "Fn_NotepadSave", ""]]
Local $i
for $i = 0 to $AllKeys - 1
$KEYS[$i][$KeyUserSet] = IniRead(@ScriptDir & "\" & $APP_INI, "UserKeys", $KEYS[$i][$KeyName], $KEYS[$i][$KeyDefault])
if $KEYS[$i][$KeyDefault] <> $KEYS[$i][$KeyUserSet] Then
$HotkeyMods = $HotkeyMods + 1
Endif
Next
;
If _Singleton($APP_NAME, 1) = 0 Then
MsgBox($MB_SYSTEMMODAL, "Warning", "An occurrence of " & $APP_NAME & " is already running")
Exit
EndIf
OnAutoItExitRegister("Fn_AtExit") ; Whatever cleanup to do on termination
; Delete the INI file.
FileDelete(@ScriptDir & "\" & $APP_INI)
; Update ini file.
IniWrite(@ScriptDir & "\" & $APP_INI, "Default", "COMMENT_1", " : " & $Version)
IniWrite(@ScriptDir & "\" & $APP_INI, "Default", "COMMENT_2", " : RangeEndIsExclusive: 0 = Avisynth : 1 = VirtualDub")
IniWrite(@ScriptDir & "\" & $APP_INI, "Default", "RangeEndIsExclusive", $USER_RangeEndIsExclusive)
IniWrite(@ScriptDir & "\" & $APP_INI, "UserKeys", "COMMENT_1", " : Accelerator keys:- CTRL=^ ALT=! SHIFT=+ WINDOWS=#")
IniWrite(@ScriptDir & "\" & $APP_INI, "UserKeys", "COMMENT_2", " : Accelerators before key characters eg '^{a}' not '{a}^'")
IniWrite(@ScriptDir & "\" & $APP_INI, "UserKeys", "COMMENT_3", " : Wrap the character part (excluding ^+!#) in curly braces eg {1} for key 1")
IniWrite(@ScriptDir & "\" & $APP_INI, "UserKeys", "COMMENT_4", " : Use Lowercase for alphabetic keys eg {a} not {A}")
IniWrite(@ScriptDir & "\" & $APP_INI, "UserKeys", "COMMENT_5", " : Where multiple characters on same keyboard key, use the lower one.")
IniWrite(@ScriptDir & "\" & $APP_INI, "UserKeys", "COMMENT_6", " : eg CTRL/SHIFT/ALT/a = '^+!{a}' and CTRL/F1 = '^{F1}'")
IniWrite(@ScriptDir & "\" & $APP_INI, "UserKeys", "COMMENT_7", " : Hotkeys must not be in use by system nor by VirtualDub2 main window.")
IniWrite(@ScriptDir & "\" & $APP_INI, "UserKeys", "COMMENT_8", " : More=http://www.autoitscript.com/autoit3/docs/functions/Send.htm")
IniWrite(@ScriptDir & "\" & $APP_INI, "UserKeys", "COMMENT_9", " : More=http://www.autoitscript.com/autoit3/docs/functions/HotKeySet.htm")
IniWrite(@ScriptDir & "\" & $APP_INI, "UserKeys", "COMMENT10", " : Count of currently modified HotKeys = " & $HotkeyMods)
; Update User set Keys in ini file.
for $i = 1 to $AllKeys - 1
IniWrite(@ScriptDir & "\" & $APP_INI, "UserKeys", $KEYS[$i][$KeyName], $KEYS[$i][$KeyUserSet] )
Next
IniWrite(@ScriptDir & "\" & $APP_INI, "UserComment", "Comment", $USER_Comment )
;;; Done updating ini file
; CTRL+SHIFT+ALT+PAUSE {PAUSE aka BREAK} is TERMINATE Program (or close via System Tray icon)
HK_Set($KEYS[0][$KeyUserSet],$KEYS[0][$KeyFuncName],$KEYS[0][$KeyName])
; Main Program Loop
Do
If Not $InAPP Then
If WinActive($APPTitle) And WinExists($EdTitle) Then
Bind() ; Make HotKeys active
$InAPP = True
EndIf
Else
If Not WinActive($APPTitle) Or Not WinExists($EdTitle) Then
UnBind() ; Deactivate Hotkeys
$InAPP = False
EndIf
EndIf
Sleep($Doze)
If $ShowCnt > 0 Then
$ShowCnt = $ShowCnt - 1
If $ShowCnt = 0 Then
ToolTip("") ; Display time expired, Switch off "SawBones is WATCHING"
EndIf
EndIf
Until (1+1 <> 2) ; 4E4, ... for a long time.
;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;
Func HK_Set($HK, $Fn,$KN="")
Local $OK
if HotKeySet($HK, $Fn) = 0 then
Local $tHK
if $KN = "" then
$tHK=$HK
Else
$tHK=$KN & "=" & $HK
endif
MsgBox($MB_SYSTEMMODAL, "SawBones Error", "Hotkey '" & $tHK & "' Could not be set" & @CRLF & "Perhaps already in use by system" & @CRLF & "Sawbones Exits")
Exit(1)
EndIf
EndFunc
Func Bind()
local $i
for $i = 1 to $AllKeys -1
HK_Set($KEYS[$i][$KeyUserSet],$KEYS[$i][$KeyFuncName],$KEYS[$i][$KeyName])
Next
Local $W = @CRLF & $Watching & @CRLF & @CRLF & " HotKeys Changed = " & $HotkeyMods & " " & @CRLF
if $USER_RangeEndIsExclusive <> 0 Then
$W = $W & @CRLF & " --- Range End Is Exclusive --- " & @CRLF
EndIf
if $USER_Comment <> "" Then
$W = $W & @CRLF & " User Comment = " & $USER_Comment & " " & @CRLF
EndIf
$ShowCnt = $ShowCntLimit
ToolTip($W)
EndFunc
Func UnBind()
ToolTip("") ; switch off tooltips.
$ShowCnt = 0
; Disable HotKeys
local $i
for $i = 1 to $AllKeys - 1
HotKeySet($KEYS[$i][$KeyUserSet])
Next
EndFunc
Func Fn_AtExit()
HotKeySet($KEYS[0][$KeyUserSet]) ; Disable Program Terminate Hotkey
UnBind()
EndFunc
Func Fn_Terminate()
Exit 0; Goodbye cruel world. ; Will call Fn_AtExit to clean up (assuming OnAutoItExitRegister registered to Fn_AtExit)
EndFunc
;;;;;;;;;;;;;;;;
Func Fn_DeleteFrame()
Local $Frm=GetFrameNo()
if $Frm <> "" Then
ControlSend($EdTitle, "", $EditControl, "DEL " & $Frm, 1) ; Send DEL Frame Number RAW
ControlSend($EdTitle, "", $EditControl, "{ENTER}", 0) ; Send ENTER key, 1 line down. COOKED
endif
EndFunc
Func Fn_DeleteRange()
Local $Rng=GetRange()
if $Rng <> "" Then
ControlSend($EdTitle, "", $EditControl, "DEL " & $Rng, 1) ; Send DEL Range (might be Only FrameNo) RAW
ControlSend($EdTitle, "", $EditControl, "{ENTER}", 0) ; Send ENTER key, 1 line down. COOKED
endif
EndFunc
Func Fn_CopyFromPrev()
Local $Frm=GetFrameNo()
if $Frm <> "" Then
$Frm = Int($Frm)
if $Frm==0 Then
ToolTip("Cannot CopyFromPrevious at Frame 0")
$ShowCnt = $ShowCntLimit * 2
Beep(500,50)
Else
ControlSend($EdTitle, "", $EditControl, "CP " & $Frm, 1) ; Send CP Frame Number RAW
ControlSend($EdTitle, "", $EditControl, "{ENTER}", 0) ; Send ENTER key, 1 line down. COOKED
EndIf
endif
EndFunc
Func Fn_CopyFromNext()
Local $Frm=GetFrameNo()
if $Frm <> "" Then
ControlSend($EdTitle, "", $EditControl, "CN " & $Frm, 1) ; Send CN Frame Number RAW
ControlSend($EdTitle, "", $EditControl, "{ENTER}", 0) ; Send ENTER key, 1 line down. COOKED
endif
EndFunc
;;;;;;;;;;;
Func Fn_DigitKey_C_1() ; CTRL/1 : FX1 Frame
FX_Key(False,1)
EndFunc
Func Fn_DigitKey_C_2() ; CTRL/2 : FX2 Frame
FX_Key(False,2)
EndFunc
Func Fn_DigitKey_C_3() ; CTRL/3 : FX3 Frame
FX_Key(False,3)
EndFunc
Func Fn_DigitKey_C_4() ; CTRL/4 : FX4 Frame
FX_Key(False,4)
EndFunc
Func Fn_DigitKey_C_5() ; CTRL/5 : FX5 Frame
FX_Key(False,5)
EndFunc
Func Fn_DigitKey_C_6() ; CTRL/6 : FX6 Frame
FX_Key(False,6)
EndFunc
Func Fn_DigitKey_C_7() ; CTRL/7 : FX7 Frame
FX_Key(False,7)
EndFunc
Func Fn_DigitKey_C_8() ; CTRL/8 : FX8 Frame
FX_Key(False,8)
EndFunc
Func Fn_DigitKey_C_9() ; CTRL/9 : FX9 Frame
FX_Key(False,9)
EndFunc
;;;;;;;;;;
Func Fn_DigitKey_CS_1() ; CTRL/SHIFT/1 : FX1 Range
FX_Key(True,1)
EndFunc
Func Fn_DigitKey_CS_2() ; CTRL/SHIFT/2 : FX2 Range
FX_Key(True,2)
EndFunc
Func Fn_DigitKey_CS_3() ; CTRL/SHIFT/3 : FX3 Range
FX_Key(True,3)
EndFunc
Func Fn_DigitKey_CS_4() ; CTRL/SHIFT/4 : FX4 Range
FX_Key(True,4)
EndFunc
Func Fn_DigitKey_CS_5() ; CTRL/SHIFT/5 : FX5 Range
FX_Key(True,5)
EndFunc
Func Fn_DigitKey_CS_6() ; CTRL/SHIFT/6 : FX6 Range
FX_Key(True,6)
EndFunc
Func Fn_DigitKey_CS_7() ; CTRL/SHIFT/7 : FX7 Range
FX_Key(True,7)
EndFunc
Func Fn_DigitKey_CS_8() ; CTRL/SHIFT/8 : FX8 Range
FX_Key(True,8)
EndFunc
Func Fn_DigitKey_CS_9() ; CTRL/SHIFT/9 : FX9 Range
FX_Key(True,9)
EndFunc
Func FX_Key($IsRange,$HKP)
if $HKP>=1 and $HKP<=9 Then
Local $Op="FX" & $HKP & " "
Local $Rng=""
if $IsRange Then
$Rng = GetRange()
else
$Rng = GetFrameNo()
EndIf
if $Rng <> "" Then
ControlSend($EdTitle, "", $EditControl, $Op & $Rng, 1) ; RAW
ControlSend($EdTitle, "", $EditControl, "{ENTER}", 0) ; Send ENTER key, 1 line down. COOKED
EndIf
EndIf
EndFunc
;;;;;;;;;;
Func Fn_Interp_1() ; CTRL/SHIFT/ALT/1 : Interpolate 1 frame
InterpNum(1)
EndFunc
Func Fn_Interp_2() ; CTRL/SHIFT/ALT/2 : Interpolate 2 frame
InterpNum(2)
EndFunc
Func Fn_Interp_3() ; CTRL/SHIFT/ALT/3 : Interpolate 3 frame
InterpNum(3)
EndFunc
Func Fn_Interp_4() ; CTRL/SHIFT/ALT/4 : Interpolate 4 frame
InterpNum(4)
EndFunc
Func Fn_Interp_5() ; CTRL/SHIFT/ALT/5 : Interpolate 5 frame
InterpNum(5)
EndFunc
Func Fn_Interp_6() ; CTRL/SHIFT/ALT/6 : Interpolate 6 frame
InterpNum(6)
EndFunc
Func Fn_Interp_7() ; CTRL/SHIFT/ALT/7 : Interpolate 7 frame
InterpNum(7)
EndFunc
Func Fn_Interp_8() ; CTRL/SHIFT/ALT/8 : Interpolate 8 frame
InterpNum(8)
EndFunc
Func Fn_Interp_9() ; CTRL/SHIFT/ALT/9 : Interpolate 9 frame
InterpNum(9)
EndFunc
Continued @ post #6
Last edited by StainlessS; 17th April 2018 at 13:03.
Reason: Update
|