private void StartClicking(object sender, KeyPressEventArgs keyEventArguments) { if (keyEventArguments.KeyChar == 'p' && !IsClickingEnabled) { IColourPicker colourPicker = new ColourPicker(); IVideoDisplay display = new WindowsScreen(); IVideoDisplay currentWindow = WindowsApplication.GetForeground(); ICursor cursor = new WindowsCursor(); Color colour = colourPicker.GetFromDisplayPosition(display, cursor.GetPosition()); IPixelFinder pixelFinder = new PixelFinder(); IClicker clicker = new Clicker(); Thread clickingThread = new Thread(() => { IsClickingEnabled = true; while (IsClickingEnabled) { var clickedPosition = pixelFinder.FindPixelPosition(currentWindow, colour); if (clickedPosition.HasValue) { clicker.Click((int)currentWindow.Handle, clickedPosition.Value); } Thread.Sleep(TimeSpan.FromSeconds(1)); } }); clickingThread.Start(); } }
public void FindPixelPosition() { IVideoDisplay videoDisplay = new WindowsDisplay(); ICursor cursor = new WindowsCursor(); IColourPicker colorPicker = new ColourPicker(); Color colourAtCursor = colorPicker.GetFromDisplayPosition(videoDisplay, cursor.GetPosition()); var point = PixelFinder.FindPixelPosition(videoDisplay, colourAtCursor); Assert.IsNotNull(point, "Could not find the pixel you were hovering over on the screen."); }