51Testing软件测试论坛

 找回密码
 (注-册)加入51Testing

QQ登录

只需一步,快速开始

微信登录,快人一步

手机号码,快捷登录

查看: 3798|回复: 1
打印 上一主题 下一主题

[资料] mouseclick

[复制链接]

该用户从未签到

跳转到指定楼层
1#
发表于 2013-5-28 12:27:01 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
  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. '



复制代码
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏
回复

使用道具 举报

  • TA的每日心情
    擦汗
    8 小时前
  • 签到天数: 1046 天

    连续签到: 4 天

    [LV.10]测试总司令

    2#
    发表于 2013-5-29 09:11:31 | 只看该作者
    LZ这个帖子什么意思,请详细说明下!
    回复 支持 反对

    使用道具 举报

    本版积分规则

    关闭

    站长推荐上一条 /1 下一条

    小黑屋|手机版|Archiver|51Testing软件测试网 ( 沪ICP备05003035号 关于我们

    GMT+8, 2024-11-14 17:34 , Processed in 0.098926 second(s), 27 queries .

    Powered by Discuz! X3.2

    © 2001-2024 Comsenz Inc.

    快速回复 返回顶部 返回列表