Sign in to follow this  
Followers 0
EchaniDrgn

Super Clipboard

7 posts in this topic

This is a little clipboard script I cobbled together because I hated using notepad for code scraps when I had to paste functions into multiple files. It's pretty easy to extend this script including adding buttons and adding clipboard rows.

Any suggestions?

CODE

#include <GUIConstants.au3>

#include <GUIConstantsEx.au3>

#include <WindowsConstants.au3>

#include <Misc.au3>

#Region GUI_CONSTANTS

Global $TITLE_STRING = "Super Clipboard by EchaniDrgn";

Global Const $BUTTON_HEIGHT = 20;

Global Const $BUTTON_WIDTH = 60;

Global Const $BUTTON_COLUMNS = 5;

Global Const $BUTTON_ROWS = 12;

Global Const $BORDER = 10;

Global Const $GUI_WINDOW_WIDTH = $BUTTON_WIDTH * $BUTTON_COLUMNS + $BORDER * 2;

Global Const $GUI_WINDOW_HEIGHT = $BUTTON_HEIGHT * $BUTTON_ROWS + $BORDER * 2;

Global Const $GUI_WINDOW_DEFAULT_X = Number(IniRead(@ScriptDir & "\SuperClipboard.ini", "Startup", "default_x", "-1"));

Global Const $GUI_WINDOW_DEFAULT_Y = Number(IniRead(@ScriptDir & "\SuperClipboard.ini", "Startup", "default_y", "-1"));

#EndRegion

#Region GLOBALS

Global Enum $MAIN_WINDOW, _

$COPY_PASTE_BUTTON_1, _

$DATA_SET_BUTTON_1, _

$COPY_PASTE_AREA_1, _

$COPY_PASTE_BUTTON_2, _

$DATA_SET_BUTTON_2, _

$COPY_PASTE_AREA_2, _

$COPY_PASTE_BUTTON_3, _

$DATA_SET_BUTTON_3, _

$COPY_PASTE_AREA_3, _

$COPY_PASTE_BUTTON_4, _

$DATA_SET_BUTTON_4, _

$COPY_PASTE_AREA_4, _

$GUI_LIST_SIZE;

Global Enum $GUI_NAME, _

$GUI_LABEL, _

$GUI_TYPE, _

$GUI_LEFT, _

$GUI_TOP, _

$GUI_HEIGHT, _

$GUI_WIDTH, _

$GUI_HANDLE, _

$GUI_ATTRIBUTES_LENGTH;

Global Enum $TYPE_COPY_PASTE_BUTTON, _

$TYPE_EDIT_BOX, _

$TYPE_DATA_SET_BUTTON, _

$TYPES_LENGTH;

Global $GUI_ARRAY[$GUI_LIST_SIZE][$GUI_ATTRIBUTES_LENGTH];

Global $dll = DllOpen("user32.dll")

#EndRegion

Main()

Func Main()

Setup()

While 1

Sleep(1000)

WEnd

EndFunc

; Support Functions ===================================================================================================

Func Setup()

Opt("GUIOnEventMode", 1) ; Change to OnEvent mode

PopulateGuiElement($COPY_PASTE_BUTTON_1, "CopyPasteButton1", "Grab", $TYPE_COPY_PASTE_BUTTON, 0, 0, 1, 3);

PopulateGuiElement($COPY_PASTE_BUTTON_2, "CopyPasteButton2", "Grab", $TYPE_COPY_PASTE_BUTTON, 0, 3, 1, 3);

PopulateGuiElement($COPY_PASTE_BUTTON_3, "CopyPasteButton3", "Grab", $TYPE_COPY_PASTE_BUTTON, 0, 6, 1, 3);

PopulateGuiElement($COPY_PASTE_BUTTON_4, "CopyPasteButton4", "Grab", $TYPE_COPY_PASTE_BUTTON, 0, 9, 1, 3);

PopulateGuiElement($DATA_SET_BUTTON_1, "DataSetButton1", "Put", $TYPE_DATA_SET_BUTTON, 1, 0, 1, 3);

