我正在研究用深度相机识别的手势来控制鼠标光标的实现。我想移动光标并执行鼠标左键。如何在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);
});
}
但是没有反应。您能给我一些建议吗?]
如this answer中所述,出于明显的安全原因,不能在UWP应用中使用mouse_event。