AutoHotkey Community

It is currently May 26th, 2012, 1:04 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 171 posts ]  Go to page Previous  1, 2, 3, 4, 5, 6 ... 12  Next
Author Message
 Post subject:
PostPosted: January 4th, 2009, 2:29 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7502
Location: Australia
rjwilmsi wrote:
Regarding your post, I don't understand the bug you mention?
I already said, it prevents hotstrings(k) from removing k from the list of expressions. For example,
Code:
hotstrings("\bann(a|e)" , "Ann%$1%")
; This is supposed to "remove hotstring definition from triggering an action":
hotstrings("\bann(a|e)")

Quote:
Your second change breaks entries like ...
I forgot to replace "$" with "$$" in k and a. For example,
Code:
t := RegExReplace(t, "\n\Q" . k . "\E\r.*?\n|$", "`n" RegExReplace(k,"\$","$$$$") "`r" RegExReplace(a,"\$","$$$$") "`n", _, 1)
Notice that the replacement string is actually "$$", with each doubled up to specify a single literal character.
Quote:
If possible please post back on the problem there and what difference changing that line should make.
Again, I already said what it does: replaces any identical expressions already existing in the list. For instance, without the change, code like the following
Code:
hotstrings("omg" , "oh my god")
Sleep, 5000
hotstrings("omg" , "oh my god{!}")
will result in "omg" being expanded to "oh my god oh my god!" if the script has been running for at least 5 seconds. This is because there are two "omg" entries in the list (but also because of the first issue in the list below.)

Both of these changes are specifically useful for loading hotstring definitions from an external file, and later reloading them or modifying them via a GUI. (Someone Asked for Help with such a script recently.)

While debugging this, I've noticed some other issues:
  • Sometimes the "recognizer" seems to act on what was there, not what it was replaced with. (One could argue that neither should be recognized, but that's not the point.) For instance, if I use hotstrings("\bann(a|e)", "Ann%$1%") and type "anna", it replaces it with "Anna". If I then backspace the "a" and type another "a", or type some other letter then backspace it, "Anna" is replaced with "Anna".
    • I had originally noticed it with "oh my g" being replaced with "oh moh my god" or something similar. After modifying the script, it no longer happens this way for "omg"->"oh my god". :?
  • This is especially problematic if I click into another window (like Firefox) and start typing then backspace what I typed, as it then deletes part of my text and types "Anna". This is partly a separate issue:
  • Unlike AutoHotkey's hotstring recognizer, hotstrings() does not reset when you click, press arrow keys, home, end, etc. (Clicking and +home,delete are the main problems for me.)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 4th, 2009, 2:59 pm 
Offline
User avatar

Joined: August 11th, 2004, 1:47 am
Posts: 5347
Location: UK
I committed an update which should have hopefully resolved the issues mentioned. Thanks for the bug reports.

_________________
GitHubScriptsIronAHK Contact by email not private message.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 4th, 2009, 11:37 pm 
Offline

Joined: May 18th, 2005, 11:03 am
Posts: 30
Titan wrote:
I committed an update which should have hopefully resolved the issues mentioned. Thanks for the bug reports.

Thanks for the update - it is certainly an improvement. The "isn't" bug I had has now gone too. Also, the main bug I was suffering from was over extra firing of hotkeys, which I believe is the issue Lexikos mentioned.

However, one bug introduced by this update (I'm pretty sure) is that now backspacing of a hotstring doesn't work: e.g. type anna, get it converted to Anna by hotstrings("\bann(a|e)" , "Ann%$1%") rule, but then if backspace is pressed immediately, the character before Anna is deleted rather than the last 'a' in Anna. If the e = line is changed to remove BS this doesn't happen, but does that break other things? Thanks.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 5th, 2009, 1:57 am 
Offline
User avatar

Joined: August 11th, 2004, 1:47 am
Posts: 5347
Location: UK
Both bugs fixed in v2.53.

_________________
GitHubScriptsIronAHK Contact by email not private message.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 5th, 2009, 8:25 am 
Offline

Joined: April 18th, 2008, 7:57 am
Posts: 1390
Location: The Interwebs
Thanks, this is great until we get fully implemented dynamic hotstrings!


Just a little modification I made in my own version of the function;
Code:
         StringSplit, x, A_LoopField, `r
         If (RegExMatch(s, x1 . "$", $)) ; match
         {
            StringLen, l, $
            SendInput, {BS %l%}
            If (IsLabel(SubStr(x2, 1, -1)) && SubStr(x2,0) = ":")
               Gosub, % SubStr(x2, 1, -1)
            Else
            {
               Transform, x0, Deref, %x2%
               Send, %x0%
            }
         }

Just makes it so you have to put a colon ( : ) after a label name if you want it to go to a label instead of replace the text; simply makes it a bit harder to accidentally go to a label instead of replacing the text...

Edit: Fixed with updated code.


Last edited by Krogdor on January 5th, 2009, 8:53 am, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 5th, 2009, 8:31 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7502
Location: Australia
Thanks Titan. [Edit: However, I suppose you assumed avoiding RegExReplace would be more efficient, without having actually benchmarked it. With my sample text, the method which I had been using benchmarked 327% faster for removing, and 54% faster for replacing:
Code:
    Else If a =
        t := RegExReplace(t, "\n\Q" . k . "\E\r.*?\n")
    Else If k !=
        t := RegExReplace(t, "\n\Q" . k . "\E\r.*?\n|$", "`n" RegExReplace(k,"\$","$$$$") "`r" RegExReplace(a,"\$","$$$$") "`n", _, 1)
Or maybe you just felt like rewriting it the long way. :P
End edit.]

Krogdor, it isn't possible for a label name to end with ":", therefore (IsLabel(x2) && SubStr(x2,0) = ":") will always evaluate to false. I suggest:
Code:
if (SubStr(x2,0)=":" && IsLabel(SubStr(x2,1,-1)))


Last edited by Lexikos on January 5th, 2009, 9:00 am, edited 2 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 5th, 2009, 8:52 am 
Offline

Joined: April 18th, 2008, 7:57 am
Posts: 1390
Location: The Interwebs
Yeah, sorry about that Lexikos—I wasn't at the computer with my script so I was just going off of what I remembered. That would be the correct way to implement it.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 5th, 2009, 2:06 pm 
Offline
User avatar

Joined: August 11th, 2004, 1:47 am
Posts: 5347
Location: UK
Krogdor wrote:
Just makes it so you have to put a colon ( : ) after a label name if you want it to go to a label instead of replace the text
I like the idea, but I'll keep it as it is now for the sake of compatibility.

Lexikos wrote:
I suppose you assumed avoiding RegExReplace would be more efficient, without having actually benchmarked it.
I had a tough time with the GC on Mono so I was actually concerned with the memory usage of:

RegExMatch Performance wrote:
To improve performance, the 100 most recently used regular expressions are kept cached in memory (in compiled form).

I haven't benchmarked this either so I can't be certain. Either way I should hope a parsing loop is more newb friendly which is a good enough reason to keep it.

_________________
GitHubScriptsIronAHK Contact by email not private message.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 5th, 2009, 8:20 pm 
Offline

Joined: May 18th, 2005, 11:03 am
Posts: 30
Thanks to all for the continued work on this script. I have a bug with the latest version of the script to report. I believe Lexikos may have already mentioned this, but here goes:
Code:
hotstrings("(A|a)quir" , "%$1%cquir") ; acquire

using the above hotstring if 'aquir' is typed this is autoreplaced to 'acquir'. All correct so far, but if you then press backspace and 'r' another 'a' is added to the front of the word. This can be continued multiple times. I believe this is a problem for any hotstrings where the replace is longer than the find.

If the line with 'e = BS' is changed to remove 'BS' this goes away, but then this removes the fact that the function can work on user-corrected words.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 5th, 2009, 9:14 pm 
Offline
User avatar

Joined: August 11th, 2004, 1:47 am
Posts: 5347
Location: UK
Thanks for the report. Fixed in v2.54.

_________________
GitHubScriptsIronAHK Contact by email not private message.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 19th, 2009, 8:37 pm 
First if all, many thanx for your script!

Possibly you'd find it interesting: I'd had modified it a little bit in order to catch the numpad keys. I had to correct IP addresses because in my native keyboard layout there's a comma `,' on the numpad Del and often IP addresses were typed as 1,2,3,4

So here's the trivial addition to your script (suppose diff-form suits you)
Code:
--- Hotstrings.ahk-orig   Thu Mar 19 19:43:12 2009
+++ Hotstrings.ahk   Thu Mar 19 21:57:20 2009
@@ -33,7 +33,7 @@
          If A_Index not between 33 and 58
             Hotkey, %m%%c%, __hs
       }
