user1913843
user1913843

Reputation: 135

autohotkey loop through txt and send each line

I am attempting to loop through the list in VarX and send the keystrokes requested until the list is done. Right now it seems to jumble up and not run the commands correctly in order. any ideas of what I have wrong? it should run like this:

ctrl f
48306237
enter
tab tab tab tab enter
shift space
ctrl -

then repeat with the next number...

^!G::

VarX=

(
48306237
48306642
48303423
48303612
48303797
)

loop, parse, VarX, `n,`r

{

Send, ^f
Send, %VarX%
Send, {enter}
Send, {tab}{tab}{tab}{tab}{enter}
Send, +{space}
Send, ^-
return

}

return

Upvotes: 0

Views: 1101

Answers (2)

vafylec
vafylec

Reputation: 1015

  • If you tell us what program you are using we could possibly recommend better techniques to use, including ControlGetText/ControlSetText/AccViewer (MSAA: Microsoft Active Accessibility)/COM (Component Object Model).
  • For programs where I can only use Send, as the method of last resort, I often put a lot of sleeps in, and/or use SetKeyDelay to increase pauses between keypresses. Also I would watch the first 10 or 20 iterations to make sure that the keypresses function correctly.
  • I would also put in security measures like use IfWinActive to stop the script if the original window is no longer active, otherwise if a random window pops up it will receive the keypresses.
  • Also in this case the data is numeric so it's OK, but I would still use Send {Raw}%VarX% to send the text as a precaution, in case of characters such as +^#!{} that are treated specially by Send.
  • At the moment you have Return inside the loop, which would only allow one iteration to take place, you probably did this temporarily for diagnostic reasons, but I should point that out to others.

Upvotes: 0

Robert Ilbrink
Robert Ilbrink

Reputation: 7953

First thing, don't you want to "do something" with the result? e.g. wait to see if it found something, and then continue after you e.g. pressed a key?

Also If you want to see if a string is inside your text, why not use:

 If YourTextVariable contains %YourStringNumber%
     MsgBox, Found %YourStringNumber% in the text

If you need to use the internal "find" function, then I would suggest to use the AHK Spy to find the edit object ID and the [Find] button ID and use ControlSend to send the search criteria and ControlSend to "press the" [Find] button.

Upvotes: 1

Related Questions