Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Dynamic hotstrings


  • Please log in to reply
3 replies to this topic
Menixator
  • Members
  • 744 posts
  • Last active: Sep 01 2015 02:54 PM
  • Joined: 10 Jul 2013

You can use this library to create dynamic hotstrings.
If you are not familiar regex, you can use the function in normal mode.
Get it here.
 
Example:

#Include Hotstring.ahk

Hotstring("maths","mathemetics") ;Simple replacement.
Hotstring("ahk","autohotkey",1) ;Normal case sensitive replacement.
Hotstring("#now","%A_Now%") ;Will send %A_Now% as soon as #now is typed.
Hotstring("(a|A)faik","$1s far as I know.",3) ; Will check the case of the first character and use it in the replacement.
Hotstring("btw","btw") ; Goto the "btw" label instead of replacing it.
Hotstring("i)\b(red|orange|blue|green)\b","colors",3) ; will run the colors function.
Hotstring("(\d+)\/(\d+)%", "percent",3) ; One of poly's examples
Hotstring("np","this will work only in notepad.",,,"condition") ; Context sensitive hotkey . . Sortof.
return

btw:
MsgBox You typed %$%. ;$ variable will contain exactly what the user typed in labels. Always keep in mind that $ is a global variable.
return
Return

percent:
p := Round($1 / $2 * 100)
Send, %p%`%
Return

colors(choice){
	; The hotstrings will pass off what the user typed to the function, only if it has 1 or more parameter(s)
	MsgBox You chose %choice%
	return
}

condition(){
	;decides when to trigger the np hotstring.
	return, WinActive("ahk_class Notepad")
}


jNizM
  • Members
  • 928 posts
  • Last active: Jan 12 2018 09:23 AM
  • Joined: 01 Aug 2012
Hey Menixator
First, thanks for your script =)

A few (maybe) improvements:
1. StringTrimRight,typed,typed,1 ==> typed := SubStr(typed, 1, (StrLen(typed) - 1))
2. StringTrimLeft,typed,typed,200 ==> typed := SubStr(typed, (200 + 1))
3. } else if Hotkey in Return,Tab,Space ==> } else if (Hotkey ~= "Return|Tab|Space")

A feature request:
1. Multi-Line Support
::Test::
(
Line 1

Line3
)
2. Statistic output (used Hotkeys) just a counter
3. Statistic output (saved typing keys)
like in this tool (https://github.com/adampash/texter)
[AHK] 1.1.27.04 x64 Unicode | [WIN] 10 Pro (Version 1709)
My GitHub Profile | Donations are appreciated if I could help you

Hoox
  • Members
  • 4 posts
  • Last active: Nov 07 2014 06:17 AM
  • Joined: 05 Nov 2014

I'm trying to use this to create a dynamic hotstring to start a function. Whenever I type a word of 5 characters beginning with capital "UI" i want to run a specific function. Is this possible?



Edd
  • Members
  • 212 posts
  • Last active: Jan 06 2016 07:36 AM
  • Joined: 24 Dec 2011

Congratulations , I see you did some modifications on the library, but there are some problems with your library, I tested all of your examples and some of them are not working well.