WinForms 屏幕上的键盘

发布于 2025-01-05 10:42:02 字数 74 浏览 1 评论 0原文

我开发了一个在触摸屏计算机上使用的 Windows 窗体应用程序。当用户点击输入框(文本框)时是否可以显示键盘?我怎样才能做到这一点?

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 ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

耳根太软 2025-01-12 10:42:03

您知道 Windows 有屏幕键盘吗?

在 Windows 7 中,它是“所有程序”>“配件>轻松访问>屏幕键盘。

如果你愿意的话,你可以自己写,但当我不想拿起键盘时,我一直使用 Windows 版本。

您可以创建它的快捷方式:

位置是 %windir%\system32\osk.exe

因此,要在 TextBox_Click 事件(或您想要触发的任何事件)中启动它

, // 应该可以工作,我还没有测试过它。
System.Diagnostics.Process.Start("c:\Windows\System32\osk.exe");

只是一个更新:在我工作的机器上,我尝试运行该代码时遇到错误(我将其构建为测试),我必须将 osk.exe 复制到另一个目录,然后启动它并且它可以工作。

    /// <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();
        }
    }

这段代码有效。

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.

风吹雪碎 2025-01-12 10:42:03

您的示例对我显示错误

“无法启动屏幕键盘”

我发现这段代码可以正常工作,没有任何错误:

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);
}

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);
}
笑,眼淚并存 2025-01-12 10:42:03

我认为您必须创建一个新表单来创建键盘并在文本框中单击启动此表单

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

风吹雨成花 2025-01-12 10:42:03

我想你可以用。系统.诊断.进程.启动

   System.Diagnostics.Process.Start("osk.exe");

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

   System.Diagnostics.Process.Start("osk.exe");
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文