-      e = BS|Space|Enter|Return|Tab
+      e = BS|Space|Enter|Return|Tab|Numpad0|Numpad1|Numpad2|Numpad3|Numpad4|Numpad5|Numpad6|Numpad7|Numpad8|Numpad9|NumpadDot|NumpadDel
       Loop, Parse, e, |
          Hotkey, %m%%A_LoopField%, __hs
       z = 1
@@ -54,6 +54,28 @@
             q := "`t"
          Else If q in Enter,Return
             q := "`n"
+         Else If q = Numpad0
+            q := "0"
+         Else If q = Numpad1
+            q := "1"
+         Else If q = Numpad2
+            q := "2"
+         Else If q = Numpad3
+            q := "3"
+         Else If q = Numpad4
+            q := "4"
+         Else If q = Numpad5
+            q := "5"
+         Else If q = Numpad6
+            q := "6"
+         Else If q = Numpad7
+            q := "7"
+         Else If q = Numpad8
+            q := "8"
+         Else If q = Numpad9
+            q := "9"
+         Else If q in NumpadDot,NumpadDel
+            q := ","
          Else If (StrLen(q) != 1)
             q = {%q%}
          Else If (GetKeyState("Shift") or GetKeyState("CapsLock", "T"))

After than the code
Quote:
hotstrings("(\d+)[^\d\s.](\d+)[^\d\s.](\d+)[^\d\s.](\d+)", "%$1%.%$2%.%$3%.%$4%")
works quite as expected

Thank you once more for that great script!


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: July 2nd, 2009, 9:27 pm 
Offline

Joined: May 2nd, 2008, 8:46 pm
Posts: 8
This script works just fine for me, until I start using cut/paste.

Code:
hotstrings("(abcdefg)", "showHotstr")
Return

showHotstr:
msg := $1
MsgBox %msg%
Return


It works fine if i type
Quote:
abcdefg

However, it fails if I cut/paste any part of the "abcdefg" string.

Any thoughts?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 3rd, 2009, 3:16 am 
Offline

Joined: April 8th, 2009, 8:23 pm
Posts: 3036
Location: Rio de Janeiro - RJ - Brasil
Just to inform, the link is broken.
Hotstrings.ahk is currently located HERE.

_________________
"Read the manual. Read it again. Search the forum.
Try something before asking. Show what you've tried.
"
Image
Antonio França
My stuff: Google Profile


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 3rd, 2009, 6:13 pm 
Offline

Joined: June 18th, 2008, 8:36 am
Posts: 4923
Location: AHK Forum
Here is a small fix because some hotkeys are not being created, for example:
Code:
hotstrings("(\d\d?)\;(\d\d?)", "%$1%:%$2%")
Code:
If A_Index not between 33 and 58 ;should be 64 I think

_________________
AHK_H (2alpha) AHF TT _Struct WatchDir Yaml _Input ObjTree RapidHotkey DynaRun :wink:


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 2nd, 2010, 10:21 pm 
I really like this script VERY much . I just have three questions:

1) How to add it to the autohotkey.ini (i know, i know i´m a newbie)
2) How is the performance impact if used with thousands of hotstrings and/or complicated/long regex rules?
3) I think this script is so great. Chris could implement it into autohotkey itself. What do you think?


Report this post
Top
  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 171 posts ]  Go to page Previous  1, 2, 3, 4, 5, 6 ... 12  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: DataLife, IsNull and 13 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group