Board logo

标题: [系统相关] 哪个第三方工具可以获取鼠标坐标 [打印本页]

作者: 522235677    时间: 2015-4-8 11:06     标题: 哪个第三方工具可以获取鼠标坐标

是可以获取鼠标在屏幕上的坐标,不是cmd窗口中点击的坐标。
作者: 523066680    时间: 2015-4-8 11:36

看到某君回复了又删了?
应该有好几个工具,论坛里找找
作者: 522235677    时间: 2015-4-8 13:14

回复 2# 523066680


    论坛里我只找到了一个,但是需要按一下end键然后才能显示出坐标。我想找到不用操作的直接就能获取
作者: pcl_test    时间: 2015-4-8 13:24

本帖最后由 pcl_test 于 2015-4-8 13:30 编辑

结合vbs代码
  1. @echo off
  2. more +5 %~nx0>"%temp%\getCursor.vbs"
  3. for /f "tokens=1*" %%i in ('cscript /nologo "%temp%\getCursor.vbs"') do echo X=%%i Y=%%j
  4. pause
  5. exit
  6. Option Explicit
  7. Dim WshShell
  8. Dim oExcel, oBook, oModule
  9. Dim strRegKey, strCode, x, y
  10. Set oExcel = CreateObject("Excel.Application")
  11. set WshShell = CreateObject("wscript.Shell")
  12. strRegKey = "HKEY_CURRENT_USER\Software\Microsoft\Office\$\Excel\Security\AccessVBOM"
  13. strRegKey = Replace(strRegKey, "$", oExcel.Version)
  14. WshShell.RegWrite strRegKey, 1, "REG_DWORD"
  15. Set oBook = oExcel.Workbooks.Add
  16. Set oModule = obook.VBProject.VBComponents.Add(1)
  17. strCode = _
  18. "Private Declare Function SetCursorPos Lib ""user32"" (ByVal x As Long, ByVal y As Long) As Long" & Chr(13) & _
  19. "Private Type POINTAPI : X As Long : Y As Long : End Type"                                         & Chr(13) & _
  20. "Private Declare Function GetCursorPos Lib ""user32"" (lpPoint As POINTAPI) As Long"               & Chr(13) & _
  21. "Sub SetCursor(x as Long, y as Long) : SetCursorPos x, y : End Sub"                                & Chr(13) & _
  22. "Public Function GetXCursorPos() As Long"                                                          & Chr(13) & _
  23.      "Dim pt As POINTAPI : GetCursorPos pt : GetXCursorPos = pt.X"                                  & Chr(13) & _
  24. "End Function"                                                                                     & Chr(13) & _
  25. "Public Function GetYCursorPos() As Long"                                                          & Chr(13) & _
  26.      "Dim pt As POINTAPI: GetCursorPos pt : GetYCursorPos = pt.Y"                                   & Chr(13) & _
  27. "End Function"
  28. oModule.CodeModule.AddFromString strCode
  29. x = oExcel.Run("GetXCursorPos")
  30. y = oExcel.Run("GetYCursorPos")
  31. WScript.Echo x, y
  32. oExcel.DisplayAlerts = False
  33. oBook.Close
  34. oExcel.Quit
复制代码

作者: 522235677    时间: 2015-4-8 16:26

回复 4# pcl_test


    谢啦,网上也搜到过这个脚本,不过得有excel的支持
作者: yiwuyun    时间: 2015-4-10 17:44

因为感兴趣,所以研究了一下powershell对win32函数的调用,但只懂点皮毛:
  1. if ($true){}# == ($true){}# goto ___yiwuyun
  2. <#BeginBatOperation#
  3. :___yiwuyun
  4. @echo off&setlocal&cls
  5. (echo $yiwuyun_fileName="%~f0"&echo $strPath="%~dp0"&type "%~f0")|powershell -command -
  6. pause
  7. exit/b 0
  8. #EndBatOperation#>
  9. <#StartPowerShell#>
  10. $Signature = @"
  11. [System.Runtime.InteropServices.DllImport("user32.dll",EntryPoint="GetCursorPos")]public static extern bool GetCursorPos(out long lPoint);
  12. "@
  13. $MouseLocation= Add-Type -MemberDefinition $Signature -Name "Win32CursorPos" -Namespace Win32Functions -PassThru
  14. $point=[int64]0;
  15. $MouseLocation::GetCursorPos([ref] $point)|Out-Null;
  16. $dy=[int16]($point -shr 32);
  17. $dx=[int16]($point -band 0xffff);
  18. "鼠标坐标:($dx,$dy)";
  19. <#EndPowerShell#>
  20. <#StartJS#
  21. #EndJS#>
  22. <#StartVBS#
  23. #EndVBS#>
  24. <#StartRouterCommand#
  25. #EndRouterCommand#>
复制代码

作者: yiwuyun    时间: 2015-4-12 17:44

一翻思索,总算解决了不能传结构的问题。看来要学好powershell还需要学学C#
  1. if ($true){}# == ($true){}# goto ___yiwuyun
  2. <#BeginBatOperation#
  3. :___yiwuyun
  4. @echo off&setlocal&cls
  5. (echo $yiwuyun_fileName="%~f0"&echo $strPath="%~dp0"&type "%~f0")|powershell -command -
  6. pause
  7. exit/b 0
  8. #EndBatOperation#>
  9. <#StartPowerShell#>
  10. $TypeSignature=@"
  11. public struct Point{
  12. public int x,y;
  13. };
  14. public class MyPoint{
  15.   [System.Runtime.InteropServices.DllImport("user32.dll",EntryPoint="GetCursorPos")]
  16.   private static extern bool GetCursorPos(ref Point lpPoint);
  17.   public Point GetCursor(){
  18.     Point lpPoint=new Point();
  19.     GetCursorPos(ref lpPoint);
  20.     return lpPoint;
  21.   }
  22. }
  23. "@
  24. Add-Type -TypeDefinition $TypeSignature;
  25. $point=New-Object MyPoint;
  26. "鼠标坐标:`($($point.GetCursor().x),$($point.GetCursor().y)`)"
  27. <#EndPowerShell#>
  28. <#StartJS#
  29. #EndJS#>
  30. <#StartVBS#
  31. #EndVBS#>
  32. <#StartRouterCommand#
  33. #EndRouterCommand#>
复制代码





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