目前這個腳本運行5分鐘,但我需要通過擊鍵來阻止它。使用vbs按鍵擊殺while循環
Option Explicit
Dim Excel, x, y, x1, y1, eTime
Set Excel = WScript.CreateObject("Excel.Application")
eTime = DateAdd("n", 2, Now)
x = "111"
y = "222"
x1 = "222"
y1 = "111"
Do While Now < eTime
Excel.ExecuteExcel4Macro (_
"CALL(""user32"",""SetCursorPos"",""JJJ""," & x & "," & y & ")")
WScript.Sleep (1000)
Excel.ExecuteExcel4Macro (_
"CALL(""user32"",""SetCursorPos"",""JJJ""," & x1 & "," & y1 & ")")
WScript.Sleep (1000)
Loop
WScript.Echo "Program Ended"
我試過下面的代碼,但它不工作,我做錯了嗎?
Option Explicit
Dim Excel, x, y, x1, y1, eTime
Set Excel = WScript.CreateObject("Excel.Application")
eTime = DateAdd("n", 2, Now)
x = "111"
y = "222"
x1 = "222"
y1 = "111"
Sub Form_KeyPress(KeyAscii As Integer)
Do While Not KeyAscii = 27
Excel.ExecuteExcel4Macro (_
"CALL(""user32"",""SetCursorPos"",""JJJ""," & x & "," & y & ")")
WScript.Sleep (1000)
Excel.ExecuteExcel4Macro (_
"CALL(""user32"",""SetCursorPos"",""JJJ""," & x1 & "," & y1 & ")")
WScript.Sleep (1000)
Loop
WScript.Echo "Program Ended"
純VBScript不能做你想做的,但VBA可以([相關](https://stackoverflow.com/q/23725598/1630171))。 –