Guidelines for touch keyboard and handwriting panel (Windows Store apps)

1 out of 4 rated this helpful - Rate this topic

Describes best practices for interacting programmatically with the touch keyboard in Windows Store apps.

Developing for the touch keyboard

The Windows 8 touch keyboard enables text entry for form factors that don’t have a hardware keyboard or other peripheral keyboard devices. The touch keyboard is invoked when a user taps on an editable input field, and is dismissed when the input field loses focus. The touch keyboard is used for text entry only.

The following table presents the practices recommended for programming Windows Store apps that use the touch keyboard for text entry.

PracticeDescription

Use the touch keyboard for text input only, not for commands or keyboard shortcuts

The touch keyboard is present on touch-enabled systems when the user needs to input text. To dismiss the touch keyboard, either move focus to another control or set the input field to read-only.

Maintain keyboard presence throughout a user flow.

If you're creating custom UI, make sure your custom controls have the proper UI Automation ControlType to ensure keyboard persistence when focus moves from a text input field while in the context of text entry. For example, if you have a menu that's opened in the middle of a text-entry scenario, and you want the keyboard to persist, the menu must have the ControlType Menu.

Ensure that users always can see the input field that they're typing into.

The touch keyboard occludes half of the screen. Windows Store apps provide a default experience for managing UI when the touch keyboard appears, by ensuring that the input field with focus scrolls into view. Handle the Showing and Hiding events exposed by the InputPane object to customize your app’s reaction to the keyboard’s appearance.

Implement UI Automation properties for custom controls that have text input.

Standard controls for Windows Store apps have these properties, but custom controls require you to implement TextPattern. For the keyboard to persist contextually as focus changes to different controls, a custom control must have one of the following properties:

  • Button
  • Check box
  • Combo box
  • Radio button
  • Scroll bar
  • Tree item
  • Menu
  • Menu item

Don't use the touch keyboard as a commanding and controlling device.

The touch keyboard doesn't provide many of the accelerators or command keys found on a hardware keyboard, such as alt, the function keys, or the Windows Logo key. Don't make users navigate their application by using the keyboard.

Don't keep the keyboard displayed only to keep the touch keyboard on the screen.

When you don't expect text entry to occur, don't display the touch keyboard.

Don't manipulate UI Automation properties to control the touch keyboard.

Other accessibility tools rely on the accuracy of UI Automation properties.

 

Handling the Showing and Hiding events

The following code shows how to attach event handlers for the showing and hiding events in Windows Store apps using JavaScript.



<SCRIPT type=”text/javascript”>
    Windows.UI.Immersive.InputPane.getForCurrentView().addEventListener("showing",           onInputPaneShowing);
    Windows.UI.Immersive.InputPane.getForCurrentView().addEventListener("hiding", onInputPaneHiding);

// Handle the showing event.
function onInputPaneShowing(e)
{
    var occludedRect = e.occludedRect;

    // For this hypothetical application, the developer decided that 400 pixels is
    // the minimum height that will work for the current layout. When the
    // app gets the InputPaneShowing message, the pane is beginning to animate in.

    if (occludedRect.Top < 400)
    {
        // In this scenario, the developer decides to remove some elements (perhaps
        // a fixed navbar) and dim the screen to give focus to the text element.
        var elementsToRemove = document.getElementsByName("extraneousElements");

        // The app developer is not using default framework animation.
        _StartElementRemovalAnimations(elementsToRemove);
        _StartScreenDimAnimation();
    } 

    // This developer doesn't want the framework’s focused element visibility
    // code/animation to override the custom logic.
    e.ensuredFocusedElementInView = true;
}

// Handle the hiding event.
function onInputPaneHiding(e)
{
    // In this case, the Input Pane is dismissing. The developer can use 
    // this message to start animations.
    if (_ExtraElementsWereRemoved())
    {
        _StartElementAdditionAnimations();
    }

    // Don't use framework scroll- or visibility-related 
    // animations that might conflict with the app's logic.
    e.ensuredFocusedElementInView = true; 
}



The following code shows how to attach event handlers for the Showing and Hiding events in C#.



public class MyApplication
{
    public MyApplication()
    {
        // Grab the input pane for the main application window and attach
        // touch keyboard event handlers.
        Windows.Foundation.Application.InputPane.GetForCurrentView().Showing  
            += new EventHandler(_OnInputPaneShowing);
        Windows.Foundation.Application.InputPane.GetForCurrentView().Hiding 
            += new EventHandler(_OnInputPaneHiding);
    }

    private void _OnInputPaneShowing(object sender, IInputPaneVisibilityEventArgs eventArgs)
    {
        // If the size of this window is going to be too small, the app uses 
        // the Showing event to begin some element removal animations.
        if (eventArgs.OccludedRect.Top < 400)
        {
            _StartElementRemovalAnimations();

            // Don't use framework scroll- or visibility-related 
            // animations that might conflict with the app's logic.
            eventArgs.EnsuredFocusedElementInView = true; 
        }
    }

    private void _OnInputPaneHiding(object sender, IInputPaneVisibilityEventArgs eventArgs)
    {
        if (_ResetToDefaultElements())
        {
            eventArgs.EnsuredFocusedElementInView = true; 
        }
    }

    private void _StartElementRemovalAnimations()
    {
        // This function starts the process of removing elements 
        // and starting the animation.
    }

    private void _ResetToDefaultElements()
    {
        // This function resets the window's elements to their default state.
    }
}


Security Considerations

The following articles provide guidance for writing secure C++ code.

Related topics

Showing
Hiding
InputPane

 

 

Build date: 11/28/2012

Did you find this helpful?
(1500 characters remaining)
© 2013 Microsoft. All rights reserved.