This repository has been archived by the owner on May 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
multiSlotCopyPaste.ahk
214 lines (169 loc) · 5.44 KB
/
multiSlotCopyPaste.ahk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
; This is a multi-slot copy/paste script for Windows.
;
; How-to:
; To store something in a specific slot, press: LEFT Control + LEFT WINDOWS + Numpad 1-9
; To recall something from a specific slot, press: LEFT Control + LEFT ALT + Numpad 1-9
; To restore last clipboard data, press: LEFT Control + LEFT ALT + Backspace
; To show all slots in a special GUI window, press: LEFT Control + LEFT ALT + Numpad 0
;
; You can still use usual Ctrl + c / Ctrl + v as you used to (for, text, files, images, ...).
; Other slots are intended for text only.
;
; Source: https://damogranlabs.com
; Date: 16.11.2018
; Version: 1.2
#SingleInstance Force
#include displayGui.ahk
slotData := Object()
; COPY keys
<^<#Numpad1::
getSelectedText(1)
return
<^<#Numpad2::
getSelectedText(2)
return
<^<#Numpad3::
getSelectedText(3)
return
<^<#Numpad4::
getSelectedText(4)
return
<^<#Numpad5::
getSelectedText(5)
return
<^<#Numpad6::
getSelectedText(6)
return
<^<#Numpad7::
getSelectedText(7)
return
<^<#Numpad8::
getSelectedText(8)
return
<^<#Numpad9::
getSelectedText(9)
return
; PASTE
<^<!Numpad1::
pasteSelectedSlot(1)
return
<^<!Numpad2::
pasteSelectedSlot(2)
return
<^<!Numpad3::
pasteSelectedSlot(3)
return
<^<!Numpad4::
pasteSelectedSlot(4)
return
<^<!Numpad5::
pasteSelectedSlot(5)
return
<^<!Numpad6::
pasteSelectedSlot(6)
return
<^<!Numpad7::
pasteSelectedSlot(7)
return
<^<!Numpad8::
pasteSelectedSlot(8)
return
<^<!Numpad9::
pasteSelectedSlot(9)
return
; Store/restore clipboard content
$^c:: ; store clipboard before new clipboard is saved
storeClipboard()
return
<^<!BackSpace:: ; write old cached clipboard data to current clipboard
restoreClipboard()
return
<^<!Numpad0:: ; Show slots data in popup message window
printAllSlotsData()
return
; --------------------------------------------------------------------------------------------------------
; Functions
; --------------------------------------------------------------------------------------------------------
getSelectedText(slotIndex)
{ ; store current clipboard data, copy currently selected text, restore clipboard data
global slotData
currentClipboardData := ClipboardAll ; save clipboard contents
Clipboard := ; clear clipboard
Send ^c ; copy clipboard
ClipWait 1 ; wait for clipboard to contain data
slotData[slotIndex] := Clipboard ; get currently selected text
Clipboard := currentClipboardData ; restore original Clipboard contents
currentClipboardData := ; save the memory if the clipboard was very large
}
pasteSelectedSlot(slotIndex)
{ ; fast-print slot data: copy currently clipboard data, set clipboard data with slot data, paste, restore original clipboard data
global slotData
currentClipboardData := ClipboardAll ; save clipboard content
Clipboard := slotData[slotIndex] ; set clipboard
Send ^v ; paste clipboard
Sleep 100
Clipboard := currentClipboardData ; restore original Clipboard content
currentClipboardData = ; save the memory if the clipboard was very large
}
storeClipboard()
{ ; store clipboard data and issue 'copy' command
global slotData
slotData[10] := Clipboard
Send ^c ; copy clipboard
ClipWait 1 ; wait for clipboard to contain data
}
restoreClipboard()
{ ; write cached clipboard data back to clipboard
global slotData
Clipboard := slotData[10]
ClipWait 1
}
beautifySlotName(slotName, addLeadingNewLines:=True)
{ ; common function to add dashes and center text - used to separate slot name and slot data
totalLengthOfSlotName := 100
_numberOfSpaces := 2
lenOfSlotName := StrLen(slotName)
numberOfDashes := (totalLengthOfSlotName - lenOfSlotName - _numberOfSpaces)/2
loop % numberOfDashes
dashesString .= "-"
newSlotName := dashesString . " " . slotName . " " . dashesString . "`n" ; spaces number must match with _numberOfSpaces
if (addLeadingNewLines){
newSlotName := "`n`n" . newSlotName
}
return newSlotName
}
printAllSlotsData()
{ ; display non-empty slots data in ScrollBox Gui
global slotData
lastClipboard := beautifySlotName("Last clipboard", False) . slotData[10]
printData := lastClipboard
; print out only slots that are not empty
if (slotData[1]) {
printData .= beautifySlotName("Slot 1") . slotData[1]
}
if (slotData[2]) {
printData .= beautifySlotName("Slot 2") . slotData[2]
}
if (slotData[3]) {
printData .= beautifySlotName("Slot 3") . slotData[3]
}
if (slotData[4]) {
printData .= beautifySlotName("Slot 4") . slotData[4]
}
if (slotData[5]) {
printData .= beautifySlotName("Slot 5") . slotData[5]
}
if (slotData[6]) {
printData .= beautifySlotName("Slot 6") . slotData[6]
}
if (slotData[7]) {
printData .= beautifySlotName("Slot 7") . slotData[7]
}
if (slotData[8]) {
printData .= beautifySlotName("Slot 8") . slotData[8]
}
if (slotData[9]) {
printData .= beautifySlotName("Slot 9") . slotData[9]
}
ScrollBox(printData, "s f{s10} h600 w500", "Multi-Slot Copy Paste: non-empty slots")
}