Board logo

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

作者: ecogbc    时间: 2012-7-27 23:32     标题: VBS 如何抓取屏幕某一点坐标的颜色值?

本帖最后由 pcl_test 于 2017-4-16 16:42 编辑

VBS 如何抓取屏幕某一点坐标颜色?
作者: pcl_test    时间: 2017-4-16 16:42

本帖最后由 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
复制代码

作者: shuaige100    时间: 2017-8-31 11:30

我要点赞快乐咯
作者: segree    时间: 2023-5-19 18:57

牛逼牛逼,怎么这么好的帖子没人顶?




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