次の方法で共有


入力デバイスを識別する

Windows アプリ デバイスに接続されている入力デバイスを識別し、その機能と属性を識別します。

重要な API: Windows.Devices.InputWindows.UI.InputWindows.UI.Xaml.Input

マウスのプロパティを取得する

Windows.Devices.Input 名前空間には、1 つ以上の接続されたマウスによって公開されるプロパティを取得するために使用される MouseCapabilities クラスが含まれています。 新しい MouseCapabilities オブジェクトを作成し、関心のあるプロパティを取得するだけです。

ここで説明するプロパティによって返される値は、検出されたすべてのマウスに基づいています。ブール型プロパティは、少なくとも 1 つのマウスが特定の機能をサポートしている場合は 0 以外を返し、数値プロパティは任意の 1 つのマウスによって公開される最大値を返します。

 

次のコードでは、一連の TextBlock 要素を使用して、個々のマウスのプロパティと値を表示します。

private void GetMouseProperties()
{
    MouseCapabilities mouseCapabilities = new Windows.Devices.Input.MouseCapabilities();
    MousePresent.Text = mouseCapabilities.MousePresent != 0 ? "Yes" : "No";
    VertWheel.Text = mouseCapabilities.VerticalWheelPresent != 0 ? "Yes" : "No";
    HorzWheel.Text = mouseCapabilities.HorizontalWheelPresent != 0 ? "Yes" : "No";
    SwappedButtons.Text = mouseCapabilities.SwapButtons != 0 ? "Yes" : "No";
    NumButtons.Text = mouseCapabilities.NumberOfButtons.ToString();
}

キーボードのプロパティを取得する

Windows.Devices.Input 名前空間には、キーボードが接続されているかどうかを取得するために使用される KeyboardCapabilities クラスが含まれています。 新しい KeyboardCapabilities オブジェクトを作成し、KeyboardPresent プロパティを取得するだけです。

次のコードでは、TextBlock 要素を使用して、キーボードのプロパティと値を表示します。

private void GetKeyboardProperties()
{
    KeyboardCapabilities keyboardCapabilities = new Windows.Devices.Input.KeyboardCapabilities();
    KeyboardPresent.Text = keyboardCapabilities.KeyboardPresent != 0 ? "Yes" : "No";
}

タッチ プロパティを取得する

Windows.Devices.Input 名前空間には、タッチ デジタイザーが接続されているかどうかを取得するために使用される TouchCapabilities クラスが含まれています。 新しい TouchCapabilities オブジェクトを作成し、関心のあるプロパティを取得するだけです。

ここで説明するプロパティによって返される値は、検出されたすべてのタッチ デジタイザーに基づいています。ブール型プロパティは、少なくとも 1 つのデジタイザーが特定の機能をサポートしている場合は 0 以外を返し、数値プロパティは 1 つのデジタイザーによって公開される最大値を返します。

 

次のコードでは、一連の TextBlock 要素を使用して、タッチのプロパティと値を表示します。

private void GetTouchProperties()
{
    TouchCapabilities touchCapabilities = new Windows.Devices.Input.TouchCapabilities();
    TouchPresent.Text = touchCapabilities.TouchPresent != 0 ? "Yes" : "No";
    Contacts.Text = touchCapabilities.Contacts.ToString();
}

ポインターのプロパティを取得する

Windows.Devices.Input 名前空間には、検出されたデバイスがポインター入力 (タッチ、タッチパッド、マウス、ペン) をサポートするかどうかを取得するために使用する PointerDevice クラスが含まれています。 新しい PointerDevice オブジェクトを作成し、関心のあるプロパティを取得するだけです。

ここで説明するプロパティによって返される値は、検出されたすべてのポインター デバイスに基づいています。ブール型プロパティは、少なくとも 1 つのデバイスが特定の機能をサポートしている場合は 0 以外を返し、数値プロパティは、任意の 1 つのポインター デバイスによって公開される最大値を返します。

次のコードでは、テーブルを使用して、各ポインター デバイスのプロパティと値を表示します。