PopulateGuiElement($DATA_SET_BUTTON_2, "DataSetButton2", "Put", $TYPE_DATA_SET_BUTTON, 1, 3, 1, 3);

PopulateGuiElement($DATA_SET_BUTTON_3, "DataSetButton3", "Put", $TYPE_DATA_SET_BUTTON, 1, 6, 1, 3);

PopulateGuiElement($DATA_SET_BUTTON_4, "DataSetButton4", "Put", $TYPE_DATA_SET_BUTTON, 1, 9, 1, 3);

PopulateGuiElement($COPY_PASTE_AREA_1, "CopyPasteArea1", "", $TYPE_EDIT_BOX, 2, 0, 3, 3);

PopulateGuiElement($COPY_PASTE_AREA_2, "CopyPasteArea2", "", $TYPE_EDIT_BOX, 2, 3, 3, 3);

PopulateGuiElement($COPY_PASTE_AREA_3, "CopyPasteArea3", "", $TYPE_EDIT_BOX, 2, 6, 3, 3);

PopulateGuiElement($COPY_PASTE_AREA_4, "CopyPasteArea4", "", $TYPE_EDIT_BOX, 2, 9, 3, 3);

GUICreate($TITLE_STRING, _

$GUI_WINDOW_WIDTH, _

$GUI_WINDOW_HEIGHT, _

$GUI_WINDOW_DEFAULT_X, _

$GUI_WINDOW_DEFAULT_Y);

GUISetOnEvent($GUI_EVENT_CLOSE, "Cleanup");

CreateGuis();

GUISetState(@SW_SHOW);

EndFunc

Func Cleanup()

Local $winPos = WinGetPos($TITLE_STRING);

IniWrite(@ScriptDir & "\SuperClipboard.ini", "Startup", "default_x", String($winPos[0]));

IniWrite(@ScriptDir & "\SuperClipboard.ini", "Startup", "default_y", String($winPos[1]));

WriteOutToFile($COPY_PASTE_AREA_1);

WriteOutToFile($COPY_PASTE_AREA_2);

WriteOutToFile($COPY_PASTE_AREA_3);

WriteOutToFile($COPY_PASTE_AREA_4);

DllClose($dll);

Exit;

EndFunc

Func WriteOutToFile(Const $guiEnum)

If FileExists(GuiEnumToFile($guiEnum)) Then FileDelete(GuiEnumToFile($guiEnum))

FileWrite(GuiEnumToFile($guiEnum), GUICtrlRead($GUI_ARRAY[$guiEnum][$GUI_HANDLE]));

EndFunc

Func GuiEnumToFile(Const $guiEnum)

Return @ScriptDir & "\" & $GUI_ARRAY[$guiEnum][$GUI_NAME] & ".txt";

EndFunc

Func PopulateGuiElement(Const $guiEnum, Const $name, Const $label, Const $guiType, Const $column, Const $row, Const $width = 1, Const $height = 1)

$GUI_ARRAY[$guiEnum][$GUI_NAME] = $name;

$GUI_ARRAY[$guiEnum][$GUI_LABEL] = $label;

$GUI_ARRAY[$guiEnum][$GUI_TYPE] = $guiType;

$GUI_ARRAY[$guiEnum][$GUI_LEFT] = ColumnToCoordinate($column);

$GUI_ARRAY[$guiEnum][$GUI_TOP] = RowToCoordinate($row);

$GUI_ARRAY[$guiEnum][$GUI_WIDTH] = $width * $BUTTON_WIDTH;

$GUI_ARRAY[$guiEnum][$GUI_HEIGHT] = $height * $BUTTON_HEIGHT;

EndFunc

Func ColumnToCoordinate(Const $column)

Return $BORDER + ($BUTTON_WIDTH * $column);

EndFunc

Func RowToCoordinate (Const $row)

Return $BORDER + ($BUTTON_HEIGHT * $row);

EndFunc

Func CreateGuis()

For $i = 0 to $GUI_LIST_SIZE - 1

CreateGuiFromArray($i);

Next

EndFunc

Func CreateGuiFromArray(Const $guiEnum)

Local $tempString = "";

Switch $GUI_ARRAY[$guiEnum][$GUI_TYPE]

