AutoHotkey Community

It is currently May 24th, 2012, 7:31 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 171 posts ]  Go to page 1, 2, 3, 4, 5 ... 12  Next
Author Message
PostPosted: February 4th, 2007, 6:59 pm 
Offline
User avatar

Joined: August 11th, 2004, 1:47 am
Posts: 5346
Location: UK
Dynamically add regular expression type hotstrings.

Example:
Code:
hotstrings("now#", "%A_Now%")
hotstrings("(B|b)tw", "%$1%y the way")
hotstrings("(\d+)\/(\d+)%", "percent") ; try 4/50%
Return

percent:
p := Round($1 / $2 * 100)
Send, %p%`%
Return

Download

_________________
GitHubScriptsIronAHK Contact by email not private message.


Last edited by polyethene on March 3rd, 2010, 9:16 pm, edited 4 times in total.

Report this post
Top
 Profile  
Reply with quote  
PostPosted: February 21st, 2007, 1:10 pm 
Offline

Joined: February 11th, 2007, 4:10 pm
Posts: 185
Titan wrote:
Dynamically add regular expression type hotstrings.


Thinks.I'll have a try.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 28th, 2007, 7:59 pm 
Offline

Joined: May 18th, 2005, 11:03 am
Posts: 30
Hmm, this seems interesting, but I can't get it to work.
I've pasted the function and examples into my autohotkey.ini file and reloaded it. I then expected that if I typed Btw in notepad it would be converted to By the way, and if I typed btw it would be converted to by the way. Am I totally missing the point? Does this script not effectively add regex support to hotstrings?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 4th, 2007, 4:05 pm 
Offline
User avatar

Joined: August 11th, 2004, 1:47 am
Posts: 5346
Location: UK
rjwilmsi wrote:
Does this script not effectively add regex support to hotstrings?
It does, that was probably a bad example. Try hs("gr[ea]y", "{#}CCC") - it replaces 'grey' or 'gray' with its hex colour code.

_________________
GitHubScriptsIronAHK Contact by email not private message.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 6th, 2007, 12:52 am 
Offline

Joined: June 26th, 2006, 6:14 pm
Posts: 1379
Location: USA
Used it here
http://www.autohotkey.com/forum/viewtopic.php?t=18110


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 17th, 2007, 2:09 pm 
Offline

Joined: May 28th, 2007, 5:05 am
Posts: 2
I like the idea of the dynamic hotstrings and I like the idea of regular expressions in them. But, as other people have described, I'd like to find a way to make dynamic hotstrings that behave more like regular, default hotstrings in that they wait for an non-word character before firing the replacement text.

For example, when defined using the hs() function above, the "btw" entry will expand to "by the way" without waiting for a space or comma afterward. (Which makes it impossible to define multiple hotstrings that use the same root.)

For example, I'd "lb" to expand to "pound", but "lbrt" to expand to liberate, and I haven't figured out yet how to do that using the hs() function above.

(The reason I don't want to use the #Hostring directive or syntax is that I'd like these hotstrings to be dynamically created as part of a compiled script.)

Thanks,
T


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 17th, 2007, 2:24 pm 
Offline
User avatar

Joined: August 11th, 2004, 1:47 am
Posts: 5346
Location: UK
That is an important feature that's currently lacking. I've been meaning to update this script for a long time. I'll try work on it soon and release version 2.

_________________
GitHubScriptsIronAHK Contact by email not private message.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 17th, 2007, 3:33 pm 
Offline
User avatar

Joined: August 30th, 2005, 8:43 pm
Posts: 8643
Location: Salem, MA
please try
Code:
hs("(B|b)tw\W", "%$1%y the way")

_________________
Image
(Common Answers) - New Tutorials Forum - Humongous FAQ


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 17th, 2007, 5:07 pm 
Offline

Joined: May 28th, 2007, 5:05 am
Posts: 2
engunneer wrote:
please try
Code:
hs("(B|b)tw\W", "%$1%y the way")

Does that work for you? Because that doesn't get expanded at all for me. (FWIW, I also thought about using regular expressions to try to test for end-of-word characters, but couldn't get it to work.)

T


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 17th, 2007, 5:11 pm 
Offline
User avatar

Joined: August 11th, 2004, 1:47 am
Posts: 5346
Location: UK
That would work if you typed something like 'btw.' or 'btw!', but these aren't nice solutions so I'll continue working on an update.

_________________
GitHubScriptsIronAHK Contact by email not private message.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 17th, 2007, 5:36 pm 
Offline
User avatar

Joined: August 30th, 2005, 8:43 pm
Posts: 8643
Location: Salem, MA
I didn't have a chance to try it. I also didn't have time to look up the regex, maybe \s was the right one?

_________________
Image
(Common Answers) - New Tutorials Forum - Humongous FAQ


Report this post
Top
 Profile  
Reply with quote  
 Post subject: handling of spaces
PostPosted: December 17th, 2007, 8:15 pm 
Offline

Joined: May 18th, 2005, 11:03 am
Posts: 30
Hi all,
I've been using this for a while now but have got stuck by one issue:

say i define an entry like this (I have this problem with other examples):

hs("ann(a|e)" , "Ann%$1%")

now this correctly changes:
anna -> Anna
anne -> Anne

however, spaces don't seem to be counted, so these are also incorrectly changed;
ann a -> aAnna
ann e -> aAnne

So it would seem that spaces are ignored by the regex matching? Am I right and can anybody tell me how to fix it?

Thanks


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 21st, 2007, 9:11 am 
Offline

Joined: May 18th, 2005, 11:03 am
Posts: 30
Please, anybody? I haven't yet resolved this.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 21st, 2007, 9:49 am 
Online

Joined: June 6th, 2006, 3:19 pm
Posts: 1654
Location: Denmark
Try this:

Code:
hs(c, a = "") {
   static d, b, q
   global $
   v = `n,€,~$,Numpad,BS,Space
   StringSplit, v, v, `,
   If !d {
      Loop, 104
         Hotkey, % Chr(42 * !!RegExMatch(t := Chr(32 + (x := A_Index))
            , "[a-z]")) . v3 . (x > 94 ? v4 . x - 95 : t), _hs
      Hotkey, %v3%%v5%, _hs
      d := 1
   }
   If a
      Return, !!b .= c . v2 . a . v1
   If c = %v3%%v5%
      Return, !!q := SubStr(q, 1, -1)
   If c = %v3%%v6%
      Return, !!q := SubStr(q, 1, -1)

   If GetKeyState("Shift", "P") or GetKeyState("Capslock", "T")
      StringUpper, c, c
   Else StringLower, c, c
   q .= SubStr(c, StrLen(v3) + !!InStr(c, v4) * StrLen(v4) + 1 + !!InStr(c, "*"))
   Loop, Parse, b, %v1%
   {
      If (c := RegExMatch(q, SubStr(t := A_LoopField, 1
         , InStr(t, v2) - 1) . "$", $)) and t {
         f += RegExMatch(t, ".+" . v2 . "(.+)", l)
         SendInput, % "{BS " . StrLen($) . "}"
         Transform, l, Deref, %l1%
         If IsLabel(l)
            GoSub, %l%
         Else SendInput, %l%
      }
   }
   If f
      q =
}

~$space::
_hs:
hs(A_ThisHotkey)
Return

_________________
RegEx Powered Dynamic Hotstrings
COM
AutoHotkey 2


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 21st, 2007, 7:23 pm 
Offline

Joined: May 18th, 2005, 11:03 am
Posts: 30
Thanks, that's perfect!

For others who may be interested, it's possible to exclude returns and tabs in a similar fashion:

Code:
hs(c, a = "") {
   static d, b, q
   global $
   v = `n,€,~$,Numpad,BS,Space,Tab,Return
   StringSplit, v, v, `,
   If !d {
      Loop, 104
         Hotkey, % Chr(42 * !!RegExMatch(t := Chr(32 + (x := A_Index))
            , "[a-z]")) . v3 . (x > 94 ? v4 . x - 95 : t), _hs
      Hotkey, %v3%%v5%, _hs
      d := 1
   }
   If a
      Return, !!b .= c . v2 . a . v1
   If c = %v3%%v5%
      Return, !!q := SubStr(q, 1, -1)
   If c = %v3%%v6%
      Return, !!q := SubStr(q, 1, -1)
  If c = %v3%%v7%
      Return, !!q := SubStr(q, 1, -1)
   If c = %v3%%v8%
      Return, !!q := SubStr(q, 1, -1)

   If GetKeyState("Shift", "P") or GetKeyState("Capslock", "T")
      StringUpper, c, c
   Else StringLower, c, c
   q .= SubStr(c, StrLen(v3) + !!InStr(c, v4) * StrLen(v4) + 1 + !!InStr(c, "*"))
   Loop, Parse, b, %v1%
   {
      If (c := RegExMatch(q, SubStr(t := A_LoopField, 1
         , InStr(t, v2) - 1) . "$", $)) and t {
         f += RegExMatch(t, ".+" . v2 . "(.+)", l)
         SendInput, % "{BS " . StrLen($) . "}"
         Transform, l, Deref, %l1%
         If IsLabel(l)
            GoSub, %l%
         Else SendInput, %l%
      }
   }
   If f
      q =
}

~$space::
~$return::
~$tab::

_hs:
hs(A_ThisHotkey)
Return


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

All times are UTC [ DST ]


Who is online

Users browsing this forum: Relayer, teadrinker, tic and 10 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