Tuesday, April 2, 2013

Using touch screen keyboard using C# in Windows 8

I was trying to make Windows 8 OSK (On screen Keyboard) keyboard to appear and go away when the user clicks / touches outside the textbox area. This feature is so user friendly and has been implemented in almost all the smart phones that use touch screen.

Finally after a bit of tweaking around, I invented this way which would enrich the user interface.

The following code can be used in C# that will make the OSK to appear when the user clicks or enters the textbox area and will go away once the user leaves or clicks away from the textbox area.

Code:

This code will call a method called openOnScreenKeyboard()

 private void textBox_MouseClick(object sender, MouseEventArgs e)
        {
            openOnScreenKeyboard();
        }

This method will call a method called killOnScreenKeyboard()

 private void textBox_Leave(object sender, EventArgs e)
        {
            killOnScreenKeyboard();
        }

This method goes into the program files and opens up the executable that launches the OSK.

private static void openOnScreenKeyboard()
        {           
            System.Diagnostics.Process.Start("C:\\Program Files\\Common Files\\Microsoft shared\\ink\\TabTip.exe");

        } 

This method goes into the processes, and looks for process that is called TabTip and kills it.

 private static void killOnScreenKeyboard()
        {
            if (System.Diagnostics.Process.GetProcessesByName("TabTip").Count() > 0)
            {
                System.Diagnostics.Process asd = System.Diagnostics.Process.GetProcessesByName("TabTip").First();
                asd.Kill();
            }

        }

Hope you found it helpful.

2 comments:

donotdont said...

if i want to use number
How to use it

Ashlesh said...

Chutirat Chaisan, I could not find a way to directly open a numeric keyboard. I have trained my users to press the number mode on the keyboard to use the OSK's numeric key pad.
Thanks,