本帖最后由 pcl_test 于 2015-4-8 13:30 编辑
结合vbs代码- @echo off
- more +5 %~nx0>"%temp%\getCursor.vbs"
- for /f "tokens=1*" %%i in ('cscript /nologo "%temp%\getCursor.vbs"') do echo X=%%i Y=%%j
- pause
- exit
- Option Explicit
- 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" & Chr(13) & _
- "Private Type POINTAPI : X As Long : Y As Long : End Type" & Chr(13) & _
- "Private Declare Function GetCursorPos Lib ""user32"" (lpPoint As POINTAPI) As Long" & Chr(13) & _
- "Sub SetCursor(x as Long, y as Long) : SetCursorPos x, y : End Sub" & Chr(13) & _
- "Public Function GetXCursorPos() As Long" & Chr(13) & _
- "Dim pt As POINTAPI : GetCursorPos pt : GetXCursorPos = pt.X" & Chr(13) & _
- "End Function" & Chr(13) & _
- "Public Function GetYCursorPos() As Long" & Chr(13) & _
- "Dim pt As POINTAPI: GetCursorPos pt : GetYCursorPos = pt.Y" & Chr(13) & _
- "End Function"
- oModule.CodeModule.AddFromString strCode
- x = oExcel.Run("GetXCursorPos")
- y = oExcel.Run("GetYCursorPos")
- WScript.Echo x, y
- oExcel.DisplayAlerts = False
- oBook.Close
- oExcel.Quit
复制代码
|