Case $TYPE_EDIT_BOX

$GUI_ARRAY[$guiEnum][$GUI_HANDLE] = GUICtrlCreateEdit($GUI_ARRAY[$guiEnum][$GUI_LABEL], _

$GUI_ARRAY[$guiEnum][$GUI_LEFT], _

$GUI_ARRAY[$guiEnum][$GUI_TOP], _

$GUI_ARRAY[$guiEnum][$GUI_WIDTH], _

$GUI_ARRAY[$guiEnum][$GUI_HEIGHT]);

If FileExists(GuiEnumToFile($guiEnum)) Then

$tempString = FileRead(GuiEnumToFile($guiEnum));

GUICtrlSetData($GUI_ARRAY[$guiEnum][$GUI_HANDLE], $tempString);

FileDelete(GuiEnumToFile($guiEnum));

EndIf

Case $TYPE_COPY_PASTE_BUTTON

$GUI_ARRAY[$guiEnum][$GUI_HANDLE] = GUICtrlCreateButton($GUI_ARRAY[$guiEnum][$GUI_LABEL], _

$GUI_ARRAY[$guiEnum][$GUI_LEFT], _

$GUI_ARRAY[$guiEnum][$GUI_TOP], _

$GUI_ARRAY[$guiEnum][$GUI_WIDTH], _

$GUI_ARRAY[$guiEnum][$GUI_HEIGHT]);

GUICtrlSetOnEvent($GUI_ARRAY[$guiEnum][$GUI_HANDLE], "CopyPasteButtonX")

Case $TYPE_DATA_SET_BUTTON

$GUI_ARRAY[$guiEnum][$GUI_HANDLE] = GUICtrlCreateButton($GUI_ARRAY[$guiEnum][$GUI_LABEL], _

$GUI_ARRAY[$guiEnum][$GUI_LEFT], _

$GUI_ARRAY[$guiEnum][$GUI_TOP], _

$GUI_ARRAY[$guiEnum][$GUI_WIDTH], _

$GUI_ARRAY[$guiEnum][$GUI_HEIGHT]);

GUICtrlSetOnEvent($GUI_ARRAY[$guiEnum][$GUI_HANDLE], "DataSetButtonX")

Case Else

MsgBox(0, "Error", "Bad Type in CreateGuiFromArray");

EndSwitch

EndFunc

Func CopyPasteButtonX()

Local $targetGuiEnum = GuiCtrlIdToEnum(@GUI_CtrlId) + 2;

Local $tempString = ClipGet();

ClipPut(GUICtrlRead($GUI_ARRAY[$targetGuiEnum][$GUI_HANDLE]));

While(Not _IsPressed("01", $dll))

Sleep(50);

ToolTip("Click Location to paste" & @CR & "or select text to replace." & @CR & "Right-click to cancel.");

If _IsPressed("02", $dll) Then

ClipPut($tempString);

ToolTip("");

Return False;

EndIf

WEnd

While(_IsPressed("01", $dll))

Sleep(50);

ToolTip("ESC to cancel");

If _IsPressed("1B", $dll) Then

ClipPut($tempString);

ToolTip("");

Return False;

EndIf

WEnd

Send("^v");

ClipPut($tempString);

ToolTip("");

Return True;

EndFunc

Func DataSetButtonX()

Local $targetGuiEnum = GuiCtrlIdToEnum(@GUI_CtrlId) + 1;

GUICtrlSetData($GUI_ARRAY[$targetGuiEnum][$GUI_HANDLE], ClipGet());

EndFunc

Func GuiCtrlIdToEnum(Const $guiCtrlId)

For $i = 0 to $GUI_LIST_SIZE - 1

If $guiCtrlId = $GUI_ARRAY[$i][$GUI_HANDLE] Then Return $i

Next

Return -1;

EndFunc

Share this post


Link to post
Share on other sites



have it popup on hotkey, and don't have the put + grab... make it so clicking on an empty box puts, clicking on full box grabs...

thats just my personal taste though, something you probably do need is a clear box button... thats probably the most useful suggestion to you.

very nice idea though, I have a script that means on a hotkey it just creates a tempfile and opens it, not too good fo snippets, put OK for testing code.

