Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
375 views
in Technique[技术] by (71.8m points)

loops - VBScript - How to use Sendkeys without it looping and crashing my computer?

I am trying to use the Enter SendKey and for some reason the only way it actually works - kinda - is if I have it like this which I found from another example:

Do  
  wshell.SendKeys "{ENTER}"
Loop

Obviously since that's in a loop that's what it's going to do... loop. As a result everything I click on hits Enter until I click another window where it will keep hitting Enter until I end up just restarting my computer.

But if I take it out of the loop it doesn't work at all. Additionally, even if I have it in the loop, though I have tried:

wshell.AppActivate "Internet Explorerer"

I still have to click on the IE window in order for it to actually "press" Enter

How do I use the SendKeys so it's not looping AND you don't have to manually click on the IE window for it to run?

NOTE: I'm only able to use VBScript, not VBA or anything else.

question from:https://stackoverflow.com/questions/65903951/vbscript-how-to-use-sendkeys-without-it-looping-and-crashing-my-computer

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I discovered the issue was NOT with the SendKeys, it was with the focus being on the HTA instead of IE so when it was running, there was nothing to hit Enter on.

I was able to completely resolve the issue using this:

wshell.AppActivate("title")
wshell.SendKeys "{ENTER}"

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...