Skip to content

Instantly share code, notes, and snippets.

@Pulover
Last active February 23, 2018 03:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save Pulover/6088602 to your computer and use it in GitHub Desktop.
Save Pulover/6088602 to your computer and use it in GitHub Desktop.
; Pulover's Clipboard History
#NoEnv
#SingleInstance force
#InstallKeybdHook
Menu, Tray, Add, Show Clipboard History, ShowHistory
Menu, Tray, Add, Options, Options
Menu, Tray, Add, Pause, PauseScript
Menu, Tray, Add, Exit, Exit
Menu, Tray, NoStandard
Menu, Tray, Default, Show Clipboard History
Menu, Tray, Icon, Shell32.dll, 261
ClipArray := Object()
ClipMax := 50
MenuMax := 10
NoChange := 1
OnClipboardChange:
If NoChange = 1
{
SetTimer, Change, -100
return
}
If Clipboard =
return
ClipArray.Insert(1, Clipboard)
Goto, Update
return
Change:
NoChange := 0
return
#^NumpadAdd::
ShowHistory:
Gui 1:+LastFoundExist
IfWinExist
{
WinActivate
Goto, Update
}
Gui +Resize +AlwaysOnTop
Gui, Add, Button, Default gCopy, Copy
Gui, Add, Button, x+10 gDelete, Delete
Gui, Add, Button, x+10 gClear, Clear History
Gui, Add, Button, x+10 gOptionsButton, Options
Gui, Add, ListView, xm r21 w300 -Multi vClipHistory gClipHistory, Index|Content
GuiControl, -Redraw, ClipHistory
for index, element in ClipArray
LV_Add("", Index, Element)
GuiControl, +Redraw, ClipHistory
LV_ModifyCol(1, 40)
LV_ModifyCol(2, 240)
Gui, Show,, Clipboard History
return
OptionsButton:
Gui, 2:+owner1
Gui, 1:Default
Gui +Disabled
Options:
Gui, 2:Add, Text,, Maximum number of Clips:
Gui, 2:Add, Edit, xp+130 yp-2 Limit Number W80
Gui, 2:Add, UpDown, 0x80 Range0-999999 vClipMax, %ClipMax%
Gui, 2:Add, Text, xm, Maximum Clips in Menu:
Gui, 2:Add, Edit, xp+130 yp-2 Limit Number W80
Gui, 2:Add, UpDown, 0x80 Range0-999999 vMenuMax, %MenuMax%
Gui, 2:Add, Button, Section Default xm W60 H22 gOptOK, OK
Gui, 2:Add, Button, ys W60 H22 gOptCancel, Cancel
Gui, 2:Show,, Options
return
OptOK:
Gui, 2:Submit, NoHide
2GuiClose:
2GuiEscape:
OptCancel:
Gui 1:+LastFoundExist
IfWinExist
Gui, 1:-Disabled
Gui, 2:Destroy
return
ShowPasteMenu:
TotalItems := ClipArray.MaxIndex()
Loop, %MenuMax%
{
ThisMenu := SubStr(ClipArray[A_Index], 1, 50)
If ThisMenu =
break
Menu, ClipHistory, Add, %A_Index%: %ThisMenu%, Paste
}
Menu, ClipHistory, Add
Menu, ClipHistory, Add, Paste All, PasteAll
Menu, ClipHistory, Add, Reverse Order, Reverse
Menu, ClipHistory, Add, Clear All, Clear
Menu, ClipHistory, Add
Menu, ClipHistory, Add, Show All (%TotalItems%), ShowHistory
Menu, ClipHistory, Show
Menu, ClipHistory, DeleteAll
return
*^$Numpad1::
*^$Numpad2::
*^$Numpad3::
*^$Numpad4::
*^$Numpad5::
*^$Numpad6::
*^$Numpad7::
*^$Numpad8::
*^$Numpad9::
*^$Numpad0::
NoChange := 1
SelectedClip := RegExReplace(A_ThisHotkey, "\D")
If SelectedClip = 0
SelectedClip := 10
If GetKeyState("Alt", "P")
SelectedClip := SelectedClip +10
If (ClipArray[SelectedClip] = "")
{
NoChange := 0
return
}
Clipboard := ClipArray[SelectedClip]
Clipwait
Send ^v
return
Paste:
NoChange := 1
SelectedClip := RTrim(SubStr(A_ThisMenuItem, 1, 2), ":")
Clipboard := ClipArray[SelectedClip]
Clipwait
Send ^v
return
PasteAll:
NoChange := 1
AllClip := ""
For Index, Value in ClipArray
AllClip .= Value
If AllClip =
{
NoChange := 0
return
}
Clipboard := AllClip
Clipwait
Send ^v
return
Copy:
NoChange := 1
Gui, Submit, NoHide
If LV_GetCount("Selected") = 0
return
RowNumber := LV_GetNext(0)
LV_GetText(ArrayId, RowNumber, 1)
Clipboard := ClipArray[ArrayId]
return
Delete:
Gui, Submit, NoHide
If LV_GetCount("Selected") = 0
return
RowNumber := LV_GetNext(0)
ClipArray.Remove(RowNumber)
GoSub, Update
return
Clear:
ClipArray := Object()
ClipAllArray := Object()
Update:
ClipCount := ClipArray.MaxIndex()
If (ClipCount > ClipMax)
ClipArray.Remove(ClipCount, ClipCount)
LV_Delete()
GuiControl, -Redraw, ClipHistory
For Index, Element in ClipArray
LV_Add("", Index, Element)
GuiControl, +Redraw, ClipHistory
return
Reverse:
ReverseArray(ClipArray)
GoSub, Update
return
ReverseArray(ByRef Array)
{
Count := Array.MaxIndex() +1
For Index, Value in Array
Value%A_Index% := Array[Index]
For Index, Value in Array
Array[Count - Index] := Value%A_Index%
}
GuiClose:
GuiEscape:
Gui, Destroy
return
GuiSize:
If A_EventInfo = 1
return
GuiWidth := A_GuiWidth
GuiHeight := A_GuiHeight
GuiControl, Move, ClipHistory, % "W" GuiWidth-20 "H" GuiHeight-45
return
ClipHistory:
If A_GuiEvent = DoubleClick
GoSub, Copy
return
PauseScript:
Suspend
Pause
return
Exit:
ExitApp
; #########################################################
*$RButton::
MouseExtras("ShowPasteMenu")
return
$AppsKey::
MouseExtras("ShowPasteMenu")
return
; MouseExtras
; Author: Pulover [Rodolfo U. Batista]
; rodolfoub@gmail.com
/*
- Allows to use subroutines for Holding and Double Clicking a Mouse Button.
- Keeps One-Click and Drag functions.
- Works with combinations, i.e. LButton & RButton.
Usage:
Assign the function to the Mouse Hotkey and input the Labels to
trigger with GoSub and wait times in the parameters:
MouseExtras("HoldSub", "DoubleSub", "HoldTime", "DClickTime", "Button")
HoldSub: Button Hold Label.
HoldTime: Wait Time to Hold Button (miliseconds - optional).
DoubleSub: Double Click Label.
DClickTime: Wait Time for Double Click (seconds - optional).
Button: Choose a different Button (optional - may be useful for combinations).
- If you don't want to use a certain function put "" in the label.
- I recommend using the "*" prefix to allow them to work with modifiers.
- Note: Althought it's designed for MouseButtons it will work with Keyboard as well.
*/
MouseExtras(HoldSub, HoldTime="200", DoubleSub="", DClickTime="0.2", Button="")
{
If Button =
Button := A_ThisHotkey
Button := LTrim(Button, "~*$")
If InStr(Button, "&")
Button := RegExReplace(Button, "^.*&( +)?")
MouseGetPos, xpos
Loop
{
MouseGetPos, xposn
If (A_TimeSinceThisHotkey > HoldTime)
{
If IsLabel(HoldSub)
GoSub, %HoldSub%
Else
{
Send {%Button% Down}
KeyWait, %Button%
Send {%Button% Up}
}
return
}
Else
If (xpos <> xposn)
{
Send {%Button% Down}
KeyWait, %Button%
Send {%Button% Up}
return
}
Else
If !GetKeyState(Button, "P")
{
If !IsLabel(DoubleSub)
{
Send {%Button%}
return
}
KeyWait, %Button%, D T%DClickTime%
If ErrorLevel
Send {%Button%}
Else
{
If IsLabel(DoubleSub)
GoSub, %DoubleSub%
Else
Send {%Button%}
}
return
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment