passing parameter with hotstring

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
GS SAHU
Posts: 37
Joined: 29 Sep 2014, 12:18

passing parameter with hotstring

12 Feb 2017, 12:00

i want to pass parameter with hotstring.
as : when i type hello world
call hello hot string and pass world as parameter. i can pass any word in place of world

Code: Select all

::hello::
xyz(%1%)
{
msgbox %1% //show in message world
}
return
how to use parameter for passing.
Guest

Re: passing parameter with hotstring

12 Feb 2017, 12:06

Code: Select all

::hello::
	xyz(Trim(A_ThisHotkey,":"))
return

xyz(in)
	{
	 msgbox %in% //show in message world
	}
GS SAHU
Posts: 37
Joined: 29 Sep 2014, 12:18

Re: passing parameter with hotstring

12 Feb 2017, 12:35

Thanks for your reply.
%A_ThisHotkey% pass only hotstring which is define in code not pass line parameter
Guest

Re: passing parameter with hotstring

12 Feb 2017, 13:22

I'm not sure what you mean, but you can pass on anything you like to a function. Some examples

Code: Select all

Global MyArray:={"hello":"world","btw":"AutoHotkey"} ; associative array

::btw::
::hello::
	xyz(MyArray[Trim(A_ThisHotkey,":")])
return

::bye:: ; regular hotstring
	xyz("Goodnight")
Return	

xyz(in)
	{
	 msgbox %in%
	}
If by %1% you mean a parameter you passed on to your script at start up it is probably best to assign these to a normal variable a soon as possible

Code: Select all

HelloText=%1%

::hello::
	xyz(HelloText)
return

xyz(in)
	{
	 msgbox %in%
	}
GS SAHU
Posts: 37
Joined: 29 Sep 2014, 12:18

Re: passing parameter with hotstring

13 Feb 2017, 12:59

i want to write a script.
when i type.
open notepad , open wordpad , open paint, open cmd
script like that

Code: Select all

::open::
open(nextstring)
return
open(nextstring)
{
run %nextstring%.exe
}
Guest

Re: passing parameter with hotstring

13 Feb 2017, 15:18

Code: Select all

::open::
Input,nextstring,,{Enter}
Run,%nextstring%.exe
return
User avatar
FanaticGuru
Posts: 1906
Joined: 30 Sep 2013, 22:25

Re: passing parameter with hotstring

13 Feb 2017, 17:14

GS SAHU wrote:i want to write a script.
when i type.
open notepad , open wordpad , open paint, open cmd
script like that

Code: Select all

::open::
open(nextstring)
return
open(nextstring)
{
run %nextstring%.exe
}
If you truly need the script not to do anything until after you type "open notepad " then you might look into Dynamic Hotstrings. It is a script somewhere on the forums that allows you to use RegEx patterns as hotstrings and you can make what you seem to want work very much like a normal hotstring without having to type invisible or bring up a input box.

FG
Hotkey Help - Help Dialog for Currently Running AHK Scripts
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: passing parameter with hotstring

13 Feb 2017, 17:53

You can use the V option for the input command to make the input text visible.
Walker

Re: passing parameter with hotstring

18 Sep 2017, 13:34

Enter the word you want to pass into the HotString 1 space to the left of the HotString

Code: Select all

; enter your argument | Parameter left or the trigger string 
; Ctrl + Left Arrow moves the curso to the beginning of the previous word

Send ^{Left}					; send Ctrl + Left error - goes to begning of word to the left
Send {Shift down}				; hold shift down 
Send ^{end}						; select to end of line
Send {Shift up}					; shift up 
tempClip := clipboard			; save the current clipboard stuff (text anyway)
clipboard := ""
Send ^{x}						; copy to the clipboard 
ClipWait						; wait for the clipboard to have stuff 
my_word := Clipboard
clipboard := tempClip

msgbox, % "My word is " my_word
This seems to work on a Windows 7 machine

Walker

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: -Elaphe-, downstairs, Frogrammer, Google [Bot] and 232 guests