回复 10# buyiyang
这也不算是bat,都用的是powershell(C#),不明白为什么一定要vbs,我参考http://demon.tw/programming/vbs-control-mouse.html写了一个vbs(vba)- Option Explicit
- Dim WshShell
- Dim oExcel, oBook, oModule
- Dim strRegKey, strCode, x, y
- Set oExcel = CreateObject("Excel.Application")
- set WshShell = CreateObject("wscript.Shell")
- strRegKey = "HKEY_CURRENT_USER\Software\Microsoft\Office\$\Excel\Security\AccessVBOM"
- strRegKey = Replace(strRegKey, "$", oExcel.Version)
- WshShell.RegWrite strRegKey, 1, "REG_DWORD"
- Set oBook = oExcel.Workbooks.Add
- Set oModule = obook.VBProject.VBComponents.Add(1)
- strCode = _
- "Private Declare PtrSafe Sub keybd_event Lib ""user32"" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Integer, ByVal dwExtraInfo As Integer)" & vbCrLf & _
- "Private Sub KeyClick()" & vbCrLf & _
- "keybd_event &H65, 0, 0, 0" & vbCrLf & _
- "keybd_event &H65, 0, 2, 0" & vbCrLf & _
- "keybd_event 1, &H45, &H65, 0" & vbCrLf & _
- "keybd_event 1, &H45, 2, 0" & vbCrLf & _
- "End Sub"
- oModule.CodeModule.AddFromString strCode
- oExcel.Run "KeyClick"
- oExcel.DisplayAlerts = False
- oBook.Close
- oExcel.Quit
复制代码 15、16行按下、释放Numpad5键,17、18行按下、释放左键。 |