Board logo

标题: [问题求助] 能否用VBS监测鼠标,从而触发事件? [打印本页]

作者: ww0000    时间: 2013-2-26 16:10     标题: 能否用VBS监测鼠标,从而触发事件?

写一段VBS,运行代码后,监测鼠标,鼠标一动就跳出警告框?
退出代码后,就正常!
作者: ww0000    时间: 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秒后再获取一次坐标,然后进行两次坐标的判断,如何不一样,就
报警!




欢迎光临 批处理之家 (http://bbs.bathome.net/) Powered by Discuz! 7.2