First line in script works but the rest does not execute Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
M4verick
Posts: 193
Joined: 03 Nov 2020, 12:00

First line in script works but the rest does not execute

08 Feb 2024, 17:56

Here's my code:

Code: Select all

^+Right::Run, Firefox.exe https://github.com/yt-dlp/yt-dlp
Sleep, 3000
Send, !d
Sleep, 500
Send, {end}
SendInput, #installation{Enter}
It opens up the desired website but for some strange reason, the rest of the script is not executing. Any ideas?
User avatar
mikeyww
Posts: 27366
Joined: 09 Sep 2014, 18:38

Re: First line in script works but the rest does not execute  Topic is solved

08 Feb 2024, 18:11

Move the Run command to a new line below your hotkey. This will remove the implicit Return and allow the other statements to execute.

Hotkey subroutines typically end with a Return command. Without a Return or other control flow, the script will proceed to the next statement.

Example of a multi-statement hotkey subroutine
M4verick
Posts: 193
Joined: 03 Nov 2020, 12:00

Re: First line in script works but the rest does not execute

08 Feb 2024, 18:17

OK, first let me try to understand your statement:

"This will remove the implicit Return and allow the other statements to execute."

I don't follow. What does this mean exactly?
EDIT: nevermind - I see you edited your original comment.

EDIT 2: I still don't understand how this works. How does moving everything down to the next line below the hotkey make everything else work?

Secondly, I did as you instructed and everything is working.... but not quite. On the very last line of the code, it's not typing out the pound symbol (hashkey). Should I use SendRaw instead?

EDIT 3: I figured it out: I changed the very last line to:

Code: Select all

SendInput, {#}installation{Enter}
Last edited by M4verick on 08 Feb 2024, 18:33, edited 1 time in total.
User avatar
mikeyww
Posts: 27366
Joined: 09 Sep 2014, 18:38

Re: First line in script works but the rest does not execute

08 Feb 2024, 18:31

You'll want to read this section carefully.

Introduction and simple examples:
If a hotkey needs to execute only a single line, that line can be listed to the right of the double-colon. In other words, the return is implicit.
Next:
Should I use SendRaw instead?
How to find out, in two steps.

1. Run a script that uses SendRaw.

2. See if it works!

Enjoy!
M4verick
Posts: 193
Joined: 03 Nov 2020, 12:00

Re: First line in script works but the rest does not execute

08 Feb 2024, 18:39

OK so I can understand this better, I went back to my original script & tried to fix it a different way by using Return:

Code: Select all

^+Right::Run, Firefox.exe https://github.com/yt-dlp/yt-dlp
Sleep, 3000
Send, !d
Sleep, 500
Send, {end}
SendInput, {#}installation{Enter}
Return
Based on your first comment above saying that it's looking for a Return, I thought this would work, but it's not!
User avatar
mikeyww
Posts: 27366
Joined: 09 Sep 2014, 18:38

Re: First line in script works but the rest does not execute

08 Feb 2024, 19:03

Perhaps if I say this a different way, it will help.

1. Whenever a statement is listed on the same line as a hotkey, that statement is immediately followed by an implicit Return command.

2. Unlabeled code that follows a Return command is unreachable and will never execute.
M4verick
Posts: 193
Joined: 03 Nov 2020, 12:00

Re: First line in script works but the rest does not execute

08 Feb 2024, 19:10

OK I understand better now. Thanks.
GEV
Posts: 1005
Joined: 25 Feb 2014, 00:50

Re: First line in script works but the rest does not execute

08 Feb 2024, 23:02

From an older documentation:
To have more than one command executed by a hotkey, put the first line beneath the hotkey definition and make the last line a return.
For example:
...
That was easier to understand for beginners.

Why is that so?

Because
mikeyww wrote:
08 Feb 2024, 19:03
1. Whenever a statement is listed on the same line as a hotkey, that statement is immediately followed by an implicit Return command.

2. Unlabeled code that follows a Return command is unreachable and will never execute.
and
Without a Return or other control flow, the script will proceed to the next statement.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: balawi28, Chunjee, moltenchees and 278 guests