Programming4us
         
 
 
Windows Phone

Handling Input on Windows Phone 7 : The Keyboard

8/11/2011 5:18:09 PM
The last thing a mobile user wants to do is type on a mobile keyboard, but it is inevitable for many applications to require some form of text input. In this section I discuss keyboard capabilities and API enhancements to ease typing on the keyboard on Windows Phone 7 devices.

1. Physical Keyboard

Windows Phone 7 devices may also have a hardware slide-out keyboard, but your application will not pass certification in App Hub if it is dependent upon the hardware keyboard. Otherwise, from a software development perspective, programming for hardware keyboard input "just works." Of the six devices available at Windows Phone 7 launch, only one had a full slide-out keyboard, and another had a vertical QWERTY keyboard. The other four devices were pure touch devices without a physical keyboard.

2. Soft Input Panel (SIP) Keyboard

All Windows Phone 7 devices have a SIP keyboard used for entering text. Typing on the SIP keyboard built into Windows Phone 7 is a pretty comfortable means of entering text; however, it is still a small keyboard, so anything that a developer can do to ease typing can really help improve the overall user experience.

3. Programming with the Keyboard

Typing text on a mobile phone should be minimized as much as possible, but if text input is required, a developer should take advantage of capabilities to make typing as simple as possible. In the next section I cover InputScope, which is a must-have feature to take advantage of when typing is required in your Windows Phone 7 applications.

When testing keyboard input, you will be tempted to type on your PC keyboard; however, it does not work. You must use the mouse with the SIP keyboard in the Emulator for input.

Click the Pause/Break button on your PC keyboard to enable typing in the emulator with your PC keyboard instead of having to use the mouse to "touch" the SIP.


3.1. InputScope

The InputScope property is available on the TextBox control, which is the primary control for text input. InputScope lets the developer customize the keyboard for the expected type of input. For example, the default behavior is that when you click into a TextBox, the SIP keyboard pops up, as shown in Figure 1.

Figure 1. Default SIP keyboard

The second TextBox has an InputScope of Text, which enables word selection just above the keyboard, as shown in Figure 2.

Figure 2. InputScope of Text SIP keyboard with word suggestion

With just one simple attribute, text input becomes much easier for the enduser. Figure 3 shows three additional text input options, which I explain just after the figure.

Figure 3. Search, Password, and TelephoneNumber InputScopecustomizations

Configuring an InputScope of Search turns the Enter key into a GO key with the idea that the user enters a search keyword and then clicks Enter to kick off a search. Password is not actually an InputScope. It is a custom TextBox class named PasswordBox that automatically hides data entry as the user types. An InputScope of TelephoneNumber brings up a phone keypad. As you can see, all of these could come in handy as you develop your application UI and optimize input for the end user. Table 1 lists the available InputScope options and their descriptions, reprinted here for your convenience from the Windows Phone 7 documentation.

Table 1. Available InputScope Options
Input ScopeDescription
AddressCityThe text input pattern for a city address.
AddressCountryNameThe text input pattern for the name of a country/region.
AddressCountryShortNameThe text input pattern for the abbreviated name of a country/region.
dAdressStateOrProvinceThe text input pattern for a state or province.
AddressStreetThe text input pattern for a street address.
AlphanumericFullWidthThe text input pattern for alphanumeric full-width characters (East-Asian languages only).
AlphanumericHalfWidthThe text input pattern for alphanumeric half-width characters(East-Asian languages only).
ChatThe SIP layout for text messaging, which recognizes pre-defined abbreviations. Supported only in Silverlight for Windows Phone.
CurrencyAmountThe text input pattern for amount of currency.
CurrencyAmountAndSymbolThe text input pattern for amount and symbol of currency.
CurrencyChineseThe text input pattern for Chinese currency.
DateThe text input pattern for a calendar date.
DateDayThe text input pattern for the numeric day in a calendar date.
DateDayNameThe text input pattern for the name of the day in a calendar date.
DateMonthThe text input pattern for the numeric month in a calendar date.
DateMonthNameThe text input pattern for the name of the month in a calendar date.
DateYearThe text input pattern for the year in a calendar date.
DefaultThe default handling of input commands.
DigitsThe text input pattern for digits.
EmailNameOrAddressThe SIP layout for an e-mail name or address. Supported only in Silverlight for Windows Phone.
EmailSmtpAddressThe text input pattern for a Simple Mail Transfer Protocol (SMTP) e-mail address.
EmailUserNameThe text input pattern for an e-mail user name.
FileNameThe text input pattern for a file name.
FullFilePathThe text input pattern for the full path of a file.
HanjaThe text input pattern for Hanja characters (Korean characters).
HiraganaThe text input pattern for the Hiragana writing system(a Japanese syllabary).
KatakanaFullWidthThe text input pattern for full-width Katakana characters (a Japanese syllabary).
KatakanaHalfWidthThe text input pattern for half-width Katakana characters (a Japanese syllabary).
LogOnNameThe text input pattern for a log on name.
MapsThe SIP layout for entering a map location. Supported only in Silverlight for Windows Phone.
NameOrPhoneNumberThe SIP layout for SMS To field. Supported only in Silverlight for Windows Phone.
NumberThe text input pattern for a number.
NumberFullWidthThe text input pattern for a full-width number.
OneCharThe text input pattern for one character.
PasswordThe text input pattern for a password.
PersonalFullNameThe text input pattern for a person's full name.
PersonalGivenNameThe text input pattern for a person's given name.
PersonalMiddleNameThe text input pattern for a person's middle name.
PersonalNamePrefixThe text input pattern for the prefix of a person's name.
PersonalNameSuffixThe text input pattern for the suffix of a person's name.
PersonalSurnameThe text input pattern for a person's surname.
PhraseListThe text input pattern for a phrase list.
PostalAddressThe text input pattern for a postal address.
PostalCodeThe text input pattern for a postal code.
RegularExpressionThe text input pattern for a regular expression.
SearchThe SIP layout for a search query. Supported only in Silverlight for Windows Phone.
SrgsThe text input pattern for the Speech Recognition Grammar Specification (SRGS).
TelephoneAreaCodeThe text input pattern for a telephone area code.
TelephoneCountryCodeThe text input pattern for a telephone country/region code.
TelephoneLocalNumberThe text input pattern for a telephone local number.
TelephoneNumberThe text input pattern for a telephone number.
TextThe software input panel (SIP) layout for standard text input. Supported only in Silverlight for Windows Phone.
TimeThe text input pattern for the time.
TimeHourThe text input pattern for the hour of the time.
TimeMinorSecThe text input pattern for the minutes or seconds of time.
UrlThe text input pattern for a Uniform Resource Locator (URL).
XmlThe text input pattern for XML.

