简体   繁体   English

VBScript - 如何使用 Sendkeys 而不使我的计算机循环和崩溃?

[英]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:我正在尝试使用 Enter SendKey 并且由于某种原因,它实际工作的唯一方法 - 有点 - 是如果我有这样的它,我从另一个例子中找到:

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.结果,我单击的所有内容都按 Enter 键,直到我单击另一个 window ,它会一直按 Enter 键,直到我最终重新启动计算机。

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我仍然需要单击 IE window 才能真正“按”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?如何使用 SendKeys 使其不循环并且您不必手动单击 IE window 即可运行?

NOTE: I'm only able to use VBScript, not VBA or anything else.注意:我只能使用 VBScript,而不是 VBA 或其他任何东西。

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.我发现问题不在于 SendKeys,而在于 HTA 而不是 IE,所以当它运行时,没有什么可以按 Enter 键的。

I was able to completely resolve the issue using this:我能够使用这个完全解决这个问题:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM