locked
Some soft keyboard questions RRS feed

  • Question

  • 1)How do you hide the soft keyboard? I have logic to move the input focus to successive TextBox controls when the user presses enter, and I want to dismiss the soft keyboard when the user presses enter while the final TextBox is focused.

     

    2)How do you ensure that the soft keyboard doesn't obscure input controls? I have everything in a ScrollViewer but when the soft keyboard appears the system doesn't adjust to make those controls visible. 

     

    3)How do you get the screen dimensions of the on screen keyboard?

    Sunday, January 22, 2012 10:26 PM

Answers

  • Hi Derek,

    The right thing to do here is to set the Focus to a focusable but non-text control (such as a Button or your UserControl). This should dismiss the keyboard if it was shown automatically (but not if the user explicitly showed it). As I mentioned though, there are several known issues around keyboard hiding and showing in the Developer Preview.

    EnsuredFocusedElementInView (I typoed the name before, but the correct one can be found from the docs that I linked for InputPane) is a property on the InputVisibilityEventArgs passed to the InputPane.Hiding and Showing events. An easy way to figure this sort of relationship is to use Visual Studio's Object Browser. It'll also help find typos ;)

    --Rob

     

     

    • Marked as answer by Jie Bao Monday, February 6, 2012 8:57 AM
    Tuesday, January 24, 2012 2:19 AM
    Moderator

All replies

  • Applications don't have direct control over the soft keyboard. It will show when a text control has focus and hide when one doesn't, unless the user has explicitly shown or hidden the keyboard. If the focus moves off of the final TextBox when the user presses enter then the keyboard should hide. If the focus is still on the TextBox then the keyboard stays in case the user wants to enter more text. See Input Hosting Manager and the Touch Keyboard for more details.

    The keyboard shouldn't obscure text input controls, but there are some known issues with this in the Developer Preview. If you have a specific scenario which reproduces this can you please file a bug with the Feedback tool with exact repro steps so we can make sure your situation is covered.

    When the keyboard is shown or hidden the Windows.UI.ViewManagement.InputPane.Showing and Hiding events will fire. These pass the OccludedRect, which you can also get from an InputPane object. The app can set EnsureFocusedElementInView to true if it wants to handle getting out of the way of the keyboard itself or false if it wants this to happen automatically.

    There is a Keyboard Events sample which demonstrates how this can be used. It is in HTML/JavaScript, but uses the same Windows.UI classes that are available to Xaml/C# apps. 

    ---Rob

    Monday, January 23, 2012 6:31 AM
    Moderator
  • I took a look at the "touch keyboard" link.

    Not having an explicit way to dismiss the keyboard seems like an unnecessary limitation. At least on Windows Phone 7 I'm able to perform pivot.Focus() (where "pivot" is a Pivot control in the UI) to get rid of the keyboard. On Windows 8/Metro, calling Focus() within the page (UserControl) doesn't do anything, and since there's no way to "focus" a non-focusable control (like a TextBlock), there's no good way to dismiss the keyboard. My hack for the time being is to create a read-only TextBox that's styled like the background (so you can't see it) and calling Focus() on that to get rid of the keyboard. 

    I did a search for "EnsureFocusedElementInView" and couldn't find any information on that.

    Monday, January 23, 2012 9:34 PM
  • Hi Derek,

    The right thing to do here is to set the Focus to a focusable but non-text control (such as a Button or your UserControl). This should dismiss the keyboard if it was shown automatically (but not if the user explicitly showed it). As I mentioned though, there are several known issues around keyboard hiding and showing in the Developer Preview.

    EnsuredFocusedElementInView (I typoed the name before, but the correct one can be found from the docs that I linked for InputPane) is a property on the InputVisibilityEventArgs passed to the InputPane.Hiding and Showing events. An easy way to figure this sort of relationship is to use Visual Studio's Object Browser. It'll also help find typos ;)

    --Rob

     

     

    • Marked as answer by Jie Bao Monday, February 6, 2012 8:57 AM
    Tuesday, January 24, 2012 2:19 AM
    Moderator
  • Yes,

    Focusing on a non-keyboard item like a button will close the keyboard. Great, that works. the problem is my QA team always wants to 'light dismiss' the keyboard.

    They insist they should be able to tap anywhere to close the keyboard, and refuse to use the close keyboard UI button provided on the keyboard.

    I always have to create some full screen button that sits behind valid text fields to try and capture the user's close tap. When I detect this 'close tap', I then set focus on a 'focus taking button' which in-turn closes the keyboard. Very hacky but it works.
    Unfortunately the next UI they want is full of left/right/up/down swipes I am worried this hack will breakdown

    What I really want is to make the keyboard 'light dismiss' -- my QA files it as a bug on every app. Can this be done?

    Friday, May 9, 2014 7:09 PM
  • You can enable keyboard focus on your background panel so the user can tap on it to escape the text control. There isn't a direct way to programmatically control the keyboard or to set it to light dismiss.

    See the touch keyboard documentation for more information on the invocation and dismissal logic.

    --Rob

    Saturday, May 10, 2014 2:47 PM
    Moderator
  • Rob,

    How do we enable focus on a background panel? The keyboard link does not talk about that.

    Are we to use a 3rd party FocusManager? Automation properties?

    I have not been able to find an example.

    any advice would help. Also do we have anyway to do this in WinJS ?

    -alekjz

    Wednesday, July 16, 2014 12:22 AM
  • Please post new questions in new threads rather than bumping old threads. For WinJS see the HTML The touch keyboard documentation. If you need more help with that please post in the HTML/JavaScript forum.

    You can set the Page's IsTabStop propertyto allow it to accept focus.

    <Page
        x:Class="App181.MainPage"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="using:App181"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        mc:Ignorable="d"
        IsTabStop="True"
        >
    
    

    --Rob

    Wednesday, July 16, 2014 11:42 PM
    Moderator