Replacing native parameters with a single parameter Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
paik1002
Posts: 355
Joined: 28 Nov 2015, 02:45

Replacing native parameters with a single parameter

19 Jan 2019, 12:40

Is it possible to substitute the parameters of native AHK functions/commands with a single custom parameter that joins the native parameters into one set?
Is it possible to use some kind of a label(?) for combining the native parameters?
Please refer to the following code:


WinTitle := "Notepad++"
WinText := "Selected"
ExcludeTitle := "hello"
ExcludeText := "bye"

ParametersCombined = WinTitle,WinText,ExcludeTitle,ExcludeText

if WinExist(ParametersCombined)
{
WinActivate, ParametersCombined
msgbox % WinTitle " is activated!"
}
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Replacing native parameters with a single parameter

19 Jan 2019, 13:07

why do u need to do any of this?
what problem does this solve
coffee
Posts: 133
Joined: 01 Apr 2017, 07:55

Re: Replacing native parameters with a single parameter

19 Jan 2019, 13:12

https://autohotkey.com/docs/Functions.htm#Variadic

Since this will probably have to be stated, wrap commands in a function and do.
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Replacing native parameters with a single parameter  Topic is solved

19 Jan 2019, 15:17

Like this:

Code: Select all

ParametersCombined := [WinTitle,WinText,ExcludeTitle,ExcludeText]
if WinExist(ParametersCombined*)
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
paik1002
Posts: 355
Joined: 28 Nov 2015, 02:45

Re: Replacing native parameters with a single parameter

20 Jan 2019, 01:01

jeeswg wrote:
19 Jan 2019, 15:17
Like this:

Code: Select all

ParametersCombined := [WinTitle,WinText,ExcludeTitle,ExcludeText]
if WinExist(ParametersCombined*)

Code: Select all

WinActivate, %ParametersCombined%
WinGetTitle, OutputVar, %ParametersCombined%
msgbox % OutputVar " is activated!"
Genius indeed!
Now my code will become much more manageable and less cluttersome.
I added the above lines of code for AHK commands.

FYI, AHK has issues picking up wintext on Notepad++, but your code seems to work fine with Internet Explorer.

I tested the code below like this:
1. open IE with https://www.autohotkey.com/boards/ (background or minimized)
2. open another instance of IE with www.google.com (must be active!)
3. run this hotkey

This will activate the IE window with https://www.autohotkey.com/boards/ but not viceversa.

Code: Select all

WinTitle := "Internet Explorer"
WinText := ""
ExcludeTitle := "Google"
ExcludeText := ""

ParametersCombined := [WinTitle,WinText,ExcludeTitle,ExcludeText]

If WinExist(ParametersCombined*)
{
    WinActivate, %ParametersCombined%
    WinGetTitle, OutputVar, %ParametersCombined%
    msgbox % OutputVar " is activated!"
}
Last edited by paik1002 on 20 Jan 2019, 02:38, edited 6 times in total.
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Replacing native parameters with a single parameter

20 Jan 2019, 01:16

- It seems coffee was right. Well done coffee.
coffee wrote:Since this will probably have to be stated, wrap commands in a function and do.
- The technique won't work on commands, so this may be of interest:
commands as functions (AHK v2 functions for AHK v1) - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=37&t=29689
- For your example, this should work, because when you do WinExist, that will set that window as the Last Found Window, and when no window title is specified, WinActivate will use the Last Found Window.

Code: Select all

if WinExist(ParametersCombined*)
{
	WinActivate
	msgbox % WinTitle " is activated!"
}
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
paik1002
Posts: 355
Joined: 28 Nov 2015, 02:45

Re: Replacing native parameters with a single parameter

20 Jan 2019, 01:47

Please refer to my comment above.
I added a working code that includes commands such as WinActivate and WinGetTitle.
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Replacing native parameters with a single parameter

20 Jan 2019, 02:11

- But it might *seem* to be working. I would suppose that by trying to pass an object to a command in that way, you are passing a blank string.
- You have to use the object in a function, and you must use the asterisk: *.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
paik1002
Posts: 355
Joined: 28 Nov 2015, 02:45

Re: Replacing native parameters with a single parameter

20 Jan 2019, 02:32

Yes, I just had to get it confirmed.
Indeed this technique does not work with commands.
Thank you.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: robodesign and 251 guests