Dela via


CoreIndependentInputSource Class

Definition

Surfaces core input APIs for interoperation scenarios.

public ref class CoreIndependentInputSource sealed : ICoreInputSourceBase, ICorePointerInputSource
public ref class CoreIndependentInputSource sealed : ICoreInputSourceBase, ICorePointerInputSource2
public ref class CoreIndependentInputSource sealed : ICoreInputSourceBase, ICorePointerInputSource2, ICorePointerRedirector
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
class CoreIndependentInputSource final : ICoreInputSourceBase, ICorePointerInputSource
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
class CoreIndependentInputSource final : ICoreInputSourceBase, ICorePointerInputSource2
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
class CoreIndependentInputSource final : ICoreInputSourceBase, ICorePointerInputSource2, ICorePointerRedirector
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
public sealed class CoreIndependentInputSource : ICoreInputSourceBase, ICorePointerInputSource
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
public sealed class CoreIndependentInputSource : ICoreInputSourceBase, ICorePointerInputSource2
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
public sealed class CoreIndependentInputSource : ICoreInputSourceBase, ICorePointerInputSource2, ICorePointerRedirector
Public NotInheritable Class CoreIndependentInputSource
Implements ICoreInputSourceBase, ICorePointerInputSource
Public NotInheritable Class CoreIndependentInputSource
Implements ICoreInputSourceBase, ICorePointerInputSource2
Public NotInheritable Class CoreIndependentInputSource
Implements ICoreInputSourceBase, ICorePointerInputSource2, ICorePointerRedirector
Inheritance
Object Platform::Object IInspectable CoreIndependentInputSource
Attributes
Implements

Windows requirements

Device family
Windows 10 (introduced in 10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced in v1.0)

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.

Version history

Windows version SDK version Value added
1803 17134 DispatcherQueue

Properties

Dispatcher

Gets the event dispatcher for the window.

DispatcherQueue

Gets the DispatcherQueue associated with this CoreIndependentInputSource.

HasCapture

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

IsInputEnabled

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

PointerCursor

Gets or sets the pointer cursor used by the app.

PointerPosition

Gets the client coordinates of the pointer.

Methods

ReleasePointerCapture()

Disables pointer capture for the UWP app.

SetPointerCapture()

Enables pointer capture for the UWP app.

Events

InputEnabled

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

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

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

PointerExited

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

PointerMoved

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

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

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

PointerRoutedAway

Occurs on the input object receiving pointer input when the pointer is redirected to another input object (possibly in a separate process).

PointerRoutedReleased

Occurs on all input objects ever associated with, but not currently receiving input from, a pointer that fires a CoreIndependentInputSource.PointerReleased event on an input object.

PointerRoutedTo

Occurs when captured pointer input previously being delivered to another object, transitions to being delivered to this object.

PointerWheelChanged

Occurs when the wheel button is rotated.

Applies to

See also