/* Title: Dynamic Hotstrings Function: hotstrings Dynamically adds regular expression hotstrings. Parameters: c - regular expression hotstring a - text to replace hotstring with or a label to goto, leave blank to remove hotstring definition from triggering an action Examples: > hotstring("(B|b)tw\s", "%$1%y the way") ; type 'btw' followed by space or tab > hotstring("i)omg", "oh my god!") ; type 'OMG' in any case, upper, lower or mixed > hotstrings("\bcolou?r", "rgb(128, 255, 0);") ; '\b' prevents matching with anything before the word, e.g. 'multicololoured' License: - Version 2.0 by Titan - zlib License */ hotstrings(k, a = "") { static t, d, b, m = "*~$", l = 2000 global $ If d = { Loop, 94 { c := Chr(A_Index + 32) If A_Index not between 33 and 58 Hotkey, %m%%c%, __hs } e = BS,Space,Enter,Return,Tab Loop, Parse, e, `, Hotkey, %m%%A_LoopField%, __hs d = 1 } StringReplace, k, k, `n, \n, All StringReplace, k, k, `r, \r, All If (k = "" and a = "") { StringTrimLeft, cb, A_ThisHotkey, StrLen(m) If cb = BS { If (SubStr(b, 0) != "}") StringTrimRight, b, b, 1 } Else { If cb = Space cb := " " Else If cb in Enter,Return cb := "`n" Else If cb = Tab cb := "`t" Else If (StrLen(cb) > 1) cb = {%cb%} Else { If (GetKeyState("Shift") or GetKeyState("CapsLock", "T")) StringUpper, cb, cb } b .= cb } Loop, Parse, t, `n { If A_LoopField = Continue StringSplit, ct, A_LoopField, `r If (RegExMatch(b, ct1 . "$", $)) { StringLen, rl, $ SendInput, {BS %rl%} If (IsLabel(ct2)) Gosub, %ct2% Else { Transform, ctr, Deref, %ct2% Send, %ctr% } } } If (StrLen(b) > l) StringTrimLeft, b, b, l // 2 } Else If a = t := RegExReplace(t, "\n\Q" . a . "\E\r.*?\n") Else If k != t = %t%`n%k%`r%a%`n Return __hs: hotstrings("", "") Return }