[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖
本帖最后由 buyiyang 于 2023-10-8 16:51 编辑

回复 7# wyhs4000
保存为bat脚本
  1. #@&cls&powershell "type '%~f0'|out-string|iex"&exit
  2. Add-Type @"
  3. using System;
  4. using System.Runtime.InteropServices;
  5. public class ClickKey
  6. {
  7.     [DllImport("user32.dll")]
  8.     private static extern void keybd_event(byte bVk, byte bScan, uint dwFlags, int dwExtraInfo);
  9.     public static void Click(){keybd_event(0x01, 0x45, 0x65, 0);}
  10.     public static void KeyPress(byte key){keybd_event(key, 0x45, 0x65, 0);}
  11.     public static void KeyUp(byte key){keybd_event(key, 0x45, 0x02, 0);}
  12.     public static void MouseUp(){keybd_event(0x01, 0x45, 0x02, 0);}
  13. }
  14. "@
  15. #以下按照需要调整顺序或删除
  16. # 按下左键
  17. [ClickKey]::Click()
  18. # 按下数字键盘的5键
  19. $key = 0x65
  20. [ClickKey]::KeyPress($key)
  21. # 释放左键
  22. [ClickKey]::MouseUp()
  23. # 释放数字键盘的5键
  24. [ClickKey]::KeyUp($key)
复制代码

TOP

回复 10# buyiyang


    这也不算是bat,都用的是powershell(C#),不明白为什么一定要vbs,我参考http://demon.tw/programming/vbs-control-mouse.html写了一个vbs(vba)
  1. Option Explicit
  2. Dim WshShell
  3. Dim oExcel, oBook, oModule
  4. Dim strRegKey, strCode, x, y
  5. Set oExcel = CreateObject("Excel.Application")
  6. set WshShell = CreateObject("wscript.Shell")
  7. strRegKey = "HKEY_CURRENT_USER\Software\Microsoft\Office\$\Excel\Security\AccessVBOM"
  8. strRegKey = Replace(strRegKey, "$", oExcel.Version)
  9. WshShell.RegWrite strRegKey, 1, "REG_DWORD"
  10. Set oBook = oExcel.Workbooks.Add
  11. Set oModule = obook.VBProject.VBComponents.Add(1)
  12. strCode = _
  13. "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 & _
  14. "Private Sub KeyClick()" & vbCrLf & _
  15. "keybd_event &H65, 0, 0, 0" & vbCrLf & _
  16. "keybd_event &H65, 0, 2, 0" & vbCrLf & _
  17. "keybd_event 1, &H45, &H65, 0" & vbCrLf & _
  18. "keybd_event 1, &H45, 2, 0" & vbCrLf & _
  19. "End Sub"
  20. oModule.CodeModule.AddFromString strCode
  21. oExcel.Run "KeyClick"
  22. oExcel.DisplayAlerts = False
  23. oBook.Close
  24. oExcel.Quit
复制代码
15、16行按下、释放Numpad5键,17、18行按下、释放左键。

TOP

返回列表