Page 1 of 1

Very new and want to write a script but don't know how...

Posted: 30 Dec 2018, 13:27
by matthewd253
Hello, so i am very new to autohotkey. I also do not know much about scripts or any programing... I would like to create a script that types a word for instance " testing" and sends in x amount of time lets say like 20 times. Can someone help me with this...

Re: Very new and want to write a script but don't know how...

Posted: 30 Dec 2018, 14:05
by gregster
Welcome to the forum!
Have you worked through the beginner's tutorial? Your script seems quite doable with even basic knowledge...

Look into the commands loop, send and sleep... there are examples in the docs.

If it doesn't work, show the code you tried and explain what didn't work.

Re: Very new and want to write a script but don't know how...

Posted: 30 Dec 2018, 15:07
by matthewd253
The only thing i am not seeing anywhere is anything about looping...? i think those are the only other things i need.

Re: Very new and want to write a script but don't know how...

Posted: 30 Dec 2018, 15:13
by gregster
matthewd253 wrote:
30 Dec 2018, 15:07
The only thing i am not seeing anywhere is the symbol for enter, and anything about looping...? i think those are the only other things i need.
Look into the commands loop, send...
Send says:
Key Names: The following table lists the special keys that can be sent (each key name must be enclosed in braces):
[...]
{Enter} Enter key on the main keyboard
From the tutorial - section 3:
The gigantic table on the Send page shows pretty much every special key built-in to AHK. For example: {Enter} and {Space}.

Re: Very new and want to write a script but don't know how...

Posted: 30 Dec 2018, 15:14
by matthewd253
thank you, i just found the enter thing now im looking through loop. thank you!

Re: Very new and want to write a script but don't know how...

Posted: 30 Dec 2018, 15:24
by matthewd253
Okay so i am very confused with the whole loop thing....

Loop, 3

{^x::
Send, testing one {Enter}
}
return

This is what i have..... the loop wont work and i don't know what i did wrong...

Re: Very new and want to write a script but don't know how...

Posted: 30 Dec 2018, 15:26
by gregster
I assume you want to do this:

Code: Select all

^x::   		 ; Ctrl + x
Loop, 3
{
	Send, testing one {Enter}
}
return
The key combo has to go to the top of a hotkey definition.

Re: Very new and want to write a script but don't know how...

Posted: 30 Dec 2018, 15:33
by matthewd253
Yes!!! thank you, i just ran into a slight issue with it though.... it types to quickly so it sends it as
testing one
esting one
ting one.
how could i fix this?

Re: Very new and want to write a script but don't know how...

Posted: 30 Dec 2018, 15:36
by gregster
It is probably caused by the receiving application. Try other send modes, like Sendinput instead of send.

Re: Very new and want to write a script but don't know how...

Posted: 30 Dec 2018, 15:42
by matthewd253
Okay that worked, with the loop being three it only sent it twice. so i changed it to 10 and it sent it 6 times with it only messing the word up once. so getting very close here lol. what could be causing this issue??

Re: Very new and want to write a script but don't know how...

Posted: 30 Dec 2018, 15:46
by gregster
That's weird... where are you posting it?
Perhaps add a sleep between the lines...

Code: Select all

^x::   		 ; Ctrl + x
Loop, 10
{
	SendInput, testing one {Enter}
	sleep 50		; sleep 50 ms
}
return

Re: Very new and want to write a script but don't know how...

Posted: 30 Dec 2018, 15:47
by matthewd253
I posting it in a message on facebook. and okay ill try that.

Re: Very new and want to write a script but don't know how...

Posted: 30 Dec 2018, 15:49
by matthewd253
well i added the sleep but now it sent 7 times with two of them being 1 letter..
getting closer but also farther away.

Re: Very new and want to write a script but don't know how...

Posted: 30 Dec 2018, 16:00
by gregster
I don't use Facebook, I cannot check... perhaps some javascript is messing up the edit field on the website.
Someone else might chime in.

Re: Very new and want to write a script but don't know how...

Posted: 30 Dec 2018, 20:45
by matthewd253
hope so, i would like to figure this out.

Re: Very new and want to write a script but don't know how...

Posted: 02 Jan 2019, 12:00
by hymal7
you may need to define where this code will send the text to:
For example if it is a notepad, it goes like this:

Code: Select all

^x::   		 ; Ctrl + x
Loop, 10
{
	winactivate ahk_exe notepad.exe		;assuming you are sending this code to notepad. 
	SendInput, testing one {Enter}
	sleep 100		; sleep 50 ms
}
return
If it is in a specific location in a web browser, e.g. google chrome, then:

Code: Select all

^x::   		 ; Ctrl + x
Loop, 10
{
	winactivate ahk_exe chrome.exe		;assuming you are sending this code to chrome. 
	MouseClick, left, 250, 300		;sending left-click on x,y co-ordinates in the browser.
	SendInput, testing one {Enter}
	sleep 100		; sleep 50 ms
}
return
https://autohotkey.com/docs/commands/WinActivate.htm
https://autohotkey.com/docs/commands/MouseClick.htm