[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

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

写一段VBS,运行代码后,监测鼠标,鼠标一动就跳出警告框?
退出代码后,就正常!

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秒后再获取一次坐标,然后进行两次坐标的判断,如何不一样,就
报警!

TOP

返回列表