次の方法で共有


スクリーン リーダーとハードウェア システム ボタン

ナレーターなどのスクリーン リーダーは、ハードウェア システム のボタン イベントを認識して処理し、その状態をユーザーに伝えることができる必要があります。 場合によっては、スクリーン リーダーは、これらのハードウェア ボタン イベントを排他的に処理し、他のハンドラーにバブルアップさせないようにする必要がある場合があります。

Windows 10 バージョン 2004 以降、UWP アプリケーションは、他のハードウェア ボタンと同じ方法で Fn ハードウェア システム ボタン イベントをリッスンして処理できます。 以前は、このシステム ボタンは、他のハードウェア ボタンがイベントと状態を報告する方法の修飾子としてのみ機能しました。

Fn ボタンのサポートは OEM 固有であり、(押し続けるキーの組み合わせに対して) オンまたはロックを切り替える機能や、対応するロック インジケーター ライト (視覚障碍のあるユーザーには役に立たない可能性があります) などの機能を含めることができます。

Fn ボタン イベントは、Windows.UI.Input 名前空間の新しい SystemButtonEventController クラスを介して公開されます。 SystemButtonEventController オブジェクトは、次のイベントをサポートしています。

Von Bedeutung

SystemButtonEventController は、優先度の高いハンドラーによって既に処理されている場合、これらのイベントを受信できません。

例示

次の例では、DispatcherQueue に基づいて SystemButtonEventController を作成し、このオブジェクトでサポートされている 4 つのイベントを処理する方法を示します。

Fn ボタンを押すと、サポートされている複数のイベントが発生するのが一般的です。 たとえば、Surface キーボードの Fn ボタンを押すと、SystemFunctionButtonPressed、SystemFunctionLockChanged、SystemFunctionLockIndicatorChanged が同時に起動します。

  1. この最初のスニペットでは、必要な名前空間を含め、SystemButtonEventController スレッドを管理するための DispatcherQueue オブジェクトや DispatcherQueueController オブジェクトなど、いくつかのグローバル オブジェクトを指定します。

    次に、SystemButtonEventController のイベント処理デリゲートを登録する際に返される イベントトークン を指定します。

    namespace winrt
    {
        using namespace Windows::System;
        using namespace Windows::UI::Input;
    }
    
    ...
    
    // Declare related members
    winrt::DispatcherQueueController _queueController;
    winrt::DispatcherQueue _queue;
    winrt::SystemButtonEventController _controller;
    winrt::event_token _fnKeyDownToken;
    winrt::event_token _fnKeyUpToken;
    winrt::event_token _fnLockToken;
    
  2. また、 SystemFunctionLockIndicatorChanged イベントのイベント トークンと共にブール値を指定して、アプリケーションが "学習モード" になっているかどうかを示します (ユーザーは関数を実行せずにキーボードを探索しようとしているだけです)。

    winrt::event_token _fnLockIndicatorToken;
    bool _isLearningMode = false;
    
  3. この 3 番目のスニペットには、 SystemButtonEventController オブジェクトでサポートされる各イベントの対応するイベント ハンドラー デリゲートが含まれています。

    各イベント ハンドラーは、発生したイベントを通知します。 さらに、FunctionLockIndicatorChanged ハンドラーは、アプリが "学習" モード (_isLearningMode = true) であるかどうかを制御します。これにより、イベントが他のハンドラーにバブルするのを防ぎ、ユーザーは実際にアクションを実行せずにキーボード機能を探索できます。

    void SetupSystemButtonEventController()
    {
        // Create dispatcher queue controller and dispatcher queue
        _queueController = winrt::DispatcherQueueController::CreateOnDedicatedThread();
        _queue = _queueController.DispatcherQueue();
    
        // Create controller based on new created dispatcher queue
        _controller = winrt::SystemButtonEventController::CreateForDispatcherQueue(_queue);
    
        // Add Event Handler for each different event
        _fnKeyDownToken = _controller->FunctionButtonPressed(
            [](const winrt::SystemButtonEventController& /*sender*/, const winrt:: FunctionButtonEventArgs& args)
            {
                // Mock function to read the sentence "Fn button is pressed"
                PronounceFunctionButtonPressedMock();
                // Set Handled as true means this event is consumed by this controller
                // no more targets will receive this event
                args.Handled(true);
            });
    
            _fnKeyUpToken = _controller->FunctionButtonReleased(
                [](const winrt::SystemButtonEventController& /*sender*/, const winrt:: FunctionButtonEventArgs& args)
                {
                    // Mock function to read the sentence "Fn button is up"
                    PronounceFunctionButtonReleasedMock();
                    // Set Handled as true means this event is consumed by this controller
                    // no more targets will receive this event
                    args.Handled(true);
                });
    
        _fnLockToken = _controller->FunctionLockChanged(
            [](const winrt::SystemButtonEventController& /*sender*/, const winrt:: FunctionLockChangedEventArgs& args)
            {
                // Mock function to read the sentence "Fn shift is locked/unlocked"
                PronounceFunctionLockMock(args.IsLocked());
                // Set Handled as true means this event is consumed by this controller
                // no more targets will receive this event
                args.Handled(true);
            });
    
        _fnLockIndicatorToken = _controller->FunctionLockIndicatorChanged(
            [](const winrt::SystemButtonEventController& /*sender*/, const winrt:: FunctionLockIndicatorChangedEventArgs& args)
            {
                // Mock function to read the sentence "Fn lock indicator is on/off"
                PronounceFunctionLockIndicatorMock(args.IsIndicatorOn());
                // In learning mode, the user is exploring the keyboard. They expect the program
                // to announce what the key they just pressed WOULD HAVE DONE, without actually
                // doing it. Therefore, handle the event when in learning mode so the key is ignored
                // by the system.
                args.Handled(_isLearningMode);
            });
    }
    

こちらも参照ください

SystemButtonEventController クラス