diff --git a/RegExHotstring.ahk b/RegExHotstring.ahk index 783e0c5..971166e 100644 --- a/RegExHotstring.ahk +++ b/RegExHotstring.ahk @@ -10,20 +10,20 @@ RegHook.Start() * @param {String} String RegEx string * @param {Func or String} CallBack calls function with RegEx match info or replace string * @param {String} Options - * + * * \* (asterisk): An ending character (e.g. Space, Tab, or Enter) is not required to trigger the hotstring. * use *0 to turn this option back off. - * + * * ? (question mark): The hotstring will be triggered even when it is inside another word; * that is, when the character typed immediately before it is alphanumeric. * Use ?0 to turn this option back off. - * + * * B0 (B followed by a zero): Automatic backspacing is not done to erase the abbreviation you type. * Use a plain B to turn backspacing back on after it was previously turned off. - * + * * C: Case sensitive: When you type an abbreviation, it must exactly match the case defined in the script. * Use C0 to turn case sensitivity back off. - * + * * O: Omit the ending character of auto-replace hotstrings when the replacement is produced. * Use O0 (the letter O followed by a zero) to turn this option back off. */ @@ -85,10 +85,13 @@ class RegExHs extends InputHook { switch vk { case 8: Send("{Blind}{vk08 down}") - case 32, 9, 13: - this.match(this.a0, vk, + case 9, 13, 32: + if (!this.match(this.a0, vk, SubStr(this.Input, 1, StrLen(this.Input) - 1), - (*) => Send("{Blind}{vk" Format("{:02x}", vk) " down}")) + (*) => Send("{Blind}{vk" Format("{:02x}", vk) " down}"))) { + this.Stop() + this.Start() + } case 160, 161: ; do nothing default: @@ -100,17 +103,15 @@ class RegExHs extends InputHook { OnKeyUp := this.keyUp keyUp(vk, sc) { switch vk { - case 8, 32, 9, 13: + case 8, 9, 13, 32: Send("{Blind}{vk" Format("{:02x}", vk) " up}") - this.Stop() - this.Start() } } OnChar := this.char char(c) { vk := GetKeyVK(GetKeyName(c)) - if (vk != 32 && vk != 9 && vk != 13) + if (vk != 9 && vk != 13 && vk != 32) this.match(this.a, vk) } @@ -119,7 +120,7 @@ class RegExHs extends InputHook { ; ToolTip(this.Input) if (!map.Count) { defer() - return + return false } ; loop through each strings and find the first match for , obj in map { @@ -143,10 +144,10 @@ class RegExHs extends InputHook { this.Start() } else throw TypeError('CallBack type error `nCallBack should be "Func" or "String"') - return + return true } } defer() - return + return false } } \ No newline at end of file diff --git a/demo.ahk b/demo.ahk index 324cf17..4d486bc 100644 --- a/demo.ahk +++ b/demo.ahk @@ -7,7 +7,8 @@ ; replace with regex string RegExHotstring("(\w+)a", "b$1", "C") RegExHotstring("(\w)a(\w)", "$2a$1", "*") -RegExHotstring("(\d+)(\w+)", "$2$1", "O?B0") +RegExHotstring("(\d+)(\w+)", "$2$1", "OB0") +RegExHotstring("a(\w)c", (match) => MsgBox("you just typed a" match[1] "c!"), "*?B0") ; use anonymous function RegExHotstring("(\w+)b", (match) => MsgBox("matched: " match[1])) @@ -17,7 +18,7 @@ RegExHotstring("(\w+)b", (match) => MsgBox("matched: " match[1])) ; call with function name RegExHotstring("(\w*)c", call) -RegExHotstring("r(\d+)s", rand) +RegExHotstring("r(\d+)", rand) ; receives RegExMatchInfo call(match) {