Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Drawing;
- using System.Media;
- using System.Runtime.InteropServices;
- using System.Threading;
- sealed class Win32
- {
- // Source: https://stackoverflow.com/questions/753132/how-to-get-the-colour-of-a-pixel-at-x-y-using-c/753157#753157
- [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 System.Drawing.Color GetPixelColor(int x, int y)
- {
- IntPtr hdc = GetDC(IntPtr.Zero);
- uint pixel = GetPixel(hdc, x, y);
- ReleaseDC(IntPtr.Zero, hdc);
- Color color = Color.FromArgb((int)(pixel & 0x000000FF),
- (int)(pixel & 0x0000FF00) >> 8,
- (int)(pixel & 0x00FF0000) >> 16);
- return color;
- }
- // Main Method
- static public void Main(String[] args)
- {
- Int32 x = 740;
- Int32 y = 560;
- // System.Windows.Forms.Cursor.Position = new Point(x, y);
- Color oldColor = GetPixelColor(x, y);
- Color newColor;
- while (true) {
- newColor = GetPixelColor(x, y);
- Console.WriteLine(newColor);
- if (newColor.ToArgb() != oldColor.ToArgb())
- {
- break;
- }
- oldColor = newColor;
- Thread.Sleep(1000);
- }
- using (var soundPlayer = new SoundPlayer(@"c:\Windows\Media\tada.wav"))
- {
- Console.WriteLine("WEEEEUUUUWEEEEEUUUU");
- while (true)
- {
- soundPlayer.Play();
- Thread.Sleep(1000);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment