Jump to content


Photo

Applying same function over a group of hotstrings


  • Please log in to reply
3 replies to this topic

#1 jrav

jrav
  • Members
  • 9 posts

Posted 31 May 2012 - 08:24 AM

Is there a more elegant way (less lines) to achieve this? I'm trying to understand the flow of a script better, especially in relation to hotstrings and functions, and it may be mainly an issue where I place things on the script. Thanks for your help!

::hi::
abc()
return

::there::
abc()
return

::blue::
def()
return

::sky::
def()
return
; .... and lots more hotkeys needing abc() and def() fx applied
abc()
{
}

def()
{
}


#2 Guests

  • Guests

Posted 31 May 2012 - 08:26 AM

::hi::

::there::

::this::

::is::

::how::

::you::

::do::

::it::

abc()

return



#3 jrav

jrav
  • Members
  • 9 posts

Posted 31 May 2012 - 09:07 AM

Awesome! That was answer to one of my ?s...
Now to make things a little more complicated..what if I have some unique commands but still use the same function between a group of hotkeys:

::hi::
abc()
sendinput hi
return

::there::
abc()
a := greets
return

abc()
return


#4 Guests

  • Guests

Posted 31 May 2012 - 09:51 AM

You could handle that in your function by using A_ThisHotkey
::hi::
::there::
abc()
return

abc()
	{
	 MsgBox % SubStr(A_ThisHotkey,3) 
	}
Instead of the MsgBox above you can use a If Else Structure to do specific things for each hotstring
If (SubStr(A_ThisHotkey,3) = "hi")
	{
	 ; do something	
	} Else If (SubStr(A_ThisHotkey,3) = "there")
			{
				
			} ; etc ...