Trying to create a gradual script (I think)

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
dombiskerem
Posts: 4
Joined: 12 May 2020, 04:11

Trying to create a gradual script (I think)

12 May 2020, 04:21

Hello im so new on ahk scripts and i am from Turkey so if i write something wrong please ignore.
I don't know how I can explain but to put it simply im trying write a step by step script.
I write something like this

1::
SendInput cvcv{enter}
Sleep 200
SendInput bitis{enter}
Sleep 1200
SendInput t/animdur{enter}
Sleep 500
SendInput t/l cc{space}{!}{space}vvv{enter}
return


I want to make this script step by step. So if I press 1 it will say "cvcv" and wait for another 1.When I press 1 again at any time I want it will say bitis. I want it to wait until I tell it to write the next line.

I hope I was able to explain my problem. I did research with my poor English, but when I could not make a conclusion I decided to open a topic. Thanks in advance :superhappy:
Rohwedder
Posts: 7625
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Trying to create a gradual script (I think)

12 May 2020, 05:10

Hallo,
try:

Code: Select all

1::
SendInput cvcv{enter}
KeyWait, 1
KeyWait, 1, d
SendInput bitis{enter}
KeyWait, 1
KeyWait, 1, d
SendInput t/animdur{enter}
KeyWait, 1
KeyWait, 1, d
SendInput t/l cc{space}{!}{space}vvv{enter}
return
BNOLI
Posts: 548
Joined: 23 Mar 2020, 03:55

Re: Trying to create a gradual script (I think)

12 May 2020, 05:18

Code: Select all


1::Send()

Send() {
    array := ["cvcv{enter}","bitis{enter}","t/animdur{enter}","t/l cc{space}{!}{space}vvv{enter}"]
    i++
    if (i > array.Length()) ? i := 1 : i := i
    SendInput % array[i]
}
Concept. Not tested.
Remember to use [code]CODE[/code]-tags for your multi-line scripts. Stay safe, stay inside, and remember washing your hands for 20 sec !
User avatar
boiler
Posts: 16925
Joined: 21 Dec 2014, 02:44

Re: Trying to create a gradual script (I think)

12 May 2020, 05:31

BNOLI wrote:
12 May 2020, 05:18

Code: Select all


1::Send()

Send() {
    array := ["cvcv{enter}","bitis{enter}","t/animdur{enter}","t/l cc{space}{!}{space}vvv{enter}"]
    i++
    if (i > array.Length()) ? i := 1 : i := i
    SendInput % array[i]
}
Concept. Not tested.
The ternary statement would be like this (it’s generally used in place of if, not in conjunction with it):

Code: Select all

     i := (i > array.Length()) ? 1 : i
You could also incorporate the increment of the variable into it to get rid of the separate i++ line.
ahketype
Posts: 191
Joined: 27 Oct 2016, 15:06
Location: Yorkshire, UK

Re: Trying to create a gradual script (I think)

12 May 2020, 05:36

Welcome dombiskerem. Your English is good enough, I think!
Rohwedder has given a good answer.
You can also make it just run once if you put ExitApp instead of Return (or there are other ways to control when and how a script runs - you might only want it happening on one window type, etc.).
Sorry, BNOLI, I tested your script and it doesn't move past cvcv. I tried moving the array initialization to auto-execute position and return, and then it didn't do anything. :D
User avatar
boiler
Posts: 16925
Joined: 21 Dec 2014, 02:44

Re: Trying to create a gradual script (I think)

12 May 2020, 05:47

ahketype wrote:
12 May 2020, 05:36
Sorry, BNOLI, I tested your script and it doesn't move past cvcv. I tried moving the array initialization to auto-execute position and return, and then it didn't do anything. :D
You might try it with the change I showed. And as I mentioned, the increment of i could be incorporated into the one line like this:

Code: Select all

i := 1

1::Send()

Send() {
    static array := ["cvcv{enter}","bitis{enter}","t/animdur{enter}","t/l cc{space}{!}{space}vvv{enter}"]
    SendInput % array[i]
    i := (i = array.Length()) ? 1 : i + 1
}
dombiskerem
Posts: 4
Joined: 12 May 2020, 04:11

Re: Trying to create a gradual script (I think)

12 May 2020, 05:49

Rohwedder wrote:
12 May 2020, 05:10
Hallo,
try:

Code: Select all

1::
SendInput cvcv{enter}
KeyWait, 1
KeyWait, 1, d
SendInput bitis{enter}
KeyWait, 1
KeyWait, 1, d
SendInput t/animdur{enter}
KeyWait, 1
KeyWait, 1, d
SendInput t/l cc{space}{!}{space}vvv{enter}
return
Thank u so much but i have a question. It works when I press 1 as you wrote, but my another line it like this : "3:: SendInput t/abindir{enter}". When i Press 2 times its working really fine.But in the third press of 1, it writes my abindir, which is my 3rd line, How can I solve this problem ?

