AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

RegEx Powered Dynamic Hotstrings
Goto page Previous  1, 2, 3  Next
 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
Titan



Joined: 11 Aug 2004
Posts: 5037
Location: /b/

PostPosted: Fri Dec 21, 2007 10:46 pm    Post subject: Reply with quote

Thanks for the ideas and solutions, I forgot about this script. Anyway I've completely rewrote it and uploaded the new version.
_________________
Chat (IRC)PlusNetScriptsIronAHK Contact by email not private message.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
tonne



Joined: 06 Jun 2006
Posts: 1481
Location: Denmark

PostPosted: Sat Dec 22, 2007 11:21 am    Post subject: Reply with quote

Nice!
One suggestion and a couple of issues, though.

When replacing the hotstring this seems to work smoother:
Code:
...
  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)!
_________________
there's a dog barking close within the range of my ear
sounds like he wants to escape the chain
he would probably bite me to death if he could
but the chain lets me spit in his face

- Kashmir
Back to top
View user's profile Send private message
rjwilmsi



Joined: 18 May 2005
Posts: 17

PostPosted: Sat Dec 22, 2007 12:12 pm    Post subject: Reply with quote

tonne wrote:
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?
Back to top
View user's profile Send private message
Titan



Joined: 11 Aug 2004
Posts: 5037
Location: /b/

PostPosted: Sat Dec 22, 2007 12:29 pm    Post subject: Reply with quote

Have you tried hotstrings("\bann(a|e)" , "Ann%$1%")
_________________
Chat (IRC)PlusNetScriptsIronAHK Contact by email not private message.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
rjwilmsi



Joined: 18 May 2005
Posts: 17

PostPosted: Sat Dec 22, 2007 1:33 pm    Post subject: Reply with quote

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!
Back to top
View user's profile Send private message
tonne



Joined: 06 Jun 2006
Posts: 1481
Location: Denmark

PostPosted: Sat Dec 22, 2007 2:21 pm    Post subject: Reply with quote

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

Nope, I tried \s; \b works! I better read up on regexps ;-}
_________________
there's a dog barking close within the range of my ear
sounds like he wants to escape the chain
he would probably bite me to death if he could
but the chain lets me spit in his face

- Kashmir
Back to top
View user's profile Send private message
Titan



Joined: 11 Aug 2004
Posts: 5037
Location: /b/

PostPosted: Sat Dec 22, 2007 2:30 pm    Post subject: Reply with quote

Glad it does Smile
I've included an example with \b in scripts comments for anybody who hasn't read these posts.
_________________
Chat (IRC)PlusNetScriptsIronAHK Contact by email not private message.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
scoob8000



Joined: 18 Dec 2007
Posts: 11

PostPosted: Fri Dec 28, 2007 8:08 pm    Post subject: Reply with quote

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? Smile
Back to top
View user's profile Send private message
Titan



Joined: 11 Aug 2004
Posts: 5037
Location: /b/

PostPosted: Fri Dec 28, 2007 8:21 pm    Post subject: Reply with quote

Can't see why that is, this script only uses core functionality of AutoHotkey. Have you tried #InstallKeybdHook?
_________________
Chat (IRC)PlusNetScriptsIronAHK Contact by email not private message.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
scoob8000



Joined: 18 Dec 2007
Posts: 11

PostPosted: Mon Dec 31, 2007 2:00 pm    Post subject: Reply with quote

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?
Back to top
View user's profile Send private message
Titan



Joined: 11 Aug 2004
Posts: 5037
Location: /b/

PostPosted: Mon Dec 31, 2007 2:04 pm    Post subject: Reply with quote

scoob8000 wrote:
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?
_________________
Chat (IRC)PlusNetScriptsIronAHK Contact by email not private message.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
scoob8000



Joined: 18 Dec 2007
Posts: 11

PostPosted: Wed Jan 02, 2008 2:05 pm    Post subject: Reply with quote

Titan wrote:

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
Back to top
View user's profile Send private message
rjwilmsi



Joined: 18 May 2005
Posts: 17

PostPosted: Sun Jan 06, 2008 11:15 pm    Post subject: Reply with quote

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:

Code:
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?

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


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

Code:
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.
Back to top
View user's profile Send private message
Lexikos



Joined: 17 Oct 2006
Posts: 4468
Location: Qld, Australia

PostPosted: Sat Jan 03, 2009 5:32 am    Post subject: Reply with quote

I've found a bug which prevents hotstrings(k) from removing k from the list of expressions (presuming it is supposed to remove k):
Code:
   Else If a =
      t := RegExReplace(t, "\n\Q" . a . "\E\r.*?\n")
Clearly a is empty; I guess it should be k.

Additionally, I suggest changing
Code:
   Else If k !=
      t = %t%`n%k%`r%a%`n
to something like
Code:
   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).
Back to top
View user's profile Send private message Visit poster's website
rjwilmsi



Joined: 18 May 2005
Posts: 17

PostPosted: Sat Jan 03, 2009 8:23 pm    Post subject: Reply with quote

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
Code:
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.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Goto page Previous  1, 2, 3  Next
Page 2 of 3

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group