Guest User

Untitled

a guest
Aug 29th, 2019
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.76 KB | None | 0 0
  1. using System;
  2. using System.Drawing;
  3. using System.Media;
  4. using System.Runtime.InteropServices;
  5. using System.Threading;
  6.  
  7. sealed class Win32
  8. {
  9.     // Source: https://stackoverflow.com/questions/753132/how-to-get-the-colour-of-a-pixel-at-x-y-using-c/753157#753157
  10.     [DllImport("user32.dll")]
  11.     static extern IntPtr GetDC(IntPtr hwnd);
  12.  
  13.     [DllImport("user32.dll")]
  14.     static extern Int32 ReleaseDC(IntPtr hwnd, IntPtr hdc);
  15.  
  16.     [DllImport("gdi32.dll")]
  17.     static extern uint GetPixel(IntPtr hdc, int nXPos, int nYPos);
  18.  
  19.     static public System.Drawing.Color GetPixelColor(int x, int y)
  20.     {
  21.         IntPtr hdc = GetDC(IntPtr.Zero);
  22.         uint pixel = GetPixel(hdc, x, y);
  23.         ReleaseDC(IntPtr.Zero, hdc);
  24.         Color color = Color.FromArgb((int)(pixel & 0x000000FF),
  25.                      (int)(pixel & 0x0000FF00) >> 8,
  26.                      (int)(pixel & 0x00FF0000) >> 16);
  27.         return color;
  28.     }
  29.  
  30.     // Main Method
  31.     static public void Main(String[] args)
  32.     {
  33.         Int32 x = 740;
  34.         Int32 y = 560;
  35.         // System.Windows.Forms.Cursor.Position = new Point(x, y);
  36.  
  37.         Color oldColor = GetPixelColor(x, y);
  38.         Color newColor;
  39.         while (true) {
  40.             newColor = GetPixelColor(x, y);
  41.             Console.WriteLine(newColor);
  42.             if (newColor.ToArgb() != oldColor.ToArgb())
  43.             {
  44.                 break;
  45.             }
  46.             oldColor = newColor;
  47.             Thread.Sleep(1000);
  48.         }
  49.         using (var soundPlayer = new SoundPlayer(@"c:\Windows\Media\tada.wav"))
  50.         {
  51.             Console.WriteLine("WEEEEUUUUWEEEEEUUUU");
  52.             while (true)
  53.             {
  54.                 soundPlayer.Play();
  55.                 Thread.Sleep(1000);
  56.             }
  57.         }
  58.     }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment