【问题标题】:UWP: Simulate click at specific coordinates on Windows IoTUWP:在 Windows IoT 上模拟特定坐标的点击
【发布时间】:2017-06-10 04:05:03
【问题描述】:

有没有办法在 Windows IoT 上模拟特定坐标的点击?

我尝试了 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没有这个功能?

我看到有 SendInput,但文档中唯一的语法是 C++。是否有可能在 Windows IoT 上的 C# 中使用它,如果可以,如何使用?如果您有一个例子,链接它会非常有帮助。我四处搜索,但找不到可以在 UWP 上运行的东西。

这是我用于 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);
}

【问题讨论】:

    标签: c# uwp raspberry-pi win-universal-app windowsiot


    【解决方案1】:

    从 Windows IOT(SDK 版本 16299)的 Fall Creators Update Release 开始,您可以在 UWP 应用中使用 InputInjector API:https://docs.microsoft.com/en-us/uwp/api/Windows.UI.Input.Preview.Injection.InputInjector

    API 允许在其他输入类型中注入鼠标输入。

    【讨论】:

      【解决方案2】:

      mouse_eventSendInput 都不能在 UWP 应用程序中使用。如文件所述,这些 API 用于

      仅限桌面应用

      如果您从 UWP 应用程序(显然您是)运行它,则无法自动化另一个 UWP 应用程序。沙盒不允许这样做。这包括UI Automation

      【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多