How to ignore function in a function? Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
fona
Posts: 65
Joined: 07 Apr 2022, 06:43

How to ignore function in a function?

Post by fona » 06 Apr 2023, 20:45

Dear friends,

I created a small function video1 to use it with pause so I can can do some stuff manually like this:

Code: Select all

F5::
video1()
{
SendInput {b}
SendInput {s} 
Pause3("RAlt")
Sleep, 50
SendInput {a} 
SendInput {s} 
}

Pause3(key) {
Loop
   {
   Sleep 100
   } Until GetKeyState(key,"P")
}
Return

Then I use the function "video1" again but I want it to ignore the function pause3 and just send keys without pause. Such an option without pause would be useful for my workflow. Is it possible somehow? Thanks in advance

Code: Select all

i::
        ;///////new project/////
video1()

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

Re: How to ignore function in a function?  Topic is solved

Post by mikeyww » 06 Apr 2023, 20:50

Hello,

Defining a function does not call the function. (EDIT: corrected by gregster below.)

Code: Select all

#Requires AutoHotkey v1.1.33

F5::video1("RAlt")
F6::video1()

video1(key := "") {
 Send bs
 If (key != "")
  KeyWait % key, D
 Sleep 50
 Send as
}
Last edited by mikeyww on 06 Apr 2023, 22:02, edited 1 time in total.

gregster
Posts: 9111
Joined: 30 Sep 2013, 06:48

Re: How to ignore function in a function?

Post by gregster » 06 Apr 2023, 21:50

To be fair, there is smth like a function hotkey (or hotkey function ? ;) ). That's what we have in F5:: in the original code.
Last edited by gregster on 06 Apr 2023, 21:56, edited 1 time in total.
Reason: Edit: Removed smth incorrect.

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

Re: How to ignore function in a function?

Post by mikeyww » 06 Apr 2023, 22:00

I stand corrected! I forgot that it was there in v1.

fona
Posts: 65
Joined: 07 Apr 2022, 06:43

Re: How to ignore function in a function?

Post by fona » 06 Apr 2023, 22:13

mikeyww wrote:
06 Apr 2023, 20:50
Hello,

Defining a function does not call the function. (EDIT: corrected by gregster below.)

Code: Select all

#Requires AutoHotkey v1.1.33

F5::video1("RAlt")
F6::video1()

video1(key := "") {
 Send bs
 If (key != "")
  KeyWait % key, D
 Sleep 50
 Send as
}
Thank you Mikey. Should I try this (my real code is actually too large) or you mean you have made a mistake here? :|

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

Re: How to ignore function in a function?

Post by mikeyww » 06 Apr 2023, 22:20

The code is fine. My description of calling a function was inaccurate in the case of the function hotkey as gregster has cited.

The answer to your question is that a function can have optional parameters, described here.

https://www.autohotkey.com/docs/v1/Functions.htm#optional

This enables some function calls to use the parameter, while others do not. The function can then assess whether the parameter is present, and how to handle it. In your function, you can use this feature to pass the "pause key" (key for which to wait) to the function as a parameter.

For completeness, the equivalent function hotkey is provided below.

Code: Select all

#Requires AutoHotkey v1.1.33
F5::video1("RAlt")
F6::
 video1(key := "") {
  Send bs
  If (key != "")
   KeyWait % key, D
  Sleep 50
  Send as
 }

fona
Posts: 65
Joined: 07 Apr 2022, 06:43

Re: How to ignore function in a function?

Post by fona » 06 Apr 2023, 22:44

mikeyww wrote:
06 Apr 2023, 22:20
The code is fine. My description of calling a function was inaccurate in the case of the function hotkey as gregster has cited.

The answer to your question is that a function can have optional parameters, described here.

https://www.autohotkey.com/docs/v1/Functions.htm#optional

This enables some function calls to use the parameter, while others do not. The function can then assess whether the parameter is present, and how to handle it. In your function, you can use this feature to pass the "pause key" (key for which to wait) to the function as a parameter.

For completeness, the equivalent function hotkey is provided below.

Code: Select all

#Requires AutoHotkey v1.1.33
F5::video1("RAlt")
F6::
 video1(key := "") {
  Send bs
  If (key != "")
   KeyWait % key, D
  Sleep 50
  Send as
 }
It works! Thank you so much Michael. You have always been helpful here :salute:

Post Reply

Return to “Ask for Help (v1)”