1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
Set Input = New SetInput WScript.Sleep 3000 Input.Keys "JD000","{ENTER}" '输入“JD000”并回车 Input.GetPos x,y '获得鼠标当前位置坐标 'MsgBox x & "," & y '弹窗显示鼠标位置 Input.Move 300,300 '把鼠标移动到坐标 Input.Click "LEFT" '鼠标点击动作 Class SetInput Private shell Private xls, wbk, module1 Private reg_key, xls_code, x, y Private Sub Class_Initialize() Set shell = CreateObject("wscript.Shell") Set xls = CreateObject("Excel.Application") 'vbs 完全控制excel reg_key = "HKEY_CURRENT_USER\Software\Microsoft\Office\$\Excel\Security\AccessVBOM" reg_key = Replace(reg_key, "$", xls.Version) shell.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 Keys(Str,Key) '键盘输入 shell.SendKeys Str shell.SendKeys Key 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 Click(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 |
发表回复