Jump to content

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

RegEx Powered Dynamic Hotstrings


  • Please log in to reply
225 replies to this topic
polyethene
  • Members
  • 5519 posts
  • Last active: May 17 2015 06:39 AM
  • Joined: 26 Oct 2012
Thanks for the ideas and solutions, I forgot about this script. Anyway I've completely rewrote it and uploaded the new version.

autohotkey.com/net Site Manager

 

Contact me by email (polyethene at autohotkey.net) or message tidbit


tonne
  • Members
  • 1654 posts
  • Last active: May 06 2014 06:22 PM
  • Joined: 06 Jun 2006
Nice!
One suggestion and a couple of issues, though.

When replacing the hotstring this seems to work smoother:
...
  If (IsLabel(ct2)) {
    SendInput, {BS %rl%}
    Gosub, %ct2%
  }
  Else {
    Transform, ctr, Deref, %ct2%
    SendInput, {BS %rl%}%ctr%
}
...

Trying the rjwilmsi example I found that anna is correctly, automagically changed to Anna, but nanna is wrongly changed to nAnna.
Try hotstrings("ann(a|e)" , "Ann%$1%") and type nAnne - try to correct the A to a ({left 4}{bs}a)!

rjwilmsi
  • Members
  • 30 posts
  • Last active: Nov 21 2012 12:40 PM
  • Joined: 18 May 2005

Trying the rjwilmsi example I found that anna is correctly, automagically changed to Anna, but nanna is wrongly changed to nAnna.


I'm not sure if that's a bug as such as I would want text within words to be corrected, e.g. correcting 'sss' to 'ss'. Perhaps my Anna example was a bad one to choose, or could we introduce a third argument to specify whole word/within word correction?

polyethene
  • Members
  • 5519 posts
  • Last active: May 17 2015 06:39 AM
  • Joined: 26 Oct 2012
Have you tried hotstrings("\bann(a|e)" , "Ann%$1%")

autohotkey.com/net Site Manager

 

Contact me by email (polyethene at autohotkey.net) or message tidbit


rjwilmsi
  • Members
  • 30 posts
  • Last active: Nov 21 2012 12:40 PM
  • Joined: 18 May 2005
Thanks for the very helpful posts guys (and girls?). I'll take a proper look at version 2 of the script and the suggestions in this topic when I'm back on Windows at work in the new year. I'll then post back with further examples to help others using the script. Probably this script should then be promoted to the sample list in the AHK help.

In the meantime, happy holidays to all!

tonne
  • Members
  • 1654 posts
  • Last active: May 06 2014 06:22 PM
  • Joined: 06 Jun 2006

Have you tried hotstrings("\bann(a|e)" , "Ann%$1%")

Nope, I tried \s; \b works! I better read up on regexps ;-}

polyethene
  • Members
  • 5519 posts
  • Last active: May 17 2015 06:39 AM
  • Joined: 26 Oct 2012
Glad it does :)
I've included an example with \b in scripts comments for anybody who hasn't read these posts.

autohotkey.com/net Site Manager

 

Contact me by email (polyethene at autohotkey.net) or message tidbit


scoob8000
  • Members
  • 11 posts
  • Last active: Sep 18 2009 07:39 PM
  • Joined: 18 Dec 2007
I've been trying to get this function to work for me for a few days with no luck. Just for the heck of it, I tried it on my other PC and it works just fine.

Both pc's have the same version of AHK, and my ahk files are identical.

Only real difference is one is windows 2000, and the other is XP.

Can anyone shed some light on the matter? :)

polyethene
  • Members
  • 5519 posts
  • Last active: May 17 2015 06:39 AM
  • Joined: 26 Oct 2012
Can't see why that is, this script only uses core functionality of AutoHotkey. Have you tried #InstallKeybdHook?

autohotkey.com/net Site Manager

 

Contact me by email (polyethene at autohotkey.net) or message tidbit


scoob8000
  • Members
  • 11 posts
  • Last active: Sep 18 2009 07:39 PM
  • Joined: 18 Dec 2007
I just tried #InstallKeybdHook, still no luck.

Going to do some more digging, there's gotta be something running on this machine preventing it from working..

Should it matter if AHK is installed or just unzipped into it's own folder in program files?

polyethene
  • Members
  • 5519 posts
  • Last active: May 17 2015 06:39 AM
  • Joined: 26 Oct 2012

Should it matter if AHK is installed or just unzipped into it's own folder in program files?

I highly doubt it.

Can anyone else with <XP use this script?

autohotkey.com/net Site Manager

 

Contact me by email (polyethene at autohotkey.net) or message tidbit


scoob8000
  • Members
  • 11 posts
  • Last active: Sep 18 2009 07:39 PM
  • Joined: 18 Dec 2007

Can anyone else with <XP use this script?


I couldn't find anything running on my W2K workstation, so I'll give it a shot in a vmware box at home if I remember.


Nonetheless, I'm just going to work with this on my XP machine for now..

I've pretty much got things figured out.

After my hotstring matches I want to send a {tab} without replacing the text the hotstring matched.

I'm drawing a blank here, I've tried using a seperate label but that still replaces the text with the tab.

#Hotstring b0 doesn't seem to do the trick either.



-Mike

rjwilmsi
  • Members
  • 30 posts
  • Last active: Nov 21 2012 12:40 PM
  • Joined: 18 May 2005
Two comments on version 2 of the script:

First of all let me say that version 2 of the script is an improvement on the first version, as the second version resolved a couple of issues I had.
However, I've found a couple of further/unresolved issues with version 2 of the script, so would like to post them for help / discussion:

hotstrings("([hwHW]a|i)(s?sn|ns)(['s])?t(\s)" , "%$1%sn't%$4%")

In this example isnt is replaced by isn't (etcetera) after a further space is pressed. However, typing isnt followed by a tab produces iisn't. Bug?

hotstrings("(B|b)tw\s", "%$1%y the way")

In this example typing btw followed by two spaces produces by the ww. Bug?

Send, %ctr%

Performance of the script seems better if this line uses SendInput rather than Send. Is that okay?

I will post a selection of examples once these issues are resolved/I understand I've gone wrong. Thanks.

Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006
I've found a bug which prevents hotstrings(k) from removing k from the list of expressions (presuming it is supposed to remove k):
Else If a =
		t := RegExReplace(t, "\n\Q" . [color=red]a[/color] . "\E\r.*?\n")
Clearly a is empty; I guess it should be k.

Additionally, I suggest changing
Else If k !=
		t = %t%`n%k%`r%a%`n
to something like
Else If k !=
        t := RegExReplace(t, "\n\Q" . k . "\E\r.*?\n|$", "`n" k "`r" a "`n", _, 1)
to automatically replace any identical expressions (or append, as appropriate).

rjwilmsi
  • Members
  • 30 posts
  • Last active: Nov 21 2012 12:40 PM
  • Joined: 18 May 2005
Lexikos, thank you for posting on this topic. I use this function/code every day and still have some issues with it, so any input is much appreciated.

First of all I've found that my bug with the "isn't" example I give in my post above is actually only a problem when using Notepad++ and setting 'replace tabs with spaces', so there's no bug in this script in that case.

Regarding your post, I don't understand the bug you mention? What is the problem, could you post a couple of examples (changing my script I can't see a difference in behaviour).

Your second change breaks entries like
hotstrings("\bann(a|e)" , "Ann%$1%")
as it replaces 'anna' --> 'Ann' i.e. the variable is not included. If possible please post back on the problem there and what difference changing that line should make. Thanks.