Need to create a simple script, agree on a donation

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
mint45
Posts: 5
Joined: 28 Jan 2023, 09:00

Need to create a simple script, agree on a donation

Post by mint45 » 28 Jan 2023, 09:06

We need a very simple script:
1.Take one line from a text or file. There can be many such lines.
2. Insert
3. press enter
Repeat the loop.
Ready for a little donation :D

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

Re: Need to create a simple script, agree on a donation

Post by mikeyww » 28 Jan 2023, 09:47

Code: Select all

; This script pastes text from a file.
#Requires AutoHotkey v2.0
filePath := A_ScriptDir '\test.txt'
paste(filePath)

paste(filePath) {
 If FileExist(filePath)
  SendText FileRead(filePath)
 Else MsgBox 'File not found.`n`n' filePath, 'Error', 48
}

mint45
Posts: 5
Joined: 28 Jan 2023, 09:00

Re: Need to create a simple script, agree on a donation

Post by mint45 » 28 Jan 2023, 16:42

First of all, thank you very much for responding to help! :o :shock: :o

I need to insert text the way this script does. But now I need at least some way to specify where to insert this text. For example, to point the mouse and run the script on the button. Because running this script, it starts inserting text just at the moment of launching the script.

But the solution does work, I'm very happy watching what I can't apply. :superhappy: :superhappy: :superhappy:

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

Re: Need to create a simple script, agree on a donation

Post by mikeyww » 28 Jan 2023, 18:30

Code: Select all

; This script pastes text from a file.
#Requires AutoHotkey v2.0
filePath := A_ScriptDir '\test.txt'

F3::paste(filePath)

paste(filePath) {
 Static txt := "" ; Reuse the same text
 If txt = ""
  If FileExist(filePath)
   txt := FileRead(filePath)
  Else MsgBox 'File not found.`n`n' filePath, 'Error', 48
 SendText txt
}
Or:

Code: Select all

; This script pastes text from a file.
#Requires AutoHotkey v2.0
filePath := A_ScriptDir '\test.txt'

F3::paste(filePath)

paste(filePath) {
 If FileExist(filePath)
  SendText FileRead(filePath) ; Get the file's current text
 Else MsgBox 'File not found.`n`n' filePath, 'Error', 48
}
Explained: Introduction and simple examples

mint45
Posts: 5
Joined: 28 Jan 2023, 09:00

Re: Need to create a simple script, agree on a donation

Post by mint45 » 29 Jan 2023, 05:47

mikeyww wrote:
28 Jan 2023, 18:30

Code: Select all

; This script pastes text from a file.
#Requires AutoHotkey v2.0
filePath := A_ScriptDir '\test.txt'

F3::paste(filePath)

paste(filePath) {
 Static txt := "" ; Reuse the same text
 If txt = ""
  If FileExist(filePath)
   txt := FileRead(filePath)
  Else MsgBox 'File not found.`n`n' filePath, 'Error', 48
 SendText txt
}
Or:

Code: Select all

; This script pastes text from a file.
#Requires AutoHotkey v2.0
filePath := A_ScriptDir '\test.txt'

F3::paste(filePath)

paste(filePath) {
 If FileExist(filePath)
  SendText FileRead(filePath) ; Get the file's current text
 Else MsgBox 'File not found.`n`n' filePath, 'Error', 48
}
Explained: Introduction and simple examples
Great, that's 80% of what I need.
Can you tell me where it is more convenient for you to send the donate? I am in Ukraine and I have some difficulties with transfers. Write a convenient way for you and I will try to find a solution.

I have tested everything and I have two theses:
1. When the text is inserted, is enter pressed? I need to press enter after each line.
2. Is it possible to add a small pause after each submission ( pressing enter) ?

Thank you very much, we now have light on for +-3 hours a day and you have helped me a lot!

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

Re: Need to create a simple script, agree on a donation

Post by mikeyww » 29 Jan 2023, 06:17

Hello,

Update is below. Yes, the line feed is included. Feel free to test the script to confirm that.

Code: Select all

; This script pastes text from a file.
#Requires AutoHotkey v2.0
filePath := A_ScriptDir '\test.txt'

F3::paste(filePath, WAIT := 350)

paste(filePath, wait := 0) {  ; For each file line, paste text and line feed, with intervening delay
 If FileExist(filePath) {
  Loop Read filePath
   Sleep(wait * (A_Index > 1)), SendText(A_LoopReadLine '`n')
 } Else MsgBox 'File not found.`n`n' filePath, 'Error', 48
}
Thank you for your kind offer. Please save your funds for another time, or you can always donate to the AutoHotkey Foundation. I have no connection to it.

Best of luck!

mint45
Posts: 5
Joined: 28 Jan 2023, 09:00

Re: Need to create a simple script, agree on a donation

Post by mint45 » 29 Jan 2023, 08:49

screenshot.221.jpg
screenshot.221.jpg (52.58 KiB) Viewed 223 times
Perfect. Thank you!

Post Reply

Return to “Ask for Help (v1)”