Let's now shift gears and explore the available keyboard events.

3.2. Keyboard Events

There are two keyboard events available on the TextBox, as well as pretty much any other object that inherits from UIElement: the KeyDown and KeyUp events. Both events have a KeyEventArgs class in its parameters that provides access to the Key and PlatformKeyCode values native to the platform. It also provides access to the OriginalSource property that represents the control that raised the Keyboard event, as well as a Handled member to indicate that the key has been processed.

This completes our discussion of keyboard events. In general, typing should be minimized in a mobile application for the reasons listed previously, i.e., small screen, small keyboard, and so on. Mobile devices are optimized for touch input, especially modern devices with highly responsive capacitive touch screens that do not require a stylus. Let's now focus on touch input.

Other -----------------
- User Interface : Customizing the Soft Input Panel Keyboard to Accept Only Numbers
- User Interface : Detecting Changes in the Theme Template
- Developing for Windows Phone and Xbox Live : Multiplayer Games (part 6) - Searching for an Available Network Session
- Developing for Windows Phone and Xbox Live : Multiplayer Games (part 5) - Searching for an Available Network Session
- Developing for Windows Phone and Xbox Live : Multiplayer Games (part 4) - Building a Game Lobby
- Developing for Windows Phone and Xbox Live : Multiplayer Games (part 3) - Creating a Network Session
- Developing for Windows Phone and Xbox Live : Multiplayer Games (part 2) - Main Menu and State Management
- Developing for Windows Phone and Xbox Live : Multiplayer Games (part 1) - Getting Ready for Networking Development
- User Interface : Using the ApplicationBar Control
- User Interface : Creating an Animated Splash Screen
- Windows Phone 7 Game Development : The World of 3D Graphics - Vertex and Index Buffers
- Windows Phone 7 Game Development : The World of 3D Graphics - Hidden Surface Culling
- Windows Phone 7 Game Development : The World of 3D Graphics - The Depth Buffer
- Windows Phone 7 Game Development : The World of 3D Graphics - Rendering 3D Objects
- Windows Phone 7 Game Development : The World of 3D Graphics - Perspective Projection
- Developing for Windows Phone and Xbox Live : Let the 3D Rendering Start
- Developing for Windows Phone and Xbox Live : Reach and HiDef Graphics Profiles
- Developing for Windows Phone and Xbox Live : Graphics Pipeline
- Developing for Windows Phone and Xbox Live : Graphics Pipeline
- Programming Windows Phone 7 : Elements and Properties - More on Images
 
 
Most View
- SQL Server 2008 Scheduling and Notification : Scripting Jobs and Alerts, Multiserver Job Management & Event Forwarding
- The Art of SEO : Content Optimization (part 2)
- Developing Applications for Windows Phone 7 : Data Binding (part 1)
- Developing for Windows Phone and Xbox Live : Sprites and 2D Graphics - Spritebatch (part 2)
- SharePoint 2007 : Use Alerts - Manage My Alerts in a Site
- Windows 7 : Creating a Windows Network - Installing Network Wiring
- Microsoft Dynamics AX 2009 : The Application Integration Framework (part 5) - Working with Document Services - Publishing Dynamics AX Services, Configuring Dynamics AX Services
- Exchange Server 2007: Monitor Your Exchange Environment (part 1)
- CSS for Mobile Browsers : Common Patterns (part 1) - Absolute and floating positions
- Destination: SQL Server 2008 or SQL Server 2008 R2 (part 1) - Side-by-Side Migration
Top 10
- Implementing Edge Services for an Exchange Server 2007 Environment : Utilizing the Basic Sender and Recipient Connection Filters (part 3) - Configuring Recipient Filtering
- Implementing Edge Services for an Exchange Server 2007 Environment : Utilizing the Basic Sender and Recipient Connection Filters (part 2)
- Implementing Edge Services for an Exchange Server 2007 Environment : Utilizing the Basic Sender and Recipient Connection Filters (part 1)
- Implementing Edge Services for an Exchange Server 2007 Environment : Installing and Configuring the Edge Transport Server Components
- What's New in SharePoint 2013 (part 7) - BCS
- What's New in SharePoint 2013 (part 6) - SEARCH
- What's New in SharePoint 2013 (part 6) - WEB CONTENT MANAGEMENT
- What's New in SharePoint 2013 (part 5) - ENTERPRISE CONTENT MANAGEMENT
- What's New in SharePoint 2013 (part 4) - WORKFLOWS
- What's New in SharePoint 2013 (part 3) - REMOTE EVENTS