UWP:模拟 Windows IoT 上特定坐标处的点击 [英] UWP: Simulate click at specific coordinates on Windows IoT
问题描述
有没有办法在 Windows IoT 上模拟特定坐标处的点击?
Is there a way to simulate a click at specific coordinates on Windows IoT?
我尝试使用 mouse_event:
I tried with mouse_event:
mouse_event(MOUSEEVENTF_LEFTDOWN, x, y, 0, 0);
但是,我收到此错误:
System.EntryPointNotFoundException: 'Unable to find an entry point named 'mouse_event' in DLL 'user32.dll'.'.
是不是因为 Windows 的 IoT 版本中不存在该功能?
Is it because that function doesn't exist in the IoT version of Windows?
我看到有 SendInput,但文档中唯一的语法是 C++.是否可以在 Windows IoT 上的 C# 中使用它,如果可以,如何使用?如果你有一个例子,链接它会非常有帮助.我四处搜索,但找不到可以在 UWP 上工作的东西.
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.
这是我用于 mouse_event 的代码:
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);
}
推荐答案
mouse_event 或 SendInput 可用于 UWP 应用程序.如文档所述,这些 API 用于
Neither mouse_event nor SendInput can be used in a UWP application. As documented, these API's are for
仅限桌面应用
如果您从 UWP 应用程序(显然您是)运行此程序,则无法自动执行另一个 UWP 应用程序.沙箱不允许这样做.这包括UI 自动化.
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.
这篇关于UWP:模拟 Windows IoT 上特定坐标处的点击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!