CoreIndependentInputSource CoreIndependentInputSource CoreIndependentInputSource CoreIndependentInputSource Class

Definition

Surfaces core input API for interoperation scenarios.

public : sealed class CoreIndependentInputSource : ICoreInputSourceBase, ICorePointerInputSource
struct winrt::Windows::UI::Core::CoreIndependentInputSource : ICoreInputSourceBase, ICorePointerInputSource
public sealed class CoreIndependentInputSource : ICoreInputSourceBase, ICorePointerInputSource
Public NotInheritable Class CoreIndependentInputSource Implements ICoreInputSourceBase, ICorePointerInputSource
Attributes
Windows 10 requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

Examples

Initializing independent input.

// MainPage.cpp
#include "pch.h"
#include "MainPage.h"
#include <winrt/Windows.System.Threading.h>
#include <winrt/Windows.UI.Core.h>
#include <winrt/Windows.UI.Xaml.Controls.h>

using namespace winrt;
using namespace Windows::UI::Xaml;
using namespace Windows::UI::Xaml::Controls;

Windows::Foundation::IAsyncAction m_inputLoopWorker;
...
    // Create a task to register for independent input and begin processing input messages.
    Windows::System::Threading::WorkItemHandler workItemHandler([this](Windows::Foundation::IAsyncAction const& /* action */)
    {
        // The CoreIndependentInputSource will raise pointer events for the specified device types on whichever thread it's created on.
        Windows::UI::Core::CoreIndependentInputSource coreInput{
            MySwapChainPanel().CreateCoreIndependentInputSource(
                Windows::UI::Core::CoreInputDeviceTypes::Mouse |
                Windows::UI::Core::CoreInputDeviceTypes::Touch |
                Windows::UI::Core::CoreInputDeviceTypes::Pen)
        };

        // Register for pointer events, which will be raised on the background thread.
        coreInput.PointerPressed({ this, &MainPage::SCP_OnPointerPressed });
        coreInput.PointerMoved({ this, &MainPage::SCP_OnPointerMoved });
        coreInput.PointerReleased({ this, &MainPage::SCP_OnPointerReleased });

        // Begin processing input messages as they're delivered.
        coreInput.Dispatcher().ProcessEvents(Windows::UI::Core::CoreProcessEventsOption::ProcessUntilQuit);
    });

    // Run task on a dedicated high priority background thread.
    m_inputLoopWorker = Windows::System::Threading::ThreadPool::RunAsync(
        workItemHandler, Windows::System::Threading::WorkItemPriority::High,
        Windows::System::Threading::WorkItemOptions::TimeSliced);
...
void MainPage::SCP_OnPointerPressed(Windows::Foundation::IInspectable const& /* sender */,
    Windows::UI::Core::PointerEventArgs const& /* args */) {}
void MainPage::SCP_OnPointerMoved(Windows::Foundation::IInspectable const& /* sender */,
    Windows::UI::Core::PointerEventArgs const& /* args */) {}
void MainPage::SCP_OnPointerReleased(Windows::Foundation::IInspectable const& /* sender */,
    Windows::UI::Core::PointerEventArgs const& /* args */) {}
// Create a task to register for independent input and begin processing input messages.
auto workItemHandler = ref new WorkItemHandler([this] (IAsyncAction ^)
{
   // The CoreIndependentInputSource will raise pointer events for the specified device types on whichever thread it's created on.
   CoreIndependentInputSource^ coreInput = CreateCoreIndependentInputSource(
      Windows::UI::Core::CoreInputDeviceTypes::Mouse |
      Windows::UI::Core::CoreInputDeviceTypes::Touch |
      Windows::UI::Core::CoreInputDeviceTypes::Pen
   );

   // Register for pointer events, which will be raised on the background thread.
   coreInput->PointerPressed += ref new TypedEventHandler<Object^, PointerEventArgs^>(this, &MyClass::OnPointerPressed);
   coreInput->PointerMoved += ref new TypedEventHandler<Object^, PointerEventArgs^>(this, &MyClass::OnPointerMoved);
   coreInput->PointerReleased += ref new TypedEventHandler<Object^, PointerEventArgs^>(this, &MyClass::OnPointerReleased);

   // Begin processing input messages as they're delivered.
   coreInput->Dispatcher->ProcessEvents(CoreProcessEventsOption::ProcessUntilQuit);
});

// Run task on a dedicated high priority background thread.
m_inputLoopWorker = ThreadPool::RunAsync(workItemHandler, WorkItemPriority::High, WorkItemOptions::TimeSliced);

For more example code of how to use CreateCoreIndependentInputSource and CoreIndependentInputSource, see the DrawingPanel class definition that is part of the XAML SwapChainPanel DirectX interop sample.

Remarks

Create an instance of this class by calling SwapChainBackgroundPanel::CreateCoreIndependentInputSource or SwapChainPanel::CreateCoreIndependentInputSource.

The CoreIndependentInputSource class enables an app to handle input and rendering independent of the XAML UI thread, because you're intentionally providing the input processing logic on a background thread. You must call CreateCoreIndependentInputSource from a non-UI thread, otherwise the CreateCoreIndependentInputSource method call will fail.

Properties

Dispatcher Dispatcher Dispatcher Dispatcher

Gets the event dispatcher for the window.

DispatcherQueue DispatcherQueue DispatcherQueue DispatcherQueue

Gets the DispatcherQueue associated with this CoreIndependentInputSource.

HasCapture HasCapture HasCapture HasCapture

Gets a value that reports whether the window has pointer capture.

IsInputEnabled IsInputEnabled IsInputEnabled IsInputEnabled

Gets or sets a value that indicates whether input is enabled for the UWP app.

PointerCursor PointerCursor PointerCursor PointerCursor

Gets or sets the cursor used by the UWP app.

PointerPosition PointerPosition PointerPosition PointerPosition

Gets the client coordinates of the pointer.

Methods

ReleasePointerCapture() ReleasePointerCapture() ReleasePointerCapture() ReleasePointerCapture()

Disables pointer capture for the UWP app.

SetPointerCapture() SetPointerCapture() SetPointerCapture() SetPointerCapture()

Enables pointer capture for the UWP app.

Events

InputEnabled InputEnabled InputEnabled InputEnabled

Occurs when input is enabled or disabled for the UWP app.

PointerCaptureLost PointerCaptureLost PointerCaptureLost PointerCaptureLost

Occurs when a pointer moves to another UWP app. This event is raised after PointerExited and is the final event received by the app for this pointer.

PointerEntered PointerEntered PointerEntered PointerEntered

Occurs when a pointer moves into the bounding box of the UWP app.

PointerExited PointerExited PointerExited PointerExited

Occurs when the pointer moves outside the bounding box of the UWP app.

PointerMoved PointerMoved PointerMoved PointerMoved

Occurs when a pointer moves within the bounding box of the UWP app.

PointerPressed PointerPressed PointerPressed PointerPressed

Occurs when a mouse button is clicked, or a touch or pen contact is detected, within the bounding rectangle of the UWP app.

PointerReleased PointerReleased PointerReleased PointerReleased

Occurs when a mouse button is released, or a touch or pen contact is lifted, within the bounding rectangle of the UWP app.

PointerWheelChanged PointerWheelChanged PointerWheelChanged PointerWheelChanged

Occurs when the wheel button is rotated.

See Also