Jump to content
Sign in to follow this  
EchaniDrgn

Clipboard Script

Recommended Posts

EchaniDrgn

Here's a clipboard script that I wrote recently. Not allowed to post in the examples scripts forum, so I figured I'd ask for any suggestions here.

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, _

$COPY_PASTE_AREA_1, _

$COPY_PASTE_BUTTON_2, _

$COPY_PASTE_AREA_2, _

$COPY_PASTE_BUTTON_3, _

$COPY_PASTE_AREA_3, _

$COPY_PASTE_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_BUTTON, _

$TYPE_EDIT_BOX, _

$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_BUTTON, 0, 0, 1, 3);

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

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

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

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

PopulateGuiElement($COPY_PASTE_AREA_2, "CopyPasteArea2", "", $TYPE_EDIT_BOX, 1, 3, 4, 3);

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

PopulateGuiElement($COPY_PASTE_AREA_4, "CopyPasteArea4", "", $TYPE_EDIT_BOX, 1, 9, 4, 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_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 Else

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

EndSwitch

EndFunc

Func CopyPasteButtonX()

$targetGuiEnum = GuiCtrlIdToEnum(@GUI_CtrlId) + 1;

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

ToolTip("");

Return False;

EndIf

WEnd

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

Sleep(50);

ToolTip("ESC to cancel");

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

ToolTip("");

Return False;

EndIf

WEnd

Send("^v");

ToolTip("");

Return True;

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
EchaniDrgn

Basically this is a GUI with four edit boxes into which you place the text you want to be able to insert easily.

You click on the Grab button and it puts the text on the clipboard awaiting your click.

Click where you want the text inserted and it pastes it for you. I got this idea wishing that stupid clipboard in Word was better.

Any ideas?

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  

×