I have another problem too, I wonder if I can reset this command line in the middle.
Rohwedder
Posts: 7625
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Trying to create a gradual script (I think)

12 May 2020, 05:49

another idea:

Code: Select all

1::
No++
Loop, Parse,% "
(
cvcv
bitis
t/animdur
t/l cc{space}{!}{space}vvv
)",`n
IF (No = Max:=A_Index)
	SendInput,%A_LoopField%{Enter}
No := Mod(No,Max)
Return
ahketype
Posts: 191
Joined: 27 Oct 2016, 15:06
Location: Yorkshire, UK

Re: Trying to create a gradual script (I think)

12 May 2020, 05:54

@boiler Nup, afraid not. Just doesn't seem to do anything. I'm not sure why.
ahketype
Posts: 191
Joined: 27 Oct 2016, 15:06
Location: Yorkshire, UK

Re: Trying to create a gradual script (I think)

12 May 2020, 05:59

Rohwedder wrote:
12 May 2020, 05:49
another idea:

Code: Select all

1::
No++
Loop, Parse,% "
(
cvcv
bitis
t/animdur
t/l cc{space}{!}{space}vvv
)",`n
IF (No = Max:=A_Index)
	SendInput,%A_LoopField%{Enter}
No := Mod(No,Max)
Return
:bravo: I suppose this might be better than your first because it's not sitting inside the hotkey block waiting for key-ups and key-downs? It's neat anyway.
BNOLI
Posts: 548
Joined: 23 Mar 2020, 03:55

Re: Trying to create a gradual script (I think)

12 May 2020, 06:03

You could also incorporate the increment of the variable into it to get rid of the separate i++ line.
That's great! Wasn't aware of that.
Sorry, BNOLI, I tested your script and it doesn't move past cvcv. I tried moving the array initialization to auto-execute position and return, and then it didn't do anything
Yep, the reason why I've labeled it as a concept, bc as I wasn't sure where to position the array (was initially set at the AutoExecute section as well), and if its content will work if used to handle keys. Thx for testing :thumbup:
Remember to use [code]CODE[/code]-tags for your multi-line scripts. Stay safe, stay inside, and remember washing your hands for 20 sec !
dombiskerem
Posts: 4
Joined: 12 May 2020, 04:11

Re: Trying to create a gradual script (I think)

12 May 2020, 06:13

ahketype wrote:
12 May 2020, 05:59
Rohwedder wrote:
12 May 2020, 05:49
another idea:

Code: Select all

1::
No++
Loop, Parse,% "
(
cvcv
bitis
t/animdur
t/l cc{space}{!}{space}vvv
)",`n
IF (No = Max:=A_Index)
	SendInput,%A_LoopField%{Enter}
No := Mod(No,Max)
Return
:bravo: I suppose this might be better than your first because it's not sitting inside the hotkey block waiting for key-ups and key-downs? It's neat anyway.
guys sorry but I don't think I can understand the language you speak :( Can someone say the working code please
dombiskerem
Posts: 4
Joined: 12 May 2020, 04:11

Re: Trying to create a gradual script (I think)

12 May 2020, 06:39

Guys thanks for cods its workin fine but im trying to write 31 {3}{1} like this but its write just 3 how can i fix that
ahketype
Posts: 191
Joined: 27 Oct 2016, 15:06
Location: Yorkshire, UK

Re: Trying to create a gradual script (I think)

12 May 2020, 07:01

@Rohwedder Waaaaaa? :o

I just realised I had no idea what Max:=A_Index was doing in there. I've found the maths function, Max(), but it doesn't mention that syntax. It looks like an ordinary variable, but can't be or it wouldn't loop, presumably, via the Mod() parameter No := Mod(No,Max).
ahketype
Posts: 191
Joined: 27 Oct 2016, 15:06
Location: Yorkshire, UK

Re: Trying to create a gradual script (I think)

12 May 2020, 07:04

Oh I think I see now - it is a normal variable, and it's assigned inside the conditional. I didn't realise you could do that.

At first I was reading it as IF (No = (Max=A_Index)), like that was testing the end of the array. :lolno:
Rohwedder
Posts: 7625
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Trying to create a gradual script (I think)

12 May 2020, 07:33

Max stores the number of lines so that No can be reset after the loop
with No := Mod(No,Max) if necessary.
User avatar
boiler
Posts: 16925
Joined: 21 Dec 2014, 02:44

Re: Trying to create a gradual script (I think)

12 May 2020, 08:06

ahketype wrote:
12 May 2020, 05:54
@boiler Nup, afraid not. Just doesn't seem to do anything. I'm not sure why.
Sorry, was writing from a mobile device. Just need to make i static. This does it:

Code: Select all

1::Send()

Send() {
	static i := 1
    static array := ["cvcv{enter}","bitis{enter}","t/animdur{enter}","t/l cc{space}{!}{space}vvv{enter}"]
    SendInput % array[i]
    i := (i = array.Length()) ? 1 : i + 1
}

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Anput, mikeyww and 208 guests