CoreIndependentInputSource Kelas
Definisi
Penting
Beberapa informasi terkait produk prarilis yang dapat diubah secara signifikan sebelum dirilis. Microsoft tidak memberikan jaminan, tersirat maupun tersurat, sehubungan dengan informasi yang diberikan di sini.
Menampilkan API input inti untuk skenario interoperabilitas.
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
- Warisan
- Atribut
- Penerapan
Persyaratan Windows
Rangkaian perangkat |
Windows 10 (diperkenalkan dalam 10.0.10240.0)
|
API contract |
Windows.Foundation.UniversalApiContract (diperkenalkan dalam v1.0)
|
Contoh
Menginisialisasi input independen.
// 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);
Untuk contoh kode selengkapnya tentang cara menggunakan CreateCoreIndependentInputSource dan CoreIndependentInputSource, lihat DrawingPanel
definisi kelas yang merupakan bagian dari sampel interop XAML SwapChainPanel DirectX.
Keterangan
Buat instans kelas ini dengan memanggil SwapChainBackgroundPanel.CreateCoreIndependentInputSource atau SwapChainPanel.CreateCoreIndependentInputSource.
Kelas CoreIndependentInputSource memungkinkan aplikasi untuk menangani input dan penyajian independen dari utas UI XAML, karena Anda sengaja menyediakan logika pemrosesan input pada utas latar belakang. Anda harus memanggil CreateCoreIndependentInputSource dari utas non-UI, jika tidak, panggilan metode CreateCoreIndependentInputSource akan gagal.
Riwayat versi
Versi Windows | Versi SDK | Nilai ditambahkan |
---|---|---|
1803 | 17134 | DispatcherQueue |
Properti
Dispatcher |
Mendapatkan dispatcher peristiwa untuk jendela. |
DispatcherQueue |
Mendapatkan DispatcherQueue yang terkait dengan CoreIndependentInputSource ini. |
HasCapture |
Mendapatkan nilai yang melaporkan apakah jendela memiliki pengambilan penunjuk. |
IsInputEnabled |
Mendapatkan atau menetapkan nilai yang menunjukkan apakah input diaktifkan untuk aplikasi UWP. |
PointerCursor |
Mendapatkan atau mengatur kursor penunjuk yang digunakan oleh aplikasi. |
PointerPosition |
Mendapatkan koordinat klien dari penunjuk. |
Metode
ReleasePointerCapture() |
Menonaktifkan pengambilan pointer untuk aplikasi UWP. |
SetPointerCapture() |
Mengaktifkan penangkapan pointer untuk aplikasi UWP. |
Acara
InputEnabled |
Terjadi saat input diaktifkan atau dinonaktifkan untuk aplikasi UWP. |
PointerCaptureLost |
Terjadi saat pointer berpindah ke aplikasi UWP lain. Kejadian ini dimunculkan setelah PointerExited dan merupakan peristiwa akhir yang diterima oleh aplikasi untuk pointer ini. |
PointerEntered |
Terjadi ketika pointer berpindah ke kotak pembatas aplikasi UWP. |
PointerExited |
Terjadi ketika penunjuk bergerak di luar kotak pembatas aplikasi UWP. |
PointerMoved |
Terjadi saat penunjuk bergerak dalam kotak pembatas aplikasi UWP. |
PointerPressed |
Terjadi ketika tombol mouse diklik, atau kontak sentuhan atau pena terdeteksi, dalam persegi panjang pembatas aplikasi UWP. |
PointerReleased |
Terjadi saat tombol mouse dilepaskan, atau kontak sentuhan atau pena diangkat, dalam persegi panjang pembatas aplikasi UWP. |
PointerRoutedAway |
Terjadi pada objek input yang menerima input pointer ketika pointer dialihkan ke objek input lain (mungkin dalam proses terpisah). |
PointerRoutedReleased |
Terjadi pada semua objek input yang pernah terkait dengan, tetapi saat ini tidak menerima input dari, pointer yang mengaktifkan peristiwa CoreIndependentInputSource.PointerReleased pada objek input. |
PointerRoutedTo |
Terjadi ketika input penunjuk yang ditangkap sebelumnya dikirimkan ke objek lain, transisi untuk dikirimkan ke objek ini. |
PointerWheelChanged |
Terjadi saat tombol roda diputar. |