Я пытаюсь эмулировать поведение виртуальной сенсорной панели Windows 10, т. Е. Когда пользователь касается элемента управления внутри приложения и перемещает палец, системный курсор будет отражать его движение.Тем не менее, я замечаю, что, похоже, существует некоторый конфликт между системой, обрабатывающей сенсорный ввод и ввод одновременно с мышью, когда сенсорный ввод хочет скрыть курсор, а ввод мыши хочет показать курсор.
Я начал ссоздание стандартного приложения UWP в VS-2019, вот мой MainPage.xaml, где единственное, что я изменяю - это даю свой Grid свойство Name = "Touchpad" , чтобы я мог отслеживать события указателя внутри него:
<Page
x:Class="Playground.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Playground"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid Background="Black" Name="Touchpad">
</Grid>
</Page>
Я использую Windows.UI.Input.Preview.Injection
для перемещения курсора мыши.Поскольку это Ограниченная возможность Я внес изменения в свой проект, как определено здесь: https://docs.microsoft.com/en-us/uwp/api/windows.ui.input.preview.injection#remarks
public sealed partial class MainPage : Page
{
private Point lastPosition;
private InputInjector inputInjector = InputInjector.TryCreate();
public MainPage()
{
this.InitializeComponent();
ApplicationView.PreferredLaunchViewSize = new Size(480, 480);
ApplicationView.PreferredLaunchWindowingMode = ApplicationViewWindowingMode.PreferredLaunchViewSize;
Touchpad.PointerPressed += new PointerEventHandler(Touchpad_PointerPressed);
Touchpad.PointerReleased += new PointerEventHandler(Touchpad_PointerReleased);
Touchpad.PointerMoved += new PointerEventHandler(Touchpad_PointerMoved);
}
private void Touchpad_PointerMoved(object sender, PointerRoutedEventArgs e)
{
e.Handled = true;
PointerPoint pointer = e.GetCurrentPoint(Touchpad);
Point currentPosition = pointer.Position;
if (pointer.PointerDevice.PointerDeviceType == Windows.Devices.Input.PointerDeviceType.Touch &&
lastPosition != currentPosition &&
pointer.Properties.IsPrimary == true)
{
Point delta = new Point(currentPosition.X - lastPosition.X, currentPosition.Y - lastPosition.Y);
InjectedInputMouseInfo mouseInfo = new InjectedInputMouseInfo();
mouseInfo.MouseOptions = InjectedInputMouseOptions.Move;
mouseInfo.DeltaX = (int)delta.X;
mouseInfo.DeltaY = (int)delta.Y;
if (inputInjector != null)
{
inputInjector.InjectMouseInput(new[] { mouseInfo });
}
lastPosition = currentPosition;
}
}
private void Touchpad_PointerReleased(object sender, PointerRoutedEventArgs e)
{
e.Handled = true;
lastPosition = new Point(0,0);
}
private void Touchpad_PointerPressed(object sender, PointerRoutedEventArgs e)
{
e.Handled = true;
PointerPoint pointer = e.GetCurrentPoint(Touchpad);
if (pointer.PointerDevice.PointerDeviceType == Windows.Devices.Input.PointerDeviceType.Touch &&
pointer.Properties.IsPrimary == true)
{
lastPosition = pointer.Position;
Window.Current.CoreWindow.PointerCursor = null;
}
}
}
Я заметил, что при перемещении пальца, кажется, есть два курсора (или тот, который подпрыгивает очень быстро) - один в самом приложении и один в системе / на рабочем столе.Я добавил Window.Current.CoreWindow.PointerCursor = null;
, который успешно скрывает курсор внутри приложения, но тот, которым управляет инъекция, мигает / мигает.
Я чувствую, что что-то упустил, как обратная связь на виртуальной сенсорной панелив Win10 маслянистая гладкость и, как я знаю, также приложение UWP ...