Pasting Clipboard loop

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
AutoHelpKey
Posts: 7
Joined: 28 Sep 2022, 08:50

Pasting Clipboard loop

Post by AutoHelpKey » 28 Sep 2022, 09:00

I have been trying different methods for a while to solve an issue (see below code)
I have a task that I need to select an email, pasted it into a box, press enter and then repeat.

Unfortunately I can't type all the required emails into the submit box at once, and autohotkey seems to be typing too quickly for some methods to work.
If required, I can put the emails into an array for a method to work, but obviously I want to streamline the task as much as possible.

I want to basically select all emails, copy to clipboard, click on the box I need to paste to, then press function button, pastes first email then pause for a few seconds for the program to update before moving into the next email in the clipboard.

As an example:
So I would copy the following to clipboard (ctrl C)
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]

then function button (windows b for example)
paste [email protected]
press enter
pause for loading

paste [email protected]
paste press enter
pause for loading

paste [email protected]
press enter
pause for loading

paste [email protected]
press enter
pause for loading

paste [email protected]
press enter
pause for loading

Please let me know of any ideas you may have. I've been playing around with this for a while.


/*

Code: Select all

#b::
Loop, parse, clipboard 
 { 
    send %A_LoopField%
			if (A_LoopField == ".com") ;will add other domains once working
				Send {Enter}
		sleep, 30          ;delay in ms 

  } 
Return

Code: Select all

#b::
cellArray := ["[email protected]",
"[email protected]",
"[email protected]",
"[email protected]",
"[email protected]",]

for i, element in cellArray ; Read all elements of cellArray
{
  MsgBox, Yes, the element belongs to the array. %i%, %element% ; Message + Number and element as info
  cell := cellArray[i+1] ; Pick next element
  MsgBox, %cell% ; Show next element in a message box
}
return
*/

/*

Code: Select all

#b::
myCopiedClipboard := Trim(clipboard)
Sleep, 100
linesInArraySeperatedbyNewLine := []

Loop, Parse, myCopiedClipboard, `n, `r
	if Trim(A_LoopField)
		linesInArraySeperatedbyNewLine.Push(A_LoopField)

MsgBox, % linesInArraySeperatedbyNewLine.MaxIndex()
; Just testing to see how many lines I read in

Loop, 1
	{
	Send, %myCopiedClipboard% 
	Sleep, 1000
	Send, {ENTER 2} ; separator
	}

Return
*/

Rohwedder
Posts: 7645
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Pasting Clipboard loop

Post by Rohwedder » 28 Sep 2022, 09:47

Hallo,
try:

Code: Select all

ClipBoard =
(
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
)
#b::
SetKeyDelay, 100, 100
Loop, parse, clipboard, `n, `r
{
	SendEvent,% A_LoopField
	SendEvent, {Enter}
	Sleep, 1000
}

Lepes
Posts: 141
Joined: 06 May 2021, 07:32
Location: Spain

Re: Pasting Clipboard loop

Post by Lepes » 28 Sep 2022, 10:04

There is not a fixed way to do any programming task. Each people thinks in a different way so there are too many solutions. I like the first one, there was only missing the last parameter that makes cut the string when if find a `ror may be `n

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.


/*
text to be present on clipboard before exectuing:
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]


*/


;#b::
Loop, parse, clipboard , "`n"
 { 
    MsgBox, % A_LoopField
    ;send %A_LoopField%
			if (A_LoopField == ".com") ;will add other domains once working
				Send {Enter}
		sleep, 30          ;delay in ms 

  } 
Return

AutoHelpKey
Posts: 7
Joined: 28 Sep 2022, 08:50

Re: Pasting Clipboard loop

Post by AutoHelpKey » 29 Sep 2022, 03:08

Hi guys,
Thank you for your help
The following (with the advice of Lepes) seems to work.

Code: Select all

;#b::
Loop, parse, clipboard , "`n"
 { 
    ;MsgBox, % A_LoopField
    send %A_LoopField%
			if (A_LoopField == ".com") ;will add other domains once working
				Send {Enter}
		sleep, 1000          ;delay in ms 

  } 
Return
What is confusing though is why. I'd like to understand rather than just hope it doesn't go wrong.
The loop still works and copies and enters all clipboard contents, even if it does not end with a .com

If somebody wants to test:
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]

AHKStudent
Posts: 1472
Joined: 05 May 2018, 12:23

Re: Pasting Clipboard loop

Post by AHKStudent » 29 Sep 2022, 03:31

AutoHelpKey wrote:
29 Sep 2022, 03:08
Hi guys,
Thank you for your help
The following (with the advice of Lepes) seems to work.

Code: Select all

;#b::
Loop, parse, clipboard , "`n"
 { 
    ;MsgBox, % A_LoopField
    send %A_LoopField%
			if (A_LoopField == ".com") ;will add other domains once working
				Send {Enter}
		sleep, 1000          ;delay in ms 

  } 
Return
What is confusing though is why. I'd like to understand rather than just hope it doesn't go wrong.
The loop still works and copies and enters all clipboard contents, even if it does not end with a .com

If somebody wants to test:
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
because you have this

Code: Select all

send %A_LoopField%

Post Reply

Return to “Ask for Help (v1)”