Click here to Skip to main content
15,885,366 members
Articles / Desktop Programming / Windows Forms
Article

Mobile Phone - like keyboard control in C#

Rate me:
Please Sign up or sign in to vote.
1.63/5 (6 votes)
19 Feb 20054 min read 70.8K   3K   21   9
How do you want to enter text with an IR-Remote? Well, this is the solution...

Sample image

Introduction

Demo project (FileSearcher)

The FileSearcher is the demo of the MCKeyboard. When you start it you can define a root folder for the searcher. Then you have to enter a search string by using the mobile phone control. With the GET IT button you can search the file names recursively.

Source Code and Compiled Code

The code is compiled as .NET UserControl DLL containing two classes...the MobileKB class and the Selector class.

MobileKB is the control itself. Besides the buttons, labels and textboxes, it contains two timers, one for updating the current character textbox (updateTimer) and the other for writing the current character (currentChar) and going on to the next (nextTimer). It also has a variable to indicate how often the button was hit and where we are in the array containing the source characters from keys.txt (pressCount). Finally, there is also an instance of the Selector class.

The Selector is the part of the control, which always returns the right character to the MobileKB, depending on which button was hit and how often it was hit. For example, if we hit button "4" three times, then we want to have a "l". This is done by the method GetChar(int, int). We take the first int to determine what line of characters is right and the second int to get the right character out of this line.

Background

Not long ago, myself and a friend had to test a Mediacenter-PC and we found it very exciting about what you can do with such a HomeCinema-Monster =). Not having any money at all, we put a computer next to our TV and started programming our own Mediacenter Software (which will soon be available at here). One of the difficulties for us was to provide a way to add text to the software using only a IR-remote. Our first try was a control with a keyboard graphic. You had to select a key and hit "Enter" on the IR to set a character. This was too much work to write the code, so we decided to use the keyboard style that mobile phones have. It is a much smoother way to enter text, because you don't have to navigate too much. This control is set up faster too, because the characters, which are shown by button-hitting, are defined in a text file outside and the timers can easily be set.

Using the code

The control is easy to set up:

  • Go to the form (designer-mode) you want to add the control to.
  • Right-click on the "Toolbox" will let you access the "Add/Remove Items" option. Then click the "Browse" button.
  • Look for the MCKeyboard.dll and double click it.
  • Add an instance to your form. You will receive an error message with a certain path at the end. You only have to copy the keys.txt file to this directory and it will work.

You can also use this way:

  • Add a reference to the DLL and integrate it through a using directive. Then you have to create an instance of MobileKB.
    using SARS.MCKeyboard;
    private MobileKB objMobileKB = new MobileKB();
  • Modify it like what you want. To test the control, I would prefer the default settings. The updateTimer.Interval would be 10 and the interval from nextTimer would be 1500.
  • To show the control just calls its Show() method. To update the status label, just call the Status(String) method.

Remember: You will receive an error message with a certain path at the end. You only have to copy the keys.txt file to this directory and it will work.

Points of Interest

I still have some problems or code which is a little bit "dirty". For example, when you remove an instance of MobileKB from your form, there will be an ObjectDisposedException saying there's no access to a disposed textbox. Well...I think...that's true =). But I couldn't fix this problem by now. Another thing that's a little poor is the the navigation within the control. I'd rather have a arrow-key-based navigation than a tab-based navigation. But it's a little work. The last one is the error message that keys.txt was not found. hmm, copying does it but I have to fix this. I'm sure there will be an updated version soon...with your help.

I also want to say that I really look forward getting some feedback and tipps for writing this code better. Every mail is welcome.

History

I didn't do any changes to the code since it landed at CodeProject. But I want to fix the problem with the exception, get another solution instead of the updateTimer and I want the code to be smaller. You will hear from me soon...=)

P.S.: Please email if you have questions. I also am online every day at the lounge.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
Germany Germany
Male.
From the beer temple of europe...Bavaria. (from Rosenheim, to be exactly)
Currently studying computer science and hoping to finish it as fast as i can.
Besides working for a high frequency technology company in my town.
My first Computer was one of these old Schneider "PCs" with a deck for MCs. I was 10 years old. =)
Another thing I am addicted to is music...my current favourite genres are drum n bass, big beat (fatboy slim..you know), tribal house and ethnic sound like didgeridoo mixed with good electrobeats. YEAH! =)

homepage? >>> depF-Net

Comments and Discussions

 
Questionneed help please Pin
Member 1300345016-Feb-17 7:41
Member 1300345016-Feb-17 7:41 
Someone has a project similar to this

GeneralBroken links Pin
mattvil20-Feb-05 0:53
mattvil20-Feb-05 0:53 
GeneralRe: Broken links Pin
turndevil20-Feb-05 1:17
turndevil20-Feb-05 1:17 
Generalu Pin
Marc Clifton19-Feb-05 12:41
mvaMarc Clifton19-Feb-05 12:41 
GeneralRe: u Pin
DavidNohejl19-Feb-05 13:21
DavidNohejl19-Feb-05 13:21 
GeneralRe: u Pin
turndevil20-Feb-05 1:32
turndevil20-Feb-05 1:32 
GeneralRe: u Pin
DavidNohejl20-Feb-05 7:00
DavidNohejl20-Feb-05 7:00 
GeneralRe: u Pin
turndevil20-Feb-05 10:39
turndevil20-Feb-05 10:39 
GeneralRe: u Pin
mav.northwind21-Feb-05 22:59
mav.northwind21-Feb-05 22:59 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.