; TotalClipboard ; by Scott Mattes ; 2009-04-10 ; ; version 0.5 ; ; To keep a constant record of the last 99 clipboard uses and to allow the user to ; scroll through them and reuse them. The user can also designate any of the last ; 99 to be permanent. critical #persistent #SingleInstance #NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases. SendMode Input ; Recommended for new scripts due to its superior speed and reliability. SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory. DebugMsg( "===============================================" ) DebugMsg( "Autorun" ) DebugMsg( "Autorun - WorkingDir="a_WorkingDir ) menu, tray, icon, includes\TotalClipboard 32x32.ico, 1, 1 StringSplit, filename, a_ScriptName, . iniFile = %filename1%.ini ifnotexist, TempClips FileCreateDir, TempClips ifnotexist, PermClips FileCreateDir, PermClips LoadINI() LoadingClipboard = 0 ; to control adding to saved contents when copying a save content file back to the clipboard GetCurrentEntry() DebugMsg( "Autorun - TextOnly="TextOnly " MaxEntries="MaxEntries ) return #c:: ; ; build the GUI that lets the user scroll through the temp and perm rings ; ; the GUI defaults to showing the most current clipboard action and what number it is ; ; there are tabs for temp entries, perm entries ; DebugMsg( "==========" ) DebugMsg( "#c::" ) Gui, Add, Edit, x16 y16 w70 h20 gDisplayEntry Gui, Add, UpDown, x66 y16 w20 h20 vDisplayEntry Range1-99 Wrap, %CurrentEntry% gui, add, button, y16 gToClipboard, ToClipboard Gui, Add, Text, x16 y66, No file found for this entry! Gui, Add, Edit, x16 y66 w440 h290 vCurContentText Gui, Add, Picture, x16 y66 w440 h-1 vCurContentPict Gui, Show, Center h377 w477, TotalClipboard DebugMsg( "#c:: - Leaving" ) Return GuiClose: gui, destroy Return ToClipboard: DebugMsg( "==========" ) DebugMsg( "ToClipboard" ) DE = 0%DisplayEntry% StringRight, DE, DE, 2 ext := GetFileExt( DE ) filename = TempClips\temp%DE%.%ext% LoadingClipboard = 1 ifequal, ext, txt FileRead, clipboard, %filename% else ImageToClipboard( filename ) LoadingClipboard = 0 DebugMsg( "ToClipboard - Leaving" ) return GetCurrentEntry( ) { global CurrentEntry DebugMsg( "==========" ) DebugMsg( "GetCurrentEntry" ) loop, TempClips\*, 0, 0 { LastFile = %a_LoopFileName% LastFileExt = %a_LoopFileExt% } StringReplace, LastFile, LastFile, .%LastFileExt% StringRight, CurrentEntry , LastFile, 2 DebugMsg( "GetCurrentEntry - Leaving LastFile="LastFile " LastFileExt="LastFileExt " CurrentEntry="CurrentEntry ) return CurrentEntry + 0 } GetFileExt( num ) { loop, TempClips\temp%num%*, 0, 0 return a_LoopFileExt } DisplayEntry: ; ; when the entry number changes, ; - is the number ; - load the file that goes with it ; ; display either text or pictures ; ; vCurrentEntry ; DebugMsg( "==========" ) DebugMsg( "DisplayEntry" ) gui, submit DebugMsg( "DisplayEntry - DisplayEntry="DisplayEntry ) DE = 0%DisplayEntry% StringRight, DE, DE, 2 ext := GetFileExt( DE ) filename = TempClips\temp%DE%.%ext% ifexist, %filename% { ifequal, ext, txt { FileRead, CurContentText, %filename% guicontrol, move, CurContentText, w440 h290 guicontrol, , CurContentText, %CurContentText% guicontrol, move, CurContentPict, w1 h1 } else { guicontrol, move, CurContentPict, w-1 h290 guicontrol, , CurContentPict, %filename% guicontrol, move, CurContentText, w1 h1 } } else { guicontrol, move, CurContentText, w1 h1 guicontrol, move, CurContentPict, w1 h1 } gui, show DebugMsg( "DisplayEntry - Leaving - DE="DE " ext="ext " filename='"filename "' DisplayEntry="DisplayEntry ) return Printscreen:: DoPrintScreen( 0 ) return !Printscreen:: DoPrintScreen( 1 ) return DoPrintScreen( WhichCapture ) { ;global CurrentEntry global DebugMsg( "==========" ) DebugMsg( "DoPrintScreen" ) DebugMsg( "DoPrintScreen - WhichCapture="WhichCapture ) CurrentEntry := NextEntry() CE = 0%CurrentEntry% StringRight, CE, CE, 2 imagesavename = TempClips\temp%CE%.bmp ifexist, TempClips\temp%CE%* FileDelete, TempClips\temp%CE%* CaptureScreen( WhichCapture, false, imagesavename) DebugMsg( "DoPrintScreen - Leaving" ) } NextEntry() { global CurrentEntry DebugMsg( " ==========" ) DebugMsg( " NextEntry" ) CurrentEntry += 1 ifgreater, CurrentEntry, 99 CurrentEntry = 1 DebugMsg( " NextEntry - CurrentEntry="CurrentEntry ) DebugMsg( " ==========" ) return CurrentEntry } OnClipboardChange: DebugMsg( "==========" ) DebugMsg( "OnClipboardChange" ) DebugMsg( "OnClipboardChange - Clipboard data type="a_eventinfo ) ifequal, LoadingClipboard, 0 ; this event was NOT from putting a temp/perm content file into the clipboard { ifgreater, a_EventInfo, 0 ; clipboard is not empty { CurrentEntry := NextEntry() ifequal, a_EventInfo, 1 { content = %Clipboard% ext = .txt DebugMsg( "OnClipboardChange - a_EventInfo=1" ) } else { Content = %ClipboardAll% ext = .bmp DebugMsg( "OnClipboardChange - a_EventInfo=2" ) } ; save the clip to a file CE = 0%CurrentEntry% StringRight, CE, CE, 2 ifexist, TempClips\temp%CE%* FileDelete, TempClips\temp%CE%* FileAppend, %Content%, TempClips\temp%CE%%ext% DebugMsg( "OnClipboardChange - Content="Content ) } } DebugMsg( "OnClipboardChange - Leaving" ) return LoadINI() ; ; if the ini doesn't exist, create it with default values ; ; [preferences] ; TextOnly=No ; ; [pointers] ; MaxEntries=99 ; ; read the ini values ; { global iniFile global TextOnly global MaxEntries DebugMsg( " ==========" ) DebugMsg( " LoadINI" ) DebugMsg( " LoadINI - iniFile="iniFile ) ifnotexist, %iniFile% { DebugMsg( " LoadINI - create the ini file" ) FileAppend, Created: %a_YYYY%-%a_mm%-%a_DD% %a_Hour%:%a_Min%:%a_Sec%`n`n, %iniFile% iniWrite, No, %iniFile%, preferences, TextOnly FileAppend, %a_space%, %inifile% iniWrite, 99, %iniFile%, pointers, MaxEntries } DebugMsg( " LoadINI - reading ini file" ) iniRead, TextOnly, %iniFile%, preferences, TextOnly iniRead, MaxEntries, %iniFile%, pointers, MaxEntries DebugMsg( " LoadINI - TextOnly="TextOnly " MaxEntries="MaxEntries ) DebugMsg( " LoadINI - Leaving" ) DebugMsg( " ==========" ) } #ifwinactive, TotalClipboard ESC:: gui, destroy DebugMsg( iText ) { OutputDebug, TotalClipboard: %iText% }