0

Is there a way to simulate a click at specific coordinates on Windows IoT?

I tried with mouse_event:

mouse_event(MOUSEEVENTF_LEFTDOWN, x, y, 0, 0);

but, I get this error:

System.EntryPointNotFoundException: 'Unable to find an entry point named 'mouse_event' in DLL 'user32.dll'.'. 

Is it because that function doesn't exist in the IoT version of Windows?

I saw there was SendInput, but the only syntax on the documentation is in C++. Is it possible at all to use it in C# on Windows IoT and if so how? If you have an example in mind, linking it would be very helpful. I searched around but I couldn't find something that could work on UWP.

Here is the code I used for the mouse_event:

[System.Runtime.InteropServices.DllImport("user32.dll", EntryPoint = "SetCursorPos")]
private static extern bool SetCursorPos(int X, int Y);

[System.Runtime.InteropServices.DllImport("user32.dll")]
public static extern void mouse_event(int dwFlags, int dx, int dy, int cButtons, int dwExtraInfo);

public const int MOUSEEVENTF_LEFTDOWN = 0x02;
public const int MOUSEEVENTF_LEFTUP = 0x04;
public const int MOUSEEVENTF_RIGHTDOWN = 0x08;
public const int MOUSEEVENTF_RIGHTUP = 0x10;

//...

public void Click(int x, int y)
{
    SetCursorPos(x,y);
    mouse_event(MOUSEEVENTF_LEFTDOWN, x, y, 0, 0);
    mouse_event(MOUSEEVENTF_LEFTUP, x, y, 0, 0);
}
A. E.
  • 5
  • 3

2 Answers2

2

As of Fall Creators Update Release of Windows IOT (SDK version 16299), you can use the InputInjector API in UWP apps: https://learn.microsoft.com/en-us/uwp/api/Windows.UI.Input.Preview.Injection.InputInjector

The API allows injecting mouse input among other input types.

msaleh
  • 61
  • 5
0

Neither mouse_event nor SendInput can be used in a UWP application. As documented, these API's are for

desktop apps only

If you are running this from a UWP application (which apparently you are), there is no way to automate another UWP application. The sandboxing will not allow this. This includes UI Automation.

IInspectable
  • 46,945
  • 8
  • 85
  • 181
  • Oh okay thank you. I posted another question on the larger problem I have to solve if you could check it out it'd be great. Thanks again! https://stackoverflow.com/questions/44476899/uwp-click-through-a-component-on-page – A. E. Jun 10 '17 at 18:49