Autohotkey clipboard variable holding values forever? -
Autohotkey clipboard variable holding values forever? -
i have below simple code, sends keystrokes text in clipboard 15ms delay in between characters (i utilize traverse huge lists of treeview elements).
issue: if have copied 'text1' clipboard, followed 'text2', script outputs 'text1text2' instead of 'text2' alone.
if reload script, prints 'text2'.
is there error in below code, or bug in implementing %clipboard% in autohotkey 1.1.14.03 ?
#v:: texttotype=" " texttotype=%clipboard% loopcount:=strlen(texttotype) ;stringlen, loopcount, texttotype array%loopcount%:=texttotype loop %loopcount% { thechar:=array%a_index% send %thechar% sleep 15 } homecoming
update: pointing out smarter ways of doing this, still figure out wrong in above piece of code.
update 2: error in understanding of ahk syntax. array%loopcount%:=texttotype
assigns whole string value in texttotype (loopcount)th string element of string array named 'array'.
update 3: (thanks @john y clarifying)
actually, there's no "declared" array @ all, in traditional sense. have bunch of individual variables, dynamically created needed, happen have names numbers @ end. array1 , array2 not elements in array object. 2 independent variables. autohotkey provides way glue numbers onto ends of names, can utilize them array.
the reason script doesn't work because you're using pseudo-array store different words clipboard.
i've commented code explain does:
#v:: texttotype := "" ; empty variable texttotype := clipboard ; move clipboard variable ; lenght of word ; used array index / loop count loopcount := strlen(texttotype) ; set clipboard in array @ index 'loopcount' array%loopcount% := texttotype ; loop through array many times ; string long loop % loopcount { ; retrieve word @ index in array thechar := array%a_index% ; send whole word send, % thechar sleep 15 } homecoming
instead of sending each character @ time, you're sending whole words specific indexes in array
array.
say re-create word dragon
, word 6 letters long. you'd set in array6
, you'd loop through array 6 times using same variable. @ point loop take each index @ time , move thechar
. on 6th lap in loop you'd set array6
thechar
, print whole word @ once.
then re-create word stackoverflow
. that's going go array13
, , we're going loop 13 times. on 6th lap we're going print out dragon
in array6
, , maintain going until reach 13 we'll print stackoverflow
since in array13
.
so that's why script isn't doing want to. helps little.
see code sample alpha bravo posted, that's right way of achieving want do.
autohotkey
Comments
Post a Comment