Keyboard on the screen in WinForms

2019-05-26 18:44发布

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 ?

4条回答
等我变得足够好
2楼-- · 2019-05-26 18:56

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.

查看更多
够拽才男人
3楼-- · 2019-05-26 19:00

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

   System.Diagnostics.Process.Start("osk.exe");
查看更多
forever°为你锁心
4楼-- · 2019-05-26 19:01

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);
}
查看更多
唯我独甜
5楼-- · 2019-05-26 19:11

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

查看更多
登录 后发表回答