【问题标题】:UWP C# mouse control with gestures带有手势的 UWP C# 鼠标控制
【发布时间】:2020-06-01 12:34:56
【问题描述】:

我正在使用深度相机识别的手势来控制鼠标光标。我想移动光标并执行鼠标左键单击。它如何在 UWP C# 中实现?

我已经尝试过这个鼠标移动,它工作正常,但是其他对象的事件没有被触发(用鼠标控制一切都很好):

Window.Current.CoreWindow.PointerPosition = new Point(pointerPosition.X - deltaX, pointerPosition.Y + deltaY);

鼠标点击我试过这个:

    [DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
    public static extern void mouse_event(uint dwFlags, uint dx, uint dy, uint cButtons, uint dwExtraInfo);
    //Mouse actions
    private const uint MOUSEEVENTF_LEFTDOWN = 0x0002;
    private const uint MOUSEEVENTF_LEFTUP = 0x0004;

    public async System.Threading.Tasks.Task DoMouseClickAsync()
    {
        //Call the imported function with the cursor's current position

        await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
        {
            var x = (uint)Window.Current.CoreWindow.PointerPosition.X;
            var y = (uint)Window.Current.CoreWindow.PointerPosition.Y;

            mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, x, y, 0, 0);
        });
    }

但没有反应。能给我一点建议吗?)

【问题讨论】:

    标签: c# uwp gesture


    【解决方案1】:

    正如this answer 中提到的,mouse_event 不能在 UWP 应用中使用(出于明显的安全原因)。

    【讨论】:

    • 点击此链接后,我发现提到了InjectedInputMouseInfo class,它帮助我解决了我的问题。但是在微软商店中添加了一些问题:)
    猜你喜欢
    • 1970-01-01
    • 2018-08-07
    • 1970-01-01
    • 2018-07-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多