Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / Languages / C#4.0

Combine physical keyboard with on-screen keyboard

0.00/5 (No votes)
12 Jun 2013CPOL1 min read 13.3K   1.7K  
Create your own keyboards, keypads/ virtual buttons on top of other windows; filter unwanted input.

On-Screen Keyboard

Introduction

Many developers argue that analysis of user inputs is not an easy task and some of the existing software are inherently safer just because of bad inputs. I have a need to make an on-screen keyboard with standard features for my hydrological library (this library basically is a bunch of functions for spatial and temporal computation which has been developed in Vrije University of Brussels). The article looks at a small part of my work starting from zero in programming to making a virtual keyboard. The advantage of this keyboard in an international environment like Brussels is that you may avoid wrong characters. In addition these simple features make life much easier.

Background

Sometimes you prefer to use a virtual keyboard instead of relying on the physical keyboard. You may use On-Screen Keyboard as an optional way to input data or you can mix the entered data from physical and virtual keyboards. This On-Screen Keyboard is designed to display a visual of all the standard keys. The current version of the on-screen keyboard accepts input from three kinds of controls including combobox, textbox, richtextbox, but you can easily extend it for other usages.

Using the code

As you can see in the provided example, there is just one form that is the heart of this On-Screen keyboard. The only thing that must be done in your own application is implementing the type of input controls, like this:

C#
Keybord VirtualKeyoard = new Keybord();
VirtualKeyoard.PARENT = this;
//define bounded control here
VirtualKeyoard.SetControl = InputrichText;
int screenHeight = Screen.PrimaryScreen.WorkingArea.Height;
int screenWidth = Screen.PrimaryScreen.WorkingArea.Width;
Point parentPoint = this.Location; int parentHeight = this.Height;
int parentWidth = this.Width;
int resultX; int resultY;
resultY = parentPoint.Y + (this.Height);
resultX = parentPoint.X + 30;
VirtualKeyoard.Location = new Point(resultX, resultY);
//if you want to force //
VirtualKeyoard.ShowDialog(this); VirtualKeyoard.Show(this);

Points of Interest

I could not find time to test the keyboard in practice but the initial test was quite OK.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)