private void GetPointerDevices()
{
    IReadOnlyList<PointerDevice> pointerDevices = Windows.Devices.Input.PointerDevice.GetPointerDevices();
    int gridRow = 0;
    int gridColumn = 0;

    for (int i = 0; i < pointerDevices.Count; i++)
    {
        // Pointer device type.
        TextBlock textBlock1 = new TextBlock();
        Grid_PointerProps.Children.Add(textBlock1);
        textBlock1.Text = (i + 1).ToString() + " Pointer Device Type:";
        Grid.SetRow(textBlock1, gridRow);
        Grid.SetColumn(textBlock1, gridColumn);

        TextBlock textBlock2 = new TextBlock();
        textBlock2.Text = pointerDevices[i].PointerDeviceType.ToString();
        Grid_PointerProps.Children.Add(textBlock2);
        Grid.SetRow(textBlock2, gridRow++);
        Grid.SetColumn(textBlock2, gridColumn + 1);

        // Is external?
        TextBlock textBlock3 = new TextBlock();
        Grid_PointerProps.Children.Add(textBlock3);
        textBlock3.Text = (i + 1).ToString() + " Is External?";
        Grid.SetRow(textBlock3, gridRow);
        Grid.SetColumn(textBlock3, gridColumn);

        TextBlock textBlock4 = new TextBlock();
        Grid_PointerProps.Children.Add(textBlock4);
        textBlock4.Text = pointerDevices[i].IsIntegrated.ToString();
        Grid.SetRow(textBlock4, gridRow++);
        Grid.SetColumn(textBlock4, gridColumn + 1);

        // Maximum contacts.
        TextBlock textBlock5 = new TextBlock();
        Grid_PointerProps.Children.Add(textBlock5);
        textBlock5.Text = (i + 1).ToString() + " Max Contacts:";
        Grid.SetRow(textBlock5, gridRow);
        Grid.SetColumn(textBlock5, gridColumn);

        TextBlock textBlock6 = new TextBlock();
        Grid_PointerProps.Children.Add(textBlock6);
        textBlock6.Text = pointerDevices[i].MaxContacts.ToString();
        Grid.SetRow(textBlock6, gridRow++);
        Grid.SetColumn(textBlock6, gridColumn + 1);

        // Physical device rectangle.
        TextBlock textBlock7 = new TextBlock();
        Grid_PointerProps.Children.Add(textBlock7);
        textBlock7.Text = (i + 1).ToString() + " Physical Device Rect:";
        Grid.SetRow(textBlock7, gridRow);
        Grid.SetColumn(textBlock7, gridColumn);

        TextBlock textBlock8 = new TextBlock();
        Grid_PointerProps.Children.Add(textBlock8);
        textBlock8.Text = pointerDevices[i].PhysicalDeviceRect.X.ToString() + "," +
            pointerDevices[i].PhysicalDeviceRect.Y.ToString() + "," +
            pointerDevices[i].PhysicalDeviceRect.Width.ToString() + "," +
            pointerDevices[i].PhysicalDeviceRect.Height.ToString();
        Grid.SetRow(textBlock8, gridRow++);
        Grid.SetColumn(textBlock8, gridColumn + 1);

        // Screen rectangle.
        TextBlock textBlock9 = new TextBlock();
        Grid_PointerProps.Children.Add(textBlock9);
        textBlock9.Text = (i + 1).ToString() + " Screen Rect:";
        Grid.SetRow(textBlock9, gridRow);
        Grid.SetColumn(textBlock9, gridColumn);

        TextBlock textBlock10 = new TextBlock();
        Grid_PointerProps.Children.Add(textBlock10);
        textBlock10.Text = pointerDevices[i].ScreenRect.X.ToString() + "," +
            pointerDevices[i].ScreenRect.Y.ToString() + "," +
            pointerDevices[i].ScreenRect.Width.ToString() + "," +
            pointerDevices[i].ScreenRect.Height.ToString();
        Grid.SetRow(textBlock10, gridRow++);
        Grid.SetColumn(textBlock10, gridColumn + 1);

        gridColumn += 2;
        gridRow = 0;
    }

サンプル

アーカイブサンプル