-1

I am attempting to create an auto-clicker application and was curious if there is any actual way to click with just x and y cords, and if so can I do it outside of the window? I am using C# UWP.

  • Does this answer your question? [UWP: Simulate click at specific coordinates on Windows IoT](https://stackoverflow.com/questions/44469382/uwp-simulate-click-at-specific-coordinates-on-windows-iot) – Orace Mar 21 '21 at 18:03
  • Sadly this doesn't. I can't see any place where it talks about condiments. – Shutdoor Mar 21 '21 at 18:18

1 Answers1

1

You could try to simulate a mouse click by using APIs under Windows.UI.Input.Preview.Inject namespace. And you could inject a mouse click outside of the window by this way. More information about simulating user input through input injection, please refer to the document. Note to add the inputInjectionBrokered capability.

Please check the following code as a sample:

private void Button_Click(object sender, RoutedEventArgs e)
{
    InputInjector inputInjector = InputInjector.TryCreate();
    var infoPosition = new InjectedInputMouseInfo();
    infoPosition.MouseOptions = InjectedInputMouseOptions.Absolute;
    infoPosition.DeltaX = 50;
    infoPosition.DeltaY = 50;

    var infoDown = new InjectedInputMouseInfo();
    infoDown.DeltaX = 50;
    infoDown.DeltaY = 50;
    infoDown.MouseOptions = InjectedInputMouseOptions.LeftDown;

    var infoUp = new InjectedInputMouseInfo();
    infoUp.DeltaX = 0;
    infoUp.DeltaY = 0;
    infoUp.MouseOptions = InjectedInputMouseOptions.LeftUp;

    inputInjector.InjectMouseInput(new[] { infoPosition,infoDown, infoUp });
    for(int i=0;i<10;i++)
    {
        Thread.Sleep(3000);
        inputInjector.InjectMouseInput(new[] { infoPosition, infoDown, infoUp });

    }

}

Note that values of DeltaX property and DeltaY property are relative to the last mouse wheel event, you need to set MouseOptions property as InjectedInputMouseOptions.Absolute to indicate the coordinates is an absolute value.

YanGu
  • 3,006
  • 1
  • 3
  • 7
  • So, does this move to the absolute location (50,50) and then lefts click with a delta of (50,50), i.e. the click is at (100,100)? Why is there a loop doing this injection 10 times? I saw that elsewhere but can't see why it's desirable. – james.sw.clark Dec 29 '21 at 00:15