autohotkey loop through txt and send each line

♀尐吖头ヾ 提交于 2019-12-11 19:47:01

问题


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

回答1:


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.




回答2:


  • 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.


来源:https://stackoverflow.com/questions/23092882/autohotkey-loop-through-txt-and-send-each-line

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!