Leitores de tela e botões de sistema do hardware
Leitores de tela, como o Narrador, devem ser capazes de reconhecer e manipular eventos de botão do sistema de hardware e comunicar seu estado aos usuários. Em alguns casos, o leitor de tela pode precisar lidar com esses eventos de botão de hardware exclusivamente e não permitir que eles se esgoe para outros manipuladores.
A partir Windows 10 versão 2004, os aplicativos UWP podem escutar e manipular os eventos de botão do sistema de hardware Fn da mesma maneira que outros botões de hardware. Anteriormente, esse botão do sistema agiva apenas como um modificador de como outros botões de hardware relatavam seus eventos e estado.
Observação
O suporte ao botão Fn é específico do OEM e pode incluir recursos como a capacidade de alternar/bloquear (versus uma combinação de teclas pressionadas e pressionadas), juntamente com uma luz indicadora de bloqueio correspondente (que pode não ser útil para usuários com deficiência visual ou com deficiência visual).
Os eventos de botão Fn são expostos por meio de uma nova Classe SystemButtonEventController no Windows. UI. Namespace de entrada. O objeto SystemButtonEventController dá suporte aos seguintes eventos:
- SystemFunctionButtonPressed
- SystemFunctionButtonReleased
- SystemFunctionLockChanged
- SystemFunctionLockIndicatorChanged
Importante
O SystemButtonEventController não poderá receber esses eventos se eles já foram manipulados por um manipulador de prioridade mais alta.
Exemplos
Nos exemplos a seguir, mostramos como criar um SystemButtonEventController com base em um DispatcherQueue e manipular os quatro eventos com suporte por esse objeto.
É comum que mais de um dos eventos com suporte seja a incêndio quando o botão Fn é pressionado. Por exemplo, pressionar o botão Fn em um teclado do Surface dispara SystemFunctionButtonPressed, SystemFunctionLockChanged e SystemFunctionLockIndicatorChanged ao mesmo tempo.
Neste primeiro snippet, simplesmente incluímos os namespaces necessários e especificamos alguns objetos globais, incluindo os objetos DispatcherQueue e DispatcherQueueController para gerenciar o thread SystemButtonEventController .
Em seguida, especificamos os tokens de evento retornados ao registrar os delegados de manipulação de eventos 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;
Também especificamos um token de evento para o evento SystemFunctionLockIndicatorChanged juntamente com um bool para indicar se o aplicativo está no "modo Learning" (em que o usuário está simplesmente tentando explorar o teclado sem executar nenhuma função).
winrt::event_token _fnLockIndicatorToken; bool _isLearningMode = false;
Este terceiro snippet inclui os delegados do manipulador de eventos correspondentes para cada evento com suporte pelo objeto SystemButtonEventController .
Cada manipulador de eventos anuncia o evento que ocorreu. Além disso, o manipulador FunctionLockIndicatorChanged também controla se o aplicativo está no modo "Learning" (
_isLearningMode
= true), o que impede que o evento se espante para outros manipuladores e permite que o usuário explore os recursos do teclado sem realmente executar a ação.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); }); }