找回密码
 注册
搜索
[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
查看: 27720|回复: 6

[系统相关] 哪个第三方工具可以获取鼠标坐标

[复制链接]
发表于 2015-4-8 11:06:55 | 显示全部楼层 |阅读模式
是可以获取鼠标在屏幕上的坐标,不是cmd窗口中点击的坐标。
发表于 2015-4-8 11:36:19 | 显示全部楼层
看到某君回复了又删了?
应该有好几个工具,论坛里找找
 楼主| 发表于 2015-4-8 13:14:09 | 显示全部楼层
回复 2# 523066680


    论坛里我只找到了一个,但是需要按一下end键然后才能显示出坐标。我想找到不用操作的直接就能获取
发表于 2015-4-8 13:24:58 | 显示全部楼层
本帖最后由 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
复制代码
 楼主| 发表于 2015-4-8 16:26:45 | 显示全部楼层
回复 4# pcl_test


    谢啦,网上也搜到过这个脚本,不过得有excel的支持
发表于 2015-4-10 17:44:19 | 显示全部楼层
因为感兴趣,所以研究了一下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#>
复制代码
发表于 2015-4-12 17:44:47 | 显示全部楼层
一翻思索,总算解决了不能传结构的问题。看来要学好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#>
复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|批处理之家 ( 渝ICP备10000708号 )

GMT+8, 2026-3-19 10:14 , Processed in 0.020666 second(s), 8 queries , File On.

Powered by Discuz! X3.5

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表