51Testing软件测试论坛

标题: mouseclick [打印本页]

作者: smalliv407    时间: 2013-5-28 12:27
标题: mouseclick
  1. Set oExcel = CreateObject("Excel.Application") '创建 Excel 对象

  2. set WshShell = CreateObject("wscript.Shell")

  3. strRegKey = "HKEY_CURRENT_USER\Software\Microsoft\Office\$\Excel\Security\AccessVBOM"
  4. strRegKey = Replace(strRegKey, "$", oExcel.Version)

  5. WshShell.RegWrite strRegKey, 1, "REG_DWORD"

  6. Set oBook = oExcel.Workbooks.Add '添加工作簿
  7. Set oModule = obook.VBProject.VBComponents.Add(1) '添加模块
  8. strCode ="'Author: Demon" & vbCrLf &_
  9. "'Website: http://demon.tw" & vbCrLf &_
  10. "'Date: 2011/5/10" & vbCrLf &_
  11. "Private Type POINTAPI : X As Long : Y As Long : End Type" & vbCrLf &_
  12. "Private Declare Function SetCursorPos Lib ""user32"" (ByVal x As Long, ByVal y As Long) As Long" & vbCrLf &_
  13. "Private Declare Function GetCursorPos Lib ""user32"" (lpPoint As POINTAPI) As Long" & vbCrLf &_
  14. "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 & _
  15. "Public Function GetXCursorPos() As Long" & vbCrLf & _
  16. "Dim pt As POINTAPI : GetCursorPos pt : GetXCursorPos = pt.X" & vbCrLf & _
  17. "End Function" & vbCrLf & _
  18. "Public Function GetYCursorPos() As Long" & vbCrLf & _
  19. "Dim pt As POINTAPI: GetCursorPos pt : GetYCursorPos = pt.Y" & vbCrLf & _
  20. "End Function"
  21. oModule.CodeModule.AddFromString strCode '在模块中添加 VBA 代码
  22. 'Author: Demon
  23. 'Website: http://demon.tw
  24. 'Date: 2011/5/10
  25. x = oExcel.Run("GetXCursorPos") '获取鼠标 X 坐标
  26. y = oExcel.Run("GetYCursorPos") '获取鼠标 Y 坐标
  27. 'x = 100
  28. 'y = 100
  29. 'WScript.Echo x, y
  30. oExcel.Run "SetCursorPos", 30, 30 '设置鼠标 X Y 坐标
  31. Const MOUSEEVENTF_MOVE = &H1
  32. Const MOUSEEVENTF_LEFTDOWN = &H2

  33. Const MOUSEEVENTF_LEFTUP = &H4
  34. Const MOUSEEVENTF_RIGHTDOWN = &H8
  35. Const MOUSEEVENTF_RIGHTUP = &H10
  36. Const MOUSEEVENTF_MIDDLEDOWN = &H20
  37. Const MOUSEEVENTF_MIDDLEUP = &H40

  38. Const MOUSEEVENTF_ABSOLUTE = &H8000
  39. '模拟鼠标左键单击
  40. oExcel.Run "mouse_event", MOUSEEVENTF_LEFTDOWN + MOUSEEVENTF_LEFTUP, 0, 0, 0, 0

  41. '模拟鼠标左键双击(即快速的两次单击)
  42. oExcel.Run "mouse_event", MOUSEEVENTF_LEFTDOWN + MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
  43. oExcel.Run "mouse_event", MOUSEEVENTF_LEFTDOWN + MOUSEEVENTF_LEFTUP, 0, 0, 0, 0

  44. '模拟鼠标右键单击
  45. oExcel.Run "mouse_event", MOUSEEVENTF_RIGHTDOWN + MOUSEEVENTF_RIGHTUP, 0, 0, 0, 0
  46. '模拟鼠标中键单击
  47. oExcel.Run "mouse_event", MOUSEEVENTF_MIDDLEDOWN + MOUSEEVENTF_MIDDLEUP, 0, 0, 0, 0

  48. '关闭 Excel
  49. oExcel.DisplayAlerts = False
  50. oBook.Close
  51. oExcel.Quit
  52. '
  53. '



复制代码

作者: lsekfe    时间: 2013-5-29 09:11
LZ这个帖子什么意思,请详细说明下!




欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/) Powered by Discuz! X3.2