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

[问题求助] VBS 如何抓取屏幕某一点坐标的颜色值?

[复制链接]
发表于 2012-7-27 23:32:31 | 显示全部楼层 |阅读模式
本帖最后由 pcl_test 于 2017-4-16 16:42 编辑

VBS 如何抓取屏幕某一点坐标颜色?
发表于 2017-4-16 16:42:05 | 显示全部楼层
本帖最后由 pcl_test 于 2017-4-27 08:29 编辑
  1. '运行后在屏幕任意位置点击即可
  2. Set ws = CreateObject("Wscript.Shell")
  3. Set fso = CreateObject("Scripting.FileSystemObject")

  4. If LCase(Right(WScript.FullName, 11)) = "wscript.exe" Then
  5.     ws.run "cscript.exe -nologo """ & WSH.ScriptFullName & """", 0
  6.     WSH.Quit
  7. End If

  8. Set tmp = fso.GetSpecialFolder(2)
  9. Set systemroot = fso.GetSpecialFolder(0)
  10. net = systemroot&"\Microsoft.NET\Framework"
  11. Call CreateCs
  12. Set SubFolders = fso.GetFolder(net).SubFolders
  13. For Each Folder In SubFolders
  14.     If fso.FileExists(Folder&"\csc.exe") Then
  15.         cscpath = Folder&"\csc.exe"
  16.         Exit For
  17.     End If
  18. Next

  19. If cscpath = "" Then
  20.     Msgbox "未安装Microsoft .NET Framework 2.0及以上版本组件或是相关程序缺失!"
  21.     WSH.Quit
  22. Else
  23.     If not fso.FileExists(tmp&"\$GetPixelColor.exe") Then
  24.         ws.Run cscpath&" /out:"""&tmp&"\$GetPixelColor.exe"" """&tmp&"\$GetPixelColor.cs""", 0, True
  25.     End If
  26. End If

  27. Set oExec = ws.Exec(tmp&"\$GetPixelColor.exe")
  28. Msgbox oExec.StdOut.ReadAll '结果

  29. Function CreateCs
  30.     Set cs = fso.CreateTextFile(tmp&"\$GetPixelColor.cs", 2)
  31.     cs.Write _
  32.     "using System;using System.Runtime.InteropServices;using System.Windows.Forms;" & vbCrLf & _
  33.     "using System.Drawing;using System.Threading;" & vbCrLf & _
  34.     "public class GetPixelColor {" & vbCrLf & _
  35.     "   [DllImport(""user32.dll"")]" & vbCrLf & _
  36.     "   private static extern IntPtr GetDC(IntPtr hwnd);" & vbCrLf & _
  37.     "   [DllImport(""gdi32.dll"")]" & vbCrLf & _
  38.     "   private static extern int GetPixel(IntPtr hdc, Point p);" & vbCrLf & _
  39.     "   public static void Main(string[] args){" & vbCrLf & _
  40.     "        while (true){if ((Control.MouseButtons & MouseButtons.Left) == MouseButtons.Left){" & vbCrLf & _
  41.     "           int x = Control.MousePosition.X, y = Control.MousePosition.Y;" & vbCrLf & _
  42.     "           Point p = new Point(x, y);IntPtr hdc = GetDC(IntPtr.Zero);" & vbCrLf & _
  43.     "           int c = GetPixel(hdc, p), r = (c & 0xFF);" & vbCrLf & _
  44.     "           int g = (c & 0xFF00)>>8, b = (c & 0xFF0000)>>16;" & vbCrLf & _
  45.     "           Console.WriteLine(""X:""+x+"" Y:""+y+""\r\nR:""+r+"" G:""+g+"" B:""+b+""\r\nHTML:""+" & vbCrLf & _
  46.     "               ColorTranslator.ToHtml(Color.FromArgb(r, g, b))+""\r\nHEX:""+c.ToString(""X6""));break;" & vbCrLf & _
  47.     "           }Thread.Sleep(100);" & vbCrLf & _
  48.     "}}}"
  49. End Function
复制代码

评分

参与人数 1技术 +1 收起 理由
yu2n + 1 感谢分享

查看全部评分

发表于 2017-8-31 11:30:25 | 显示全部楼层
我要点赞快乐咯
发表于 2023-5-19 18:57:42 | 显示全部楼层
牛逼牛逼,怎么这么好的帖子没人顶?
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-3-17 05:07 , Processed in 0.018680 second(s), 9 queries , File On.

Powered by Discuz! X3.5

© 2001-2026 Discuz! Team.

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