Share this post


Link to post
Share on other sites

have it popup on hotkey, and don't have the put + grab... make it so clicking on an empty box puts, clicking on full box grabs...

thats just my personal taste though, something you probably do need is a clear box button... thats probably the most useful suggestion to you.

very nice idea though, I have a script that means on a hotkey it just creates a tempfile and opens it, not too good fo snippets, put OK for testing code.

Thanks for the suggestions, I think I'll toss them together. I was already thinking of doing the clear button, but getting rid of the grab and put buttons makes sense.

I was also thinking of making a small amount of what is to be pasted in the tooltip, but I don't want to muddy up the instructions on how to cancel out. Maybe I'll put that in anyways.

Thanks for the suggestions. :-)

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

I actually recently created a smaller and easier-to-use(in my opinion) program with a similar function. Basically, you press Ctrl+1 to "switch to clipboard 1", Ctrl+2 for "clipboard 2", etc. Each one acts like a separate clipboard, so if you opened clipboard 1 and copied "qwertyuiop", then switched to keyboard 3 and copied "ASDFGHJKL", Ctrl+v would paste "ASDFGHJKL". But if you switched back to clipboard 1, Ctrl+v would paste "qwertyuiop". No GUI, no complex stuff like that, and no Alt-Tabbing needed. I'll post it later, when I get on my home computer(right now I'm using a public one at my local library).

Edited by benzrf

Share this post


Link to post
Share on other sites

Ok, this is it.

CODE
#cs ----------------------------------------------------------------------------

AutoIt Version: 3.3.0.0

Author: myName

Script Function:

Template AutoIt script.

#ce ----------------------------------------------------------------------------

; Script Start - Add your code below here

#Include <Array.au3>

#Include <Clipboard.au3>

Global $curclip

Global $cliplist[10]

$curclip = 1

$cliplist[0] = ""

$cliplist[1] = ClipGet()

$cliplist[2] = ""

$cliplist[3] = ""

$cliplist[4] = ""

$cliplist[5] = ""

$cliplist[6] = ""

$cliplist[7] = ""

$cliplist[8] = ""

$cliplist[9] = ""

HotKeySet("^c", "set")

HotKeySet("^x", "setx")

HotKeySet("^0", "set0")

HotKeySet("^1", "set1")

HotKeySet("^2", "set2")

HotKeySet("^3", "set3")

HotKeySet("^4", "set4")

HotKeySet("^5", "set5")

HotKeySet("^6", "set6")

HotKeySet("^7", "set7")

HotKeySet("^8", "set8")

HotKeySet("^9", "set9")

While 1

Sleep(100)

WEnd

Func set()

HotKeySet("^c")

Send("^c")

$cliplist[$curclip] = ClipGet()

HotKeySet("^c", "set")

EndFunc

Func setx()

HotKeySet("^x")

Send("^x")

$cliplist[$curclip] = ClipGet()

HotKeySet("^x", "setx")

EndFunc

Func set0()

$curclip = 0

_ClipBoard_SetData($cliplist[0])

EndFunc

Func set1()

$curclip = 1

_ClipBoard_SetData($cliplist[1])

EndFunc

Func set2()

$curclip = 2

_ClipBoard_SetData($cliplist[2])

EndFunc

Func set3()

$curclip = 3

_ClipBoard_SetData($cliplist[3])

EndFunc

Func set4()

$curclip = 4

_ClipBoard_SetData($cliplist[4])

EndFunc

Func set5()

$curclip = 5

_ClipBoard_SetData($cliplist[5])

EndFunc

Func set6()

$curclip = 6

_ClipBoard_SetData($cliplist[6])

EndFunc

Func set7()

$curclip = 7

_ClipBoard_SetData($cliplist[7])

EndFunc

Func set8()

$curclip = 8

_ClipBoard_SetData($cliplist[8])

EndFunc

Func set9()

$curclip = 9

_ClipBoard_SetData($cliplist[9])

EndFunc

Share this post


Link to post
Share on other sites

How do you paste?

Um... With Ctrl+v...

Or were you talking to EchaniDrgn?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0