1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
$GDI = Add-Type -MemberDefinition @' [DllImport("user32.dll")] static extern IntPtr GetDC(IntPtr hwnd); [DllImport("user32.dll")] static extern Int32 ReleaseDC(IntPtr hwnd, IntPtr hdc); [DllImport("gdi32.dll")] static extern uint GetPixel(IntPtr hdc,int nXPos,int nYPos); static public int GetPixelColor(int x, int y) { IntPtr hdc = GetDC(IntPtr.Zero); uint pixel = GetPixel(hdc, x, y); ReleaseDC(IntPtr.Zero,hdc); return (int)pixel; } '@ -Name GDI -PassThru while($true) { $PixelColorRef = $GDI::GetPixelColor([System.Windows.Forms.Cursor]::Position.X,[System.Windows.Forms.Cursor]::Position.Y) [System.Drawing.Color]::FromArgb($PixelColorRef) | Select-Object B,G,R } |