- 帖子
- 191
- 积分
- 222
- 技术
- 0
- 捐助
- 0
- 注册时间
- 2012-12-15
|
2楼
发表于 2013-2-27 15:05
| 只看该作者
Option Explicit
msgbox("3秒后获取鼠标坐标")
wscript.sleep 3000
Dim WshShell
Dim oExcel, oBook, oModule
Dim strRegKey, strCode, x, y
Set oExcel = CreateObject("Excel.Application")
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 Declare Function SetCursorPos Lib ""user32"" (ByVal x As Long, ByVal y As Long) As Long" & vbCr & _
"Private Type POINTAPI : X As Long : Y As Long : End Type" & vbCr & _
"Private Declare Function GetCursorPos Lib ""user32"" (lpPoint As POINTAPI) As Long" & vbCr & _
"Sub SetCursor(x as Long, y as Long) : SetCursorPos x, y : End Sub" & vbCr & _
"Public Function GetXCursorPos() As Long" & vbCr & _
"Dim pt As POINTAPI : GetCursorPos pt : GetXCursorPos = pt.X" & vbCr & _
"End Function" & vbCr & _
"Public Function GetYCursorPos() As Long" & vbCr & _
"Dim pt As POINTAPI: GetCursorPos pt : GetYCursorPos = pt.Y" & vbCr & _
"End Function"
oModule.CodeModule.AddFromString strCode
x = oExcel.Run("GetXCursorPos")
y = oExcel.Run("GetYCursorPos")
WScript.Echo x, y
oExcel.Run "SetCursor", 0, 0
oExcel.DisplayAlerts = False
oBook.Close
oExcel.Quit
此代码已经获取了鼠标的坐标,如何在3秒后再获取一次坐标,然后进行两次坐标的判断,如何不一样,就
报警! |
|