How to stop a loop when pressing “OK” on a message box with VBS?

后端 未结 2 1702
日久生厌
日久生厌 2021-01-26 15:34

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\         


        
相关标签:
2条回答
  • 2021-01-26 15:46

    I don't know which looping keyword you used. Use any of the below keyword after

    if x=vbOK then "Exit For/Exit Do/Exit Function" might help you

    0 讨论(0)
  • 2021-01-26 15:53

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

    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()'>
    

    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
    

    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
    

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

    0 讨论(0)
提交回复
热议问题