This section provides comprehensive documentation for the Universal Windows Platform (UWP) input APIs, enabling developers to handle user interactions seamlessly across various devices.
Understanding the fundamental principles of input handling in UWP is crucial for building responsive and accessible applications.
Pointer input encompasses touch, mouse, pen, and other pointing device interactions. UWP provides a unified model for handling these events.
Key Classes:
Windows.UI.Core.CoreDispatcher
Windows.UI.Xaml.Input.PointerRoutedEventArgs
Windows.Devices.Input.PointerDevice
// Example: Handling PointerPressed event in XAML
private void MyElement_PointerPressed(object sender, PointerRoutedEventArgs e)
{
var pointerPoint = e.GetCurrentPoint(MyElement);
var position = pointerPoint.Position;
System.Diagnostics.Debug.WriteLine($"Pointer pressed at: {position.X}, {position.Y}");
}
Capture and process keyboard events for text input, navigation, and custom shortcuts.
Key Classes:
Windows.UI.Core.KeyEventArgs
Windows.System.VirtualKey
// Example: Handling KeyDown event
private void MyTextBox_KeyDown(object sender, KeyRoutedEventArgs e)
{
if (e.Key == VirtualKey.Enter)
{
System.Diagnostics.Debug.WriteLine("Enter key pressed!");
e.Handled = true; // Mark event as handled
}
}
Utilize built-in gesture recognition to simplify common user interactions like taps, swipes, and pinch-to-zoom.
Key Classes:
Windows.UI.Xaml.Input.GestureRecognizer
Windows.UI.Xaml.Input.ManipulationModes
// Example: Enabling manipulation on an element
public MyControl()
{
InitializeComponent();
ManipulationMode = ManipulationModes.All; // Enable all manipulation gestures
}
private void MyElement_ManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e)
{
// Apply transformations based on e.Delta.Translation, e.Delta.Rotation, e.Delta.Scale
System.Diagnostics.Debug.WriteLine($"Manipulation Delta: Translation={e.Delta.Translation.X}");
}
Explore specialized APIs for handling complex input scenarios and device-specific features.
Leverage the power of pen input for rich drawing and annotation experiences.
Key Namespaces:
Windows.UI.Input.Pen
Windows.UI.Xaml.Controls.InkToolbar
Support for game controllers, joysticks, and other input peripherals.
Key Namespaces:
Windows.Gaming.Input
Integrate voice commands and speech recognition into your UWP applications.
Key Namespaces:
Windows.Media.SpeechRecognition