Page 1 of 1

How to call a one-line hotstring?

Posted: 08 Jun 2017, 09:53
by redrum
I have a number of hotkeys and hotstrings that are only enabled (not sure if that is the correct term) if a particular window is active. So these hotkeys and hotstrings are sandwiched between

Code: Select all

#IfWinActive ahk_class [particular app]

#IfWinActive
In this #IfWinActive block, I wish to add a hotkey that itself calls a hotstring within the same block.

The hotstring I want to call is the following text expansion:

Code: Select all

:*:;in::intitle:
The hotkey I tried creating:

Code: Select all

!F6::  
Send, {F6}  
Send, :*:;in
return
The Send function sends the characters :*:;in but this does not execute the text expansion. Where am I going wrong?

Re: How to call a one-line hotstring?

Posted: 08 Jun 2017, 10:10
by fischgeek
You're confusing the difference between a hotkey and a hotstring. Wouldn't you just want the hotstring to be executed when you type ;in instead of using a hotkey?

Basically, you're asking the Send command to send the following keystrokes: :*:;in when in-fact, all you want is just the hotstring.

Code: Select all

#IfWinActive ahk_class [particular app]
:*:;in::intitle:
#IfWinActive

Re: How to call a one-line hotstring?  Topic is solved

Posted: 08 Jun 2017, 10:44
by GEV
You can use GoSub to call the hotstring, but only if the hotstring executes another command (Send, Run etc.):

Code: Select all

#IfWinActive ahk_class [particular app]

	:*:;in:: 
		SendInput, intitle:
	return

	!F6::
		Send, {F6}  
		GoSub, :*:;in
	return

#IfWinActive

Re: How to call a one-line hotstring?

Posted: 08 Jun 2017, 11:52
by redrum
GEV wrote:You can use GoSub to call the hotstring, but only if the hotstring executes another command (Send, Run etc.):

Code: Select all

#IfWinActive ahk_class [particular app]

	:*:;in:: 
		SendInput, intitle:
	return

	!F6::
		Send, {F6}  
		GoSub, :*:;in
	return

#IfWinActive
Thanks for the explanation and code. Works great!

Re: How to call a one-line hotstring?

Posted: 08 Jun 2017, 11:55
by redrum
fischgeek wrote:You're confusing the difference between a hotkey and a hotstring. Wouldn't you just want the hotstring to be executed when you type ;in instead of using a hotkey?

Basically, you're asking the Send command to send the following keystrokes: :*:;in when in-fact, all you want is just the hotstring.

Code: Select all

#IfWinActive ahk_class [particular app]
:*:;in::intitle:
#IfWinActive
No, I want the hotkey because I already have the hotstring, which I sometimes execute directly, but sometimes I want to execute it immediately after pressing F6, so rather than pressing F6 and then type ";in", I want a hotkey that sends F6 and then executes the hotstring.