正文
Set objShell = CreateObject("WScript.Shell") Set mouse=New SetMouse ' 循环检测 Do ' 获取所有窗口句柄 hwnd = objShell.AppActivate("Window Title") ' 如果找到匹配窗口 If hwnd <> 0 Then WScript.Echo "$$$找到目标点击!!" & Now() ' 点击坐标 mouse.move 2456,700 mouse.clik "dbclick" ' 等待一段时间 WScript.Sleep 200 End If WScript.Echo "等待下一次检测..." & Now() ' 等待下一次检测... WScript.Sleep 200 Loop '将以下代码加入到vbs文件末就能如以上方法调用 Class SetMouse private S private xls, wbk, module1 private reg_key, xls_code, x, y Private Sub Class_Initialize() Set xls = CreateObject("Excel.Application") Set S = CreateObject("wscript.Shell") 'vbs 完全控制excel reg_key = "HKEY_CURRENT_USER\Software\Microsoft\Office\$\Excel\Security\AccessVBOM" reg_key = Replace(reg_key, "$", xls.Version) S.RegWrite reg_key, 1, "REG_DWORD" 'model 代码 xls_code = _ "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 getx() As Long" & vbCrLf & _ "Dim pt As POINTAPI : GetCursorPos pt : getx = pt.X" & vbCrLf & _ "End Function" & vbCrLf & _ "Public Function gety() As Long" & vbCrLf & _ "Dim pt As POINTAPI: GetCursorPos pt : gety = pt.Y" & vbCrLf & _ "End Function" Set wbk = xls.Workbooks.Add Set module1 = wbk.VBProject.VBComponents.Add(1) module1.CodeModule.AddFromString xls_code End Sub '关闭 Private Sub Class_Terminate xls.DisplayAlerts = False wbk.Close xls.Quit End Sub '可调用过程 Public Sub getpos( x, y) x = xls.Run("getx") y = xls.Run("gety") End Sub Public Sub move(x,y) xls.Run "SetCursorPos", x, y End Sub Public Sub clik(keydown) Select Case UCase(keydown) Case "LEFT" xls.Run "mouse_event", &H2 + &H4, 0, 0, 0, 0 Case "RIGHT" xls.Run "mouse_event", &H8 + &H10, 0, 0, 0, 0 Case "MIDDLE" xls.Run "mouse_event", &H20 + &H40, 0, 0, 0, 0 Case "DBCLICK" xls.Run "mouse_event", &H2 + &H4, 0, 0, 0, 0 xls.Run "mouse_event", &H2 + &H4, 0, 0, 0, 0 End Select End Sub End Class '代码结束
- 上一篇: python推送钉钉群消息
- 下一篇: python脚本检测出现指定标题窗口并点击鼠标
猜你喜欢
- 2024-01-08python脚本检测出现指定标题窗口并点击鼠标
- 搜索