1

I am trying to programmatically move the pointer position on a UWP app running on an Raspberry Pi 3. When I run the app on my Local Machine, the line:

Window.Current.CoreWindow.PointerPosition = new Point(512, 384);

works as expected.

When I deploy the app to the Pi 3, the above code has no effect at all. Is there another way I should be doing this? My end goal is to use Mouse movements in the X direction as input to a tuning function. I need to be able to indefinitely detect motion in the X direction. The way I am trying to do it now is to use the PointerMoved event. The problem with this is that when the pointer hits the left or right boundary of the window it no longer fires the event if I continue moving the mouse in that direction. My simple solution was to programmatically center the cursor if it hits the boundary. As I said this works fine on my Local PC, but does not work on the Raspberry Pi.

Koopakiller
  • 2,838
  • 3
  • 32
  • 47
radio_dude
  • 11
  • 1

1 Answers1

1

Try with injection:

    private InputInjector _inputInjector;
    private InjectedInputMouseInfo _mouse;

    private Vector2 _positionDelta;

    public MainPage()
    {
        InitializeComponent();
        Loaded += MainPage_Loaded;
    }

    private void MainPage_Loaded(object sender, RoutedEventArgs e)
    {
        _inputInjector = InputInjector.TryCreate();
        _inputInjector.InitializeTouchInjection(InjectedInputVisualizationMode.Indirect);

        RunMouse();
    }

    private async void RunMouse()
    {
        _positionDelta = Vector2.One;

        for (int i = 0; i < 500; i++)
        {
            await Task.Delay(10);

            if (i == 100) PointDown();
            else if (i == 400) PointUp();
            else PointMove();

            _inputInjector.InjectMouseInput(new List<InjectedInputMouseInfo>{ _mouse });
        }
    }

    private void PointDown()
    {
        _mouse = new InjectedInputMouseInfo
        {
            DeltaX = (int)_positionDelta.X,
            DeltaY = (int)_positionDelta.Y,
            MouseOptions = InjectedInputMouseOptions.LeftDown,
        };
    }

    private void PointUp()
    {
        _mouse = new InjectedInputMouseInfo
        {
            DeltaX = (int)_positionDelta.X,
            DeltaY = (int)_positionDelta.Y,
            MouseOptions = InjectedInputMouseOptions.LeftUp,
        };
    }

    private void PointMove()
    {
        _mouse = new InjectedInputMouseInfo
        {
            DeltaX = (int)_positionDelta.X,
            DeltaY = (int)_positionDelta.Y,
            MouseOptions = InjectedInputMouseOptions.Move,
        };
    }

This sample moves mouse with left button up/down

To enable this feature you must add to manifest few lines. In Package tag add

xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities" 

In Capabilities add

<rescap:Capability Name="inputInjection" /><rescap:Capability Name="inputInjectionBrokered" />

This enables restricted capabilities.

Jet Chopper
  • 1,478
  • 13
  • 22