Bagikan melalui


PointerDevice Kelas

Definisi

Mendukung kemampuan untuk mengidentifikasi perangkat pointer yang terhubung dan menentukan kemampuannya.

public ref class PointerDevice sealed
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.None)]
class PointerDevice final
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.None)]
public sealed class PointerDevice
Public NotInheritable Class PointerDevice
Warisan
Object Platform::Object IInspectable PointerDevice
Atribut

Persyaratan Windows

Rangkaian perangkat
Windows 10 (diperkenalkan dalam 10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (diperkenalkan dalam v1.0)

Contoh

Kode berikut menunjukkan cara menggunakan PointerDevice.

/// <summary> 
/// Invoked when this page is about to be displayed in a Frame. 
/// </summary> 
/// <param name="e">Event data that describes how this page was reached.  The Parameter 
/// property is typically used to configure the page.</param> 
protected override void OnNavigatedTo(NavigationEventArgs e) 
{ 
    string Buffer; 

    Buffer = "List of all pointer devices: \n\n"; 

    var PointerDeviceList = Windows.Devices.Input.PointerDevice.GetPointerDevices(); 
    int displayIndex = 1; 

    foreach (Windows.Devices.Input.PointerDevice PointerDevice in PointerDeviceList) 
    { 
        Buffer += string.Format("Pointer device " + displayIndex + ":\n"); 
        Buffer += string.Format("This pointer device type is " + 
            PointerType(PointerDevice) + "\n"); 
        Buffer += string.Format("This pointer device is " + 
            (PointerDevice.IsIntegrated ? "not " : "") + "external\n"); 
        Buffer += string.Format("This pointer device has a maximum of " + 
            PointerDevice.MaxContacts + " contacts\n"); 
        Buffer += string.Format("The physical device rect is " + 
            PointerDevice.PhysicalDeviceRect.X.ToString() + ", " + 
            PointerDevice.PhysicalDeviceRect.Y.ToString() + ", " + 
            PointerDevice.PhysicalDeviceRect.Width.ToString() + ", " + 
            PointerDevice.PhysicalDeviceRect.Height.ToString() + "\n"); 
        Buffer += string.Format("The screen rect is " + 
            PointerDevice.ScreenRect.X.ToString() + ", " + 
            PointerDevice.ScreenRect.Y.ToString() + ", " + 
            PointerDevice.ScreenRect.Width.ToString() + ", " + 
            PointerDevice.ScreenRect.Height.ToString() + "\n\n"); 
    }  
    PointerOutputTextBlock.Text = Buffer; 
}
#include <sstream>
#include <winrt/Windows.Devices.Input.h>
#include <winrt/Windows.Foundation.Collections.h>
#include <winrt/Windows.UI.Xaml.Controls.h>
using namespace winrt;
using namespace Windows::Devices::Input;
using namespace Windows::UI::Xaml::Controls;

...

void PointerGetSettings_Click(Windows::Foundation::IInspectable const& sender, Windows::UI::Xaml::RoutedEventArgs const& args)
{
    auto b{ sender.try_as<Button>() };
    if (b)
    {
        Windows::Foundation::Collections::IVectorView<PointerDevice> pointerDeviceList{ PointerDevice::GetPointerDevices() };
        std::wostringstream buffer;

        for (uint32_t i = 0; i < pointerDeviceList.Size(); i++)
        {
            winrt::hstring displayIndex{ winrt::to_hstring(i + 1) };
            buffer << L"Pointer device " << displayIndex.c_str() << std::endl;
            buffer << L"This pointer device type is ";

            switch (pointerDeviceList.GetAt(i).PointerDeviceType())
            {
            case PointerDeviceType::Mouse:
                buffer << L"Mouse" << std::endl;
                break;
            case PointerDeviceType::Pen:
                buffer << L"Pen" << std::endl;
                break;
            case PointerDeviceType::Touch:
                buffer << L"Touch" << std::endl;
                break;
            default:
                buffer << L"unknown" << std::endl;
            }

            buffer << L"This pointer device is " << (pointerDeviceList.GetAt(i).IsIntegrated() ? L"not " : L"") << L"external" << std::endl;
            buffer << L"This pointer device has a maximum of " << pointerDeviceList.GetAt(i).MaxContacts() << L" contacts" << std::endl;
            buffer << L"The physical device rect is " <<
                pointerDeviceList.GetAt(i).PhysicalDeviceRect().X << L", " <<
                pointerDeviceList.GetAt(i).PhysicalDeviceRect().Y << L", " <<
                pointerDeviceList.GetAt(i).PhysicalDeviceRect().Width << L", " <<
                pointerDeviceList.GetAt(i).PhysicalDeviceRect().Height << std::endl;
            buffer << L"The screen rect is " <<
                pointerDeviceList.GetAt(i).ScreenRect().X << L", " <<
                pointerDeviceList.GetAt(i).ScreenRect().Y << L", " <<
                pointerDeviceList.GetAt(i).ScreenRect().Width << L", " <<
                pointerDeviceList.GetAt(i).ScreenRect().Height << std::endl << std::endl;
        }

        PointerOutputTextBlock().Text(buffer.str());
    }
}
void SDKSample::DeviceCaps::Pointer::PointerGetSettings_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e) 
{ 
    Button^ b = safe_cast<Button^>(sender); 
    if (b != nullptr) 
    { 
        Windows::Foundation::Collections::IVectorView<PointerDevice^>^ PointerDeviceList = PointerDevice::GetPointerDevices(); 
        Platform::String^ Buffer; 

        for (unsigned i = 0; i < PointerDeviceList->Size; i++) { 
            Platform::String^ displayIndex = (i + 1).ToString(); 
            Buffer += "Pointer device " + displayIndex + ":\n"; 
            Buffer += "This pointer device type is " + PointerType(PointerDeviceList->GetAt(i)) + "\n"; 
            Buffer += "This pointer device is " + (PointerDeviceList->GetAt(i)->IsIntegrated ? "not " : "") + "external\n"; 
            Buffer += "This pointer device has a maximum of " + PointerDeviceList->GetAt(i)->MaxContacts.ToString() + " contacts\n"; 
            Buffer += "The physical device rect is " + 
                PointerDeviceList->GetAt(i)->PhysicalDeviceRect.X.ToString() + ", " + 
                PointerDeviceList->GetAt(i)->PhysicalDeviceRect.Y.ToString() + ", " + 
                PointerDeviceList->GetAt(i)->PhysicalDeviceRect.Width.ToString() + ", " + 
                PointerDeviceList->GetAt(i)->PhysicalDeviceRect.Height.ToString() + "\n"; 
            Buffer += "The screen rect is " + 
                PointerDeviceList->GetAt(i)->ScreenRect.X.ToString() + ", " + 
                PointerDeviceList->GetAt(i)->ScreenRect.Y.ToString() + ", " + 
                PointerDeviceList->GetAt(i)->ScreenRect.Width.ToString() + ", " + 
                PointerDeviceList->GetAt(i)->ScreenRect.Height.ToString() + "\n\n"; 
        } 

        PointerOutputTextBlock->Text = Buffer; 
    } 
}

Keterangan

Nilai yang dikembalikan oleh properti yang dibahas di sini didasarkan pada jumlah total perangkat pointer yang terhubung: Properti Boolean mengembalikan true jika satu perangkat mendukung kemampuan tertentu dan properti numerik mengembalikan nilai maksimum yang diekspos oleh semua perangkat.

Sampel Kemampuan Perangkat menunjukkan cara mendeteksi keberadaan perangkat input dan mengambil kemampuan dan atribut setiap perangkat.

Catatan

Kelas ini tidak lincah, yang berarti Anda perlu mempertimbangkan model utas dan perilaku marshalingnya. Untuk informasi selengkapnya, lihat Threading dan Marshaling (C++/CX) dan Menggunakan objek Windows Runtime di lingkungan multithreaded (.NET).

Properti

IsIntegrated

Mendapatkan nilai yang menunjukkan apakah perangkat penunjuk adalah perangkat terintegrasi. Misalnya, tampilan video dengan digitizer sentuh terintegrasi dibandingkan dengan digitizer pena/stylus eksternal.

MaxContacts

Mendapatkan nilai yang menunjukkan jumlah maksimum kontak yang didukung oleh perangkat input.

MaxPointersWithZDistance

Mendapatkan jumlah maksimum kontak hover yang didukung oleh perangkat input.

PhysicalDeviceRect

Mendapatkan koordinat persegi panjang pembatas yang didukung oleh perangkat input.

PointerDeviceType

Mendapatkan jenis perangkat penunjuk.

ScreenRect

Mendapatkan koordinat layar yang dipetakan ke persegi panjang pembatas yang didukung oleh perangkat input.

SupportedUsages

Mendapatkan koleksi yang berisi penggunaan perangkat pointer yang didukung.

Metode

GetPointerDevice(UInt32)

Mendapatkan informasi tentang perangkat penunjuk yang terkait dengan ID penunjuk input yang ditentukan.

GetPointerDevices()

Mendapatkan informasi tentang perangkat pointer yang terpasang pada sistem.

Berlaku untuk

Lihat juga