download

Customizable On Screen Keyboard (OSK) for WPF (it works for WebBrowser control)


Summary

Recently my colleagues and I faced a very particular problem in WPF. We were creating a very stylish application for a kiosk, and the keyboard should look different from the default OSK in WPF. At the beginning we import our old OSK which concatenates characters to a string, but this approach won’t work on the WebBrowser control since this control does not exposes internal components such as textbox. The following post is about my experience creating a solution for this particular problem.

The Problem

  • Customizable style for the on screen keyboard
  • The OSK must be able to interact with the WebControl control.

The solution

The default OSK

At first the most logical solution is to use the default. The problem with the default OSK is that it’s not possible to customize. Moreover the default OSK is not embedded into the WPF, it works on top of any other windows application.

Default Windows On Screen keyboard

Default Windows On Screen keyboard (OSK)

Appending strings

The our team decided to import our old OSK from a previous project. This first version of the OSK was a custom control. This custom control has a lot buttons and one string. Each time a button is pressed, a new character  is append to the string, thus the user of the control only have to check the current string in order to know which characters has been typed. The problem with this other approach is that keys like “arrows”, “control” or “alt” don’t have a way to represented into a string. At this time we’ve created out QueryKeyboard Contol which defines a bunch of buttons and appends characters to a string.

Customizing  a WPF OSK

Later on, we realize that our application will have to interact with the WebBrowser. Thus I decide we can use the same approach that the Wosk: Flexible On Screen Keyboard using WPF (http://wosk.codeplex.com/SourceControl/list/changesets) was using. Basically, WOSK was inserting keyboard  codes into the keyboard buffer, so the the operative system will report the input the the current focused window and control.

Thus, the approach was to separate the logic of the virtual keyboard from the keyboard control. So, the virtual keyboard could work as independent a service or be part of a more complex control such as the QueryKeyboardControl.

I’ve publish a sample of the project in Git Hub at https://github.com/hmadrigal/playground-dotnet/tree/master/MsDesktop.OnScreenKeyboard. The following items are the most relevant into the project sample:

  • Hmadrigal.Services.VirtualKeyboard: This projects holds the Service for a Virtual Keyboard.
    • NativeUser32.cs: Wrapper for Win32 low level calls
    • KeysEx.cs:  Known key codes. Set of known values to be inserted into the keyboard buffer.
    • VirtualKeyboardService.cs: Singleton class which exposes functionality in order to keep the state of the virtual keyboard.
  • Hmadrigal.WpfToolkit: This projects holds the visual representation for a on screen keyboard control in WPF.
    • QuertyKeyboard.cs: Custom control which keeps logic for appending strings or utilizing the virtual keyboard service.
    • Generic.xaml: Contains the default style for the custom control
    • WeakEventHandling.cs: Weak event handling (see references)
  • Hmadrigal.SampleKeyboard: WPF application using the custom keyboard with a web browser.

Querty Keyboard Control

Querty Keyboard Control using the virtual keyboard service

Remarks

  • The default style has set the attribute “Focusable” to “False” in all the buttons (or any other item which can get  the focus). This should be done for any custom style. Because of the virtual keyboard service does not known who is going to handle the reported input, then the app is responsible of setting the focus to the proper item.
  • When debugging and using  keys like shift, alt, ctrl, those are kept pressed by the virtual keyboard service, but they will affect your debug execution because of the input is happening at the operative system level. So, be cautious about where the breakpoints are set.
  • Multilingual by using IME. Particularly I’ve set up my PC to use IMEI Japanese using romanji, so  FYI it will continue working ;-).
  • Because of the WebBrowser control is a Win32 interop control running on WPF, the default focus might no be on the WebBrowser contol. Sadly I don’t have a solution for this yet, just make sure that the user have an option to set the focus into the WebBrowser control once it has been loaded.

Code

The sample code for this application is on Git Hub at:
https://github.com/hmadrigal/playground-dotnet/tree/master/MsDesktop.OnScreenKeyboard

NOTE (01/29/2014) Even at this time, this post continues to be one of the most viewed in my (humble) blog. However, I had forgotten to update this post in particular, at https://polaris.codeplex.com is the latest version of this keyboard (which is more likely to have less bugs and more flexibility such as a Debug Mode, and adding custom keys with more ease). My advice is to get the code and export the control, since the polaris libraries are meant for being downloaded and work all together, and you will be more likely to use only the keyboard.

References

How to make the Windows OSK open when a TextBox gets focus, instead of requiring users to tap a keyboard icon?
http://stackoverflow.com/questions/7518074/how-to-make-the-windows-osk-open-when-a-textbox-gets-focus-instead-of-requiring/7529920#7529920

.NET Framework Developer Center / Creating custom InputDevice
http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/a813a08a-7960-45fe-bc91-e81cdb75bd10

Wosk: Flexible On Screen Keyboard using WPF
http://wosk.codeplex.com/SourceControl/list/changesets

SendInput Example In C#
http://www.ownedcore.com/forums/mmo/warhammer-online/186390-sendinput-example-c.html

Simulating Keyboard with SendInput API in DirectInput applications
http://stackoverflow.com/questions/3644881/simulating-keyboard-with-sendinput-api-in-directinput-applications

Generic implementation for a weak event handling
http://puremsil.wordpress.com/2010/05/03/generic-weak-event-handlers/

From Joel Pobar’s CLR weblog Creating delegate types via Reflection.Emit
http://blogs.msdn.com/joelpob/archive/2004/02/15/73239.aspx

Xhader 1.1


Hello Fellas,

Today I’ve released a new version of Xhader.

http://xhader.codeplex.com/releases/view/77425

The major feature is that it should work on Blend 4. Additionally it should be using WPF 4.0 and SL 4.0 support.

Regards,
Herber

Free ebook: Programming Windows Phone 7, by Charles Petzold


Hello

Certainly a platform is as strong as the tools that you can use on it. Microsoft is giving a lot of resources for developers in order to start producing in Windows Phone 7 (WP7). This time Microsoft Press book is giving a free ebook Programming Windows Phone 7 by Charles Petzold.

 

You can download it at Free ebook: Programming Windows Phone 7, by Charles Petzold

Best regards,
Herber

Free ebook: Programming Windows Phone 7, by Charles Petzold

Free ebooks from Microsoft Patterns and Practices


Hi,

I’ve collected some information about Microsoft free publications, and I think that they’re something people might be interested in. These ebooks are free and are updated by Microsoft Community (I think most of them from Patterns and Practices). So, the following is a list of the ebooks you will find from Microsoft:

Electronic books (ebooks)

Certainly there are many resources on when which are available to learn about development. Microsoft editorial for example they offer free ebooks from time to time. Microsoft Patterns and Practices also have some free ebooks available to download. Following are ebooks available for free:

Notes

  1. Microsoft Patterns and Practices is an constantly evolving project it’s possible see their progress at Microsoft Patterns and Practices Complete Catalogbacause of this it’s possible that the local version is outdated.
Cover Name Summary Source
Improving Web Services Security byMicrosoft Corporation Patterns and Practices This guide shows you how to make the most of WCF (Windows Communication Foundation). With end-to-end application scenarios, it shows you how to design and implement authentication and authorization in WCF. Learn how to improve the security of your WCF services through prescriptive guidance including guidelines, Q&A, practices at a glance, and step-by-step how tos. It’s a collaborative effort between patterns & practices, WCF team members, and industry experts. wcfsecurityguide at codeplex
Microsoft Application Architecture Guide, 2nd Edition byMicrosoft Corporation Patterns and Practices The guide is intended to help developers and solution architects design and build effective, high quality applications using the Microsoft platform and the .NET Framework more quickly and with less risk; it provides guidance for using architecture principles, design principles, and patterns that are tried and trusted. The guidance is presented in sections that correspond to major architecture and design focus points. It is designed to be used as a reference resource or to be read from beginning to end. Application Architecture Guide at MSDN
Performance Testing Guidance for Web Applications byMicrosoft Corporation Patterns and Practices This guide shows you an end-to-end approach for implementing performance testing. Whether you are new to performance testing, or looking for ways to improve your current performance testing approach, you will find insights that you can tailor for your specific scenarios. perftestingguide at codeplex

Performance Testing Guidance for Web Applications At MSDN

Team Development with Visual Studio Team Foundation Server by Microsoft Corporation Patterns and Practices This guide shows you how to make the most of Team Foundation Server. It starts with the end in mind, but shows you how to incrementally adopt TFS for your organization. It’s a collaborative effort between patterns & practices, Team System team members, and industry experts. tfsguide at codeplex

Team Development with Visual Studio Team Foundation Server at MSDN

Developers Guide to Microsoft Prism byMicrosoft Corporation Patterns and Practices Prism provides guidance designed to help you more easily design and build rich, flexible, and easy to maintain Windows Presentation Foundation (WPF) desktop applications and Silverlight Rich Internet Applications (RIAs) and Windows Phone 7 applications. Using design patterns that embody important architectural design principles, such as separation of concerns and loose coupling, Prism helps you to design and build applications using loosely coupled components that can evolve independently but which can be easily and seamlessly integrated into the overall application. Such applications are often referred to as composite applications. Developer’s Guide to Microsoft Prism at MSDN

Excuse me if I didn’t hosted the ebooks to download, instead I provide the original source link. I think it’s worthy to visit the site because  you are more likely to find the latest version, and visit their site is a good price to pay for a free ebook.

 

Best regards,

Herber

Firefox: Last.fm and DownloadHelper


Hola,

Bien, estoy planeadno cambiar de computador por uno mas nuevo, entonces decidi instalar plugins en firefox para pobarlos. Tengo un lista de extensiones que me parecen utiles para ustedes, pero hay una combinacion que me parecio interesante:

1. fire.fm Esta extension permite escuchar musica desde el sitio de Last.fm .
2. DownloadHelper: Esta extension te ayuda a bajar cualquier contenido multimedia que esttes navegando. Vea mas detalles en la pagina downloadhelper

Aqui esta la cuestion, cuando trabajas junto los dos plugins te permiten descargar musica directamente from Last.fm. Como siempre, es un curioso efecto secundario.

Saludos,
Herberth

Firefox: Last.fm and DownloadHelper


Hello,

Well, I’m planning to change my computer for a new one, so I decided to install plugin in firefox for testing all I haven’t had the chance. I have a list of plug ins that I might encourage you to use, but here I only want to point an interesting combination:

1. fire.fm This plug in lets you listen your station or your favorites stations from Last.fm site.
2. DownloadHelper: This plug in help you to download any media content where you are navigating. See downloadhelper’s page for more details.

Here is the deal, when you work with both plug ins at the same time, you are able to download song from Last.fm. As always, it’s a kind of funny side effect. Enjoy it.

Regards,
Herberth