按“确定"时如何停止循环在带有 VBS 的消息框中? [英] How to stop a loop when pressing "OK" on a message box with VBS?

查看:20
本文介绍了按“确定"时如何停止循环在带有 VBS 的消息框中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一些帮助.我是 VBS 的新手,我想为我用来打字的视频游戏编写一个机器人.

I need some help. I am a newbie in VBS and I want to write a bot for a video game I play to type stuff.

set sellAllTyping = wscript.CreateObject("WScript.Shell")

x= MsgBox ("To stop the bot, click OK. /// Coded by Vncz with a little help from StackOverflow! :^) RIP Yams ;-;",vbOK+vbInformation,"sell all Bot")

if x=vbOK then 
' *** I don't know what to write here. ***

sellAllTyping.sendkeys "t"
wscript.sleep 1000
sellAllTyping.sendkeys "/sell all"
wscript.sleep 1000
sellAllTyping.sendkeys "{ENTER}"
wscript.sleep 5000
loop

如果我在我召唤的消息框上按 OK,我希望在最底部停止循环.如果我做对了,我应该写什么代码来代替评论?谢谢!

I want to have the loop on the very bottom stop if I press OK on the message box I summoned. In place of the comment, what code should I write, if I'm even doing it right? Thanks!

推荐答案

不幸的是,msgbox 冻结了执行.

Unfortuately, msgbox freeze the execution.

换句话说,您不能在消息出现的那一刻和您单击确定"或取消"的那一刻之间循环.

In others words, you cannot loop between the moment the message apear and the moment you click on Ok or Cancel­.

实现这一目标的唯一方法是制作这样的 HTA 文件:

The only way to achieve this is to make a HTA file like this:

<SCRIPT LANGUAGE="VBScript" src="test.vbs"> </SCRIPT>
<input type='button' value='Start' onclick='startLoop()'>
<input type='button' value='Stop' onclick='stopLoop()'>

然后,在链接的 vbs 文件(在本例中,它是 test.vbs)上,您必须编写如下内容:

then, on the linked vbs file (for this example, it's test.vbs), you must write something like this:

set sellAllTyping = CreateObject("Wscript.shell")
loopState = true

sub startLoop()
    do while loopState = true
        msgbox "yeah"
    loop
end sub

sub stopLoop()
    loopState = false
end sub

现在唯一的问题是应用程序由于循环而冻结(如果我用 sendkeys 替换 msgbox)或者总是隐藏在 msgbox 后面.

The only problem now is that the app is freezing because of the loop (if I replace msgbox with sendkeys) or is always hide behind the msgbox.

此代码运行良好(具有睡眠功能):

this code work well (with a sleep function):

set sellAllTyping = CreateObject("Wscript.shell")
loopState = true

sub startLoop()
    do while loopState = true
        msgbox "yeah"
        sleep(2)
    loop
end sub

sub stopLoop()
    loopState = false
end sub

Sub sleep (Timesec)
  sellAllTyping.Run "Timeout /T " & Timesec & " /nobreak" ,0 ,true
End Sub

确保将 hta 文件命名为something.hta"而不是something.html"

Make sure you name the hta file "something.hta" and NOT "something.html"

这篇关于按“确定"时如何停止循环在带有 VBS 的消息框中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