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 26 27 28 29 30 31 |
$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 for () { Start-Sleep -m 1000 $dX = ([System.Windows.Forms.Cursor]::Position.X) #X coordinates $dY = ([System.Windows.Forms.Cursor]::Position.Y) #Y coordinates Write-Host $dX,$dY #print coordinates $PixelColorRef = $GDI::GetPixelColor($dX,$dY) $PixelColorRef [System.Drawing.Color]::FromArgb($PixelColorRef) } |