Code doesn't run twice

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
omar
Posts: 545
Joined: 22 Oct 2015, 17:56

Code doesn't run twice

04 Dec 2023, 10:19

I have a small snippet of code that doesn't run the second time it's called:

Code: Select all

::]test::
my_string = "*&^`%$£-+=!<>#@:"
Random, char, 0, strlen(my_string)
result := SubStr(my_string, char, 1)

SendInput {#}{space}

Loop, 20
{
    SendInput, % result
}

Sleep 100
SendInput {enter}{enter}{enter}{enter}

Sleep 100

SendInput {#}{space}

Loop, 20
{
    SendInput, % result
}

Return
I'm scratching my head. I can't figure out the problem. When I test different parts of the code, it works fine.

Hoping someone can tell me where I'm going wrong.

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

Re: Code doesn't run twice

04 Dec 2023, 10:28

Hallo,
here it works as often as I trigger it.
omar
Posts: 545
Joined: 22 Oct 2015, 17:56

Re: Code doesn't run twice

04 Dec 2023, 10:33

Hmm, weird

I've run 3 times and this is the output I get:

Code: Select all

# @@@@@@@@@@@@@@@@@@@@



# @@@@@@@@@@@@@@@@@@@@

# ££££££££££££££££££££



# ££££££££££££££££££££

# 



# 

It failed the 3rd time. Have you tried running say 5/6 times?

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

Re: Code doesn't run twice

04 Dec 2023, 10:39

Perhaps?: Replace:

Code: Select all

SendInput, % result
by:

Code: Select all

SendInput, {Text}%result%
omar
Posts: 545
Joined: 22 Oct 2015, 17:56

Re: Code doesn't run twice

04 Dec 2023, 11:16

Oooh!
That worked :bravo:
Crazy and weird
What do you think was happening?
And why did that solve the problem?

Big thanks
Rohwedder
Posts: 7774
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Code doesn't run twice

04 Dec 2023, 11:30

https://www.autohotkey.com/docs/v1/lib/Send.htm
By default (that is, if neither SendRaw nor the Raw mode or Text mode is used), the characters ^+!#{} have a special meaning. …

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot], Mateusz53, MrHue, Pianist and 257 guests