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 LeftClick() { WindowsApplication currentApplication = WindowsApplication.GetForeground(); bool isSuccess = WindowsCursor.LeftClick((int)currentApplication.Handle, 0, 0); Assert.IsTrue(isSuccess); }
public void GetFromDisplayPosition() { IVideoDisplay videoDisplay = new WindowsScreen(); ICursor cursor = new WindowsCursor(); Point cursorPosition = cursor.GetPosition(); Color colourAtCursor = ColourPicker.GetFromDisplayPosition(videoDisplay, cursorPosition); Assert.IsNotNull(colourAtCursor); }
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."); }
public static void ChangeCursor(WindowsCursor cursor) => SetCursor(LoadCursor(IntPtr.Zero, (int)cursor));
public void GetPosition() { Point cursorPosition = WindowsCursor.GetPosition(); Assert.AreNotEqual(new Point(0, 0), cursorPosition); }
public static void SetCursor(WindowsCursor cursor) { SetCursor(LoadCursor(IntPtr.Zero, (int)cursor)); }