比如利用VBS进行脚本模拟鼠标,则可以利用该方法进行调整
Option Explicit
wscript.sleep 5000
Dim wshshell
Dim oExcel, oBook, oModule
Dim strRegKey, strCode, x, y
Set oExcel = CreateObject("Excel.Application") '创建 Excel 对象
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 Type POINTAPI : X As Long : Y As Long : End Type" & vbCrLf & _
"Private Declare Function SetCursorPos Lib ""user32"" (ByVal x As Long, ByVal y As Long) As Long" & vbCrLf & _
"Private Declare Function GetCursorPos Lib ""user32"" (lpPoint As POINTAPI) As Long" & vbCrLf & _
"Private Declare Sub mouse_event Lib ""user32"" Alias ""mouse_event"" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)" & vbCrLf & _
"Public Function GetXCursorPos() As Long" & vbCrLf & _
"Dim pt As POINTAPI : GetCursorPos pt : GetXCursorPos = pt.X" & vbCrLf & _
"End Function" & vbCrLf & _
"Public Function GetYCursorPos() As Long" & vbCrLf & _
"Dim pt As POINTAPI: GetCursorPos pt : GetYCursorPos = pt.Y" & vbCrLf & _
"End Function"
oModule.CodeModule.AddFromString strCode '在模块中添加 VBA 代码
'//x = oExcel.Run("GetXCursorPos") '获取鼠标 X 坐标
'//y = oExcel.Run("GetYCursorPos") '获取鼠标 Y 坐标
'//WScript.Echo x, y
Const MOUSEEVENTF_MOVE = &H1
Const MOUSEEVENTF_LEFTDOWN = &H2
Const MOUSEEVENTF_LEFTUP = &H4
Const MOUSEEVENTF_RIGHTDOWN = &H8
Const MOUSEEVENTF_RIGHTUP = &H10
Const MOUSEEVENTF_MIDDLEDOWN = &H20
Const MOUSEEVENTF_MIDDLEUP = &H40
Const MOUSEEVENTF_ABSOLUTE = &H8000
'模拟鼠标左键单击
Dim width,height
width=CreateObject("HtmlFile").ParentWindow.Screen.AvailWidth
height=CreateObject("HtmlFile").ParentWindow.Screen.AvailHeight
oExcel.Run "SetCursorPos", 1350, 13 '//进入屏幕高度宽度1350,宽度13
wscript.sleep 1000
oExcel.Run "mouse_event", MOUSEEVENTF_LEFTDOWN + MOUSEEVENTF_LEFTUP, 0, 0, 0, 0 '//点击
oExcel.Run "SetCursorPos", 1350, 229 '//进入1350,229的屏幕位置
wscript.sleep 1000
oExcel.Run "mouse_event", MOUSEEVENTF_LEFTDOWN + MOUSEEVENTF_LEFTUP, 0, 0, 0, 0 '//点击
oExcel.Run "SetCursorPos", width/2, 351 '//进入屏幕宽度正中间,351的高度的屏幕位置
oExcel.Run "mouse_event", MOUSEEVENTF_LEFTDOWN + MOUSEEVENTF_LEFTUP, 0, 0, 0, 0 '//退出
'关闭 Excel
oExcel.DisplayAlerts = False
oBook.Close
oExcel.Quit
关于作者