Making an Onscreen Keyboard

Introduction

Onscreen keyboards are quite common. Usually, the best place to find an implementation of an onscreen keyboard can be found in a restaurant's point of sale application. These days, though, using an onscreen keyboard application could be found in any industry. Today, I will show you how to make a very basic onscreen keyboard application.

Onscreen Keyboard Application

The characteristics of an onscreen keyboard application are mainly the fact that the end product does not have a method for keyboard input. Reasons for this could be due to security, or simply ease of access. An onscreen keyboard, or an OSK, is an application that provides an onscreen keyboard that can be used with a mouse or touch for touchscreens.

Our Project

Today, you will create a very basic onscreen keyboard.

Design

Open Visual Basic and create a new Windows Forms application. You may name the application anything you like. Once the project has been created, design your form to resemble Figure 1:

Figure 1: Our design

It doesn't look like much, yet. When designing your form, be careful to leave enough space for the buttons of the keyboard that we will create dynamically.

First, I create a new button object named BtnCap. This button or buttons will be placed on the form and will hold all the capitalized letters of the alphabet. Next, I created two objects to hold the first button's location (in pixels) and later on I will manipulate the left and top objects to put the buttons next to each other. I then made use of a with structure to set the dynamic button's Name, Text, Size, Location, and Tag properties inside the For Loop.

When the character M is reached, the characters must continue under the previous 13 buttons. Lastly, I set the Visible property to true, add the dynamic button to the form and create an event handler for when the particular button is clicked. Add the Click event for the buttons now:

The code is basically the same, except that now we are testing and using small letters, as shown in Figure 3:

Figure 3: Adding small letters

Numbers

Working with numbers is a tad easier than letters. You do not need to use any character manipulation techniques to convert the number to a character. You can simply use a loop from 0 to 9 and use almost the same code as above to get the numbers to appear. Here is a small example: