2

I have developed a Windows Forms application which is used on a touchscreen computer. Is it possible to display a keyboard when the user clicks on an input box (textbox)? And how can i do that ?

Emil Dumbazu
  • 662
  • 4
  • 22
  • 37

4 Answers4

4

Your example show error for me:

"Could not start On-Screen Keyboard"

I found this code which work fine without any errors:

static void StartOSK()
{
  string windir = Environment.GetEnvironmentVariable("WINDIR");
  string osk = null;

  if (osk == null)
  {
    osk = Path.Combine(Path.Combine(windir, "sysnative"), "osk.exe");
    if (!File.Exists(osk))
      osk = null;
  }

  if (osk == null)
  {
    osk = Path.Combine(Path.Combine(windir, "system32"), "osk.exe");
    if (!File.Exists(osk))
    {
      osk = null;
    }
  }

  if (osk == null)
    osk = "osk.exe";

  Process.Start(osk);
}
WooCaSh
  • 5,180
  • 5
  • 36
  • 54
4

Are you aware Windows has an on screen keyboard?

In Windows 7 it is All Programs > Accesseries > Ease Of Access > On Screen Keyboard.

You can write you own if you want, but I use the Windows one all the time when I do not feel like picking up the keyboard.

You can create a shortcut to it:

The location is %windir%\system32\osk.exe

So to launch it, in the TextBox_Click event (or whatever event you want to fire)

// Should work, I have not tested it. System.Diagnostics.Process.Start("c:\Windows\System32\osk.exe");

Just an update: On my machine at work I got an error trying to run that code (I built it as a test) and I had to copy the osk.exe to another directory and then launch it and it worked.

    /// <summary>
    /// Test to show launching on screen board (osk.exe).
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void textBox1_Click(object sender, EventArgs e)
    {
        try
        {
            Process.Start(@"c:\Temp\OSK.exe");
        }
        catch (Exception error)
        {
            string err = error.ToString();
        }
    }

And this code worked.

user1054326
  • 318
  • 1
  • 3
  • 1
    I would say that it could be slightly error-prone to use the built-in Windows On-Screen Keyboard, as it allows for the user to send all kinds of keystrokes which might not be what is intended in the application. In this case, a custom-made on-screen keyboard would be a safer bet. – markj Apr 24 '15 at 12:12
1

I think you can use. System.Diagnostics.process.start

   System.Diagnostics.Process.Start("osk.exe");
dor
  • 11
  • 1
1

I think you have to create a new form to ccreate the keyboard and launch this form in textbox click

Asmodeo
  • 43
  • 3