Help with sending an items from clipboard then sending keystrokes

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
fenyodoboz
Posts: 3
Joined: 01 Feb 2023, 10:20

Help with sending an items from clipboard then sending keystrokes

Post by fenyodoboz » 01 Feb 2023, 10:48

Searched for the solution for days but cant figure out how to do what i want altough im sure its super simple.

What i want the code do is this:

send tab 11 times
loop as many times as many lines are on the clipboard
(send Space
paste clipboard item #1
send tab 4 times
)

^e::
send {Tab 11},
Loop x
{send {space},
paste clipboard item #1
send {tab 4}
}

Heres an example:

text1
text2
text3
text4
text5

I want to be able to copy text1...text5 then when i hit my hotkey i want it to send space then insert text1, then send tab four times then send space then paste text2
The goal would be that it loops the above actions as many times as many lines are on the clipboard.

User avatar
mikeyww
Posts: 26599
Joined: 09 Sep 2014, 18:38

Re: Help with sending an items from clipboard then sending keystrokes

Post by mikeyww » 01 Feb 2023, 20:19

Welcome to this AutoHotkey forum!

Code: Select all

#Requires AutoHotkey v2.0
A_Clipboard := "
(
text1
text2
text3
text4
text5
)"

^e:: {
 Send '{Tab 11}'
 Loop Parse A_Clipboard, '`n', '`r'
  SendText ' ' A_LoopField '`t`t`t`t'
}

fenyodoboz
Posts: 3
Joined: 01 Feb 2023, 10:20

Re: Help with sending an items from clipboard then sending keystrokes

Post by fenyodoboz » 02 Feb 2023, 03:50

mikeyww wrote:
01 Feb 2023, 20:19
Welcome to this AutoHotkey forum!

Code: Select all

#Requires AutoHotkey v2.0
A_Clipboard := "
(
text1
text2
text3
text4
text5
)"

^e:: {
 Send '{Tab 11}'
 Loop Parse A_Clipboard, '`n', '`r'
  SendText ' ' A_LoopField '`t`t`t`t'
}

Thank you very much for your reply mikeyww!

When i tried to run the code it did not paste what i copied. Tried to add the tab and space press(es) i need but now im getting error when trying to run it from 2.02.

Here is the code:

Code: Select all

^e:: 
 Send '{Tab 11}'    ; This does not have to be looped, just has to be executed once when i press the hotkey
Loop (Send '{Space}'      ; this is the part till the end i want to loop.
Parse A_Clipboard, '`n', '`r'
  SendText ' ' A_LoopField '`t`t`t`t'
  Send '{Tab 4}')

What is the issue with this code now?


[Mod edit: Added [code][/code] tags. Please use them yourself when posting code.]

User avatar
boiler
Posts: 16768
Joined: 21 Dec 2014, 02:44

Re: Help with sending an items from clipboard then sending keystrokes

Post by boiler » 02 Feb 2023, 04:08

There are several issues in that few lines of code. It’s basically a mess to be honest. You can’t make up your own syntax. You can’t put the Send function on the same line as the loop. Parse doesn’t make sense on a line of its own. Indenting doesn’t group blocks of code and neither do parentheses. You don’t have braces to start and end your hotkey function as is required.

Don’t deviate from what mikeyww posted without understanding why, using the AHK documentation as a guide. Definitely don’t write code that has no basis from the documentation or examples you’ve seen.

User avatar
mikeyww
Posts: 26599
Joined: 09 Sep 2014, 18:38

Re: Help with sending an items from clipboard then sending keystrokes

Post by mikeyww » 02 Feb 2023, 07:53

Yeah, I agree with boiler.

I would back up here, too, to see if the posted script works. That tells you whether you have a working starting point.
When i tried to run the code it did not paste what i copied.
So you copied and pasted the complete (all lines) and exact script, and ran it, right, with no additional code? And it did not paste anything, such as into Notepad, right? So what actually happened?

My output is below.

Code: Select all

											 text1				 text2				 text3				 text4				 text5				
The v1 version is below.

Code: Select all

#Requires AutoHotkey v1.1.33
Clipboard := "
(
text1
text2
text3
text4
text5
)"

^e::
SendInput {Tab 11}
Loop Parse, Clipboard, "`n", "`r"
 SendInput % "{Text} " A_LoopField "`t`t`t`t"
Return

User avatar
boiler
Posts: 16768
Joined: 21 Dec 2014, 02:44

Re: Help with sending an items from clipboard then sending keystrokes

Post by boiler » 02 Feb 2023, 08:03

The interesting thing is that when I look at the comments in fenyodoboz’ code and the code itself to understand what was trying to be fixed, mikeyww’s code already did exactly those things.

fenyodoboz
Posts: 3
Joined: 01 Feb 2023, 10:20

Re: Help with sending an items from clipboard then sending keystrokes

Post by fenyodoboz » 10 Feb 2023, 10:13

Thank you very much for the help from both of you, I just tried the code in v1 and it seems like it does what I would like it to do, couldnt test it properly unfortunately because of lack of time.

Post Reply

Return to “Ask for Help (v1)”