Results 1 to 4 of 4

Thread: To abruptly end a vb script when user clicks on "Esc" button!!

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2013
    Posts
    2

    Question To abruptly end a vb script when user clicks on "Esc" button!!

    Here is my code written:-

    Set WshShell = WScript.CreateObject("WScript.Shell")
    WshShell.Run " "
    WScript.Sleep 5000
    for i=1 to 20
    WshShell.SendKeys "^{HOME}"
    WshShell.SendKeys "{END}"
    WScript.Sleep 50
    WshShell.SendKeys " or "
    WScript.Sleep 50
    WshShell.SendKeys "{DELETE}"
    WshShell.SendKeys "{END}"
    next

    Result of this code basically add's "or" onto any active window! This was written to help me in adding the text "or" in between two values. I run this code and place a notepad as active window which has values. but if i click and open any other window, this code continues untill " i = 20 " but i have to exit from this code if user("I") clicks on "Esc" button. Can somebody provide me solution to it.
    I know there is wshShell.Quit....and i truely dont know how to use it!!

  2. #2
    Default Member Bonnie West's Avatar
    Join Date
    Jun 2012
    Location
    InIDE
    Posts
    4,060

    Re: To abruptly end a vb script when user clicks on "Esc" button!!

    I'm not aware of any WSH capability to monitor keystrokes, so what you're asking probably can't be done.
    On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
    Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)

  3. #3

    Thread Starter
    New Member
    Join Date
    May 2013
    Posts
    2

    Unhappy Re: To abruptly end a vb script when user clicks on "Esc" button!!

    Quote Originally Posted by Bonnie West View Post
    I'm not aware of any WSH capability to monitor keystrokes, so what you're asking probably can't be done.
    But i badly need a solution for it!!

    how about getasynckeystate!! will this work??

  4. #4
    Default Member Bonnie West's Avatar
    Join Date
    Jun 2012
    Location
    InIDE
    Posts
    4,060

    Re: To abruptly end a vb script when user clicks on "Esc" button!!

    Both VBScript and JScript cannot call Win API functions by themselves. However, a third-party ActiveX DLL (that exposes an object that you can instantiate in VBScript) might be able to do it for you. You may want to Google that option.

    If you don't mind converting your VBScript code to a more capable scripting language, then you might want to try AutoIt or AutoHotkey.
    On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
    Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width