Is there any way in AHK to specify an iterator in a keystring, so that all or part of the string is repeated a number of times?
If not, is there any reasonably common convention for this?
And yes, I do know that I can use Loop for this.
Andrew
Keystring iterators
Re: Keystring iterators
It's not entirely clear if you want a character repeated for use in Send/SendInput or not. Just in case:
Code: Select all
F12:: SendInput, {a 12}
Re: Keystring iterators
Thanks for that, for a start - I didn't actually know that one, but tracking it down in the Help it looks like all I'll get.
I was hoping for something more general, like 8x[{Down}^d].
Andrew
I was hoping for something more general, like 8x[{Down}^d].
Andrew
Re: Keystring iterators
Code: Select all
Loop, 8
Send keys
Re: Keystring iterators
Yep, I think I'll need to do something like that to send it.
My main concern at the moment is the higher level where I *define* a string with iterations, which is parsed by AHK. I'm really looking for a relatively simple but flexible shorthand for writing such definitions. I'm sure plenty have been there before me - I'd rather use an elegant shorthand defined by someone with lots of experience in such things, than define some klunky representation of my own,
Andrew
My main concern at the moment is the higher level where I *define* a string with iterations, which is parsed by AHK. I'm really looking for a relatively simple but flexible shorthand for writing such definitions. I'm sure plenty have been there before me - I'd rather use an elegant shorthand defined by someone with lots of experience in such things, than define some klunky representation of my own,
Andrew
Re: Keystring iterators
Hmm, what are your specifications? Let's say you want to invent your own shorthand, then you could limit yourself not to use all characters possible. Like invent a shorthand that takes <> as a marker for the string that you want to repeat. If your user-defined function finds such a term with the number of repetitions it replaces it accordingly. See RLE for more inspiration.
Example: <abc 4>{Left 3}qwer<t 5>y{Enter} => abcabcabcabc{Left}{Left}{Left}qwerttttty{Enter}
To answer the question: I don't know of anybody who has come up with a RLE style shorthand and thoroughly tested it. I guess the way keys with names can take an optional Count argument is such a shorthand by the developer, and my suggestion is to make your own similar to that.
The example above is obviously not working for sending data to a XML document, so you could maybe write your function to take an optional second argument that allows you to choose from <>, [] and() or any other (rarely used) combination of characters.
I am interested to write such a functions, but it would be untested. Or more like mildly tested.
Try this:I hope that helps.
Deal with the function as you please. The greatest benefit for the community is probably when you test it thoroughly and report any bugs you find, with or without any possible fixes.
Have fun.
Example: <abc 4>{Left 3}qwer<t 5>y{Enter} => abcabcabcabc{Left}{Left}{Left}qwerttttty{Enter}
To answer the question: I don't know of anybody who has come up with a RLE style shorthand and thoroughly tested it. I guess the way keys with names can take an optional Count argument is such a shorthand by the developer, and my suggestion is to make your own similar to that.
The example above is obviously not working for sending data to a XML document, so you could maybe write your function to take an optional second argument that allows you to choose from <>, [] and() or any other (rarely used) combination of characters.
I am interested to write such a functions, but it would be untested. Or more like mildly tested.
Try this:
Code: Select all
; attempt #1
TXT = <abc 4>{Left 3}qwer<t 5>y{Enter} ; string to expand
SendInput, % RLExpand(TXT)
ExitApp
;-------------------------------------------------------------------------------
RLExpand(Text, Style := "<>") { ; expand Text where Style encoding is present
;-------------------------------------------------------------------------------
; Style must be one of <>,() or []
;---------------------------------------------------------------------------
If (Style = "<>")
_Beg := "<", _End := ">"
Else If (Style = "()")
_Beg := "\(", _End := "\)"
Else If (Style = "[]")
_Beg := "\[", _End := "\]"
Else {
MsgBox, 16, Error in RLExpand(), unsupported style: %Style%
Return
}
Result := Text, Pos := 1,
Needle = %_Beg%(?P<STR>[^\s%_End%]+?) (?P<REP>\d+)%_End%
While Pos := RegExMatch(Result, Needle, Match_, Pos) {
Replacement := ""
Loop, %Match_REP%
Replacement .= Match_STR
Result := StrReplace(Result, Match_, Replacement, 1)
}
Return, Result
}
Deal with the function as you please. The greatest benefit for the community is probably when you test it thoroughly and report any bugs you find, with or without any possible fixes.
Have fun.
Re: Keystring iterators
Maybe something like this:
Although depending on how often I was writing code, and what I was doing, I do like wolf_II's replace text approach. You could pick some rare combination like << or >>, and replace those strings with Chr(1), and then parse the text using Chr(1) as a delimiter, manipulating every even-numbered string in the loop into something that SendInput can handle, and appending text to a new string for use with SendInput.
Code: Select all
q::
SendInput, % "{Up}{Left 3}a{b 3}" StrRept("{Down}^d", 8) "{Down}{Right 3}c{d 3}"
return
StrRept(vText, vNum)
{
return StrReplace(Format("{:" vNum "}","")," ",vText)
;return StrReplace(Format("{:0" vNum "}",0),0,vText)
}
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Re: Keystring iterators
Thanks guys, particularly for the code. A
Who is online
Users browsing this forum: Bing [Bot], gabelynn1, watashiakilla and 342 guests