The MultiPaste.ahk script discussion starts with the blog "Brute Force Data-Set Copy-and-Paste (AutoHotkey Clipboard Technique)."
Many Windows users will find this AutoHotkey script handy for copying data-sets and breaking them up into component parts for pasting into form fields. You can use the app to copy and parse portions of Web tables, groups of cells in a spreadsheet, single-line street addresses, and many other blocks of data—then insert those items into individual fields in another window.
After selecting a section of a page (left-click, hold, and drag), activate the Hotkey combination CTRL+ALT+F to open a MsgBox window displaying the parsed components. The MsgBox remains always-on-top while you move to your input screen.
Next, in the destination window, select the target input field and press the Hotkey combination CTR:+ALT+WIN+W to activate the AutoHotkey Input command. You have five seconds to press one of the number keys (0-9). AutoHotkey inserts the text located next to the pressed number key in the MsgBox into the selected field. Or, merely press the recently added corresponding Hotkey ALT+1 through ALT+0 for direct paste.
This script parses text in the Windows Clipboard based upon the tab (`t) character, newlines (`r and `n), commas in single-line addresses, plus US and UK postal codes, for placement in the variable array listed in the MsgBox. This script works in a wide variety of situations—although some Web formatting may limit its results.
September 19, 2019, Added temporary Hotkeys (ALT+1 through ALT+0) which directly paste the corresponding items in the MsgBox. Hotkeys deactivate after closing the "Multi Paste" MsgBox window.
Code: Select all
^!F:: ; Hotkey combination CTRL+ALT+F
OldClipboard := ClipboardAll
Clipboard = ;clears the Clipboard
SendInput, ^c
ClipWait 0 ; pause for Clipboard data
If ErrorLevel
{
MsgBox, Error message for non-selection
}
; Replace all new paragraph marks with tabs for parsing
Clipboard := StrReplace(Clipboard, "`r`n" , "`t")
; Just in case the data-set includes a stray `r or`n
Clipboard := StrReplace(Clipboard, "`r" , "`t")
Clipboard := StrReplace(Clipboard, "`n" , "`t")
; For single-line addresses replace commas
Clipboard := StrReplace(Clipboard, "`, " , "`t")
; To parse US zip codes
Clipboard := RegExReplace(Clipboard, "\s(\d\d\d\d\d)", "`t$1")
; To parse UK postal codes
Clipboard := RegExReplace(Clipboard, "\s([A-Za-z][A-Za-z]?\d\w?)", "`t$1")
; Designed to removes excess tabs, replaced this loop with the one-line RegEx
; which follows. Loop doesn't work if a space appears between tabs—the
; RegEx does.
; Loop
; {
; Clipboard := StrReplace(Clipboard, "`t`t" , "`t")
; If ! InStr(Clipboard, "`t`t")
; Break
; }
Clipboard := RegExReplace(Clipboard, "`t\s*`t" , "`t")
; Sparse data-set
Transaction := StrSplit(Clipboard , "`t", , MaxParts := -1) ; [v1.1.28}
; Display MsgBox always-on-top (4096) for pasting into target fields
; Word-wrapped using line continuation techniques
MsgBox, 4096,Multi Paste , % "[1] " . Transaction[1] . "`r"
. "[2] " . Transaction[2] . "`r"
. "[3] " . Transaction[3] . "`r"
. "[4] " . Transaction[4] . "`r"
. "[5] " . Transaction[5] . "`r"
. "[6] " . Transaction[6] . "`r"
. "[7] " . Transaction[7] . "`r"
. "[8] " . Transaction[8] . "`r"
. "[9] " . Transaction[9] . "`r"
. "[0] " . Transaction[10]
Clipboard := OldClipboard
Return
^!#w::
Input, SingleKey, L2 T5, ,1,2,3,4,5,6,7,8,9,0
; Special action for date fields
If SingleKey = 0
SingleKey := 10
; Check for date format to parse
If (Transaction[SingleKey] ~= "\d\d?[/\-.]\d\d?[/\-.]\d\d(\d\d)?")
{
If InStr(Transaction[SingleKey],"/")
date := StrSplit(Transaction[SingleKey],"/")
If InStr(Transaction[SingleKey],"-")
date := StrSplit(Transaction[SingleKey],"-")
If InStr(Transaction[SingleKey],".")
date := StrSplit(Transaction[SingleKey],".")
SendInput, % date[1]
SendInput, /
SendInput, % date[2]
SendInput, /
SendInput, % date[3]
; msgbox, % date[1] date[2] date[3]
; For date field tabbing use the following:
; SendInput, % date[1] . "`t" . date[2] . "`t" . date[3]
}
Else If SingleKey != ""
SendInput, % Transaction[SingleKey]
Return
#IfWinExist Multi Paste
!1::SendInput, % Transaction[1]
!2::SendInput, % Transaction[2]
!3::SendInput, % Transaction[3]
!4::SendInput, % Transaction[4]
!5::SendInput, % Transaction[5]
!6::SendInput, % Transaction[6]
!7::SendInput, % Transaction[7]
!8::SendInput, % Transaction[8]
!9::SendInput, % Transaction[9]
!0::SendInput, % Transaction[10]
#IfWinExist