基于微软提供的osk.exe(On-Screen Keyboard)实现软键盘功能。
窗体上有一个文本框和按钮,点击按钮时打开软键盘同时文本框获取焦点,接收软键盘的输入。
主要代码:
DllImport("kernel32.dll", SetLastError = true)\] private static extern bool Wow64DisableWow64FsRedirection(ref IntPtr ptr); \[DllImport("kernel32.dll", SetLastError = true)\] private static extern bool Wow64RevertWow64FsRedirection(IntPtr ptr); private void button1_Click(object sender, EventArgs e) { bool isKeyboadRunning = Process.GetProcessesByName("osk").Length \> 0; if (isKeyboadRunning) return; IntPtr ptr = IntPtr.Zero; bool redirected = Wow64DisableWow64FsRedirection(ref ptr); try { Process.Start("osk.exe"); } finally { if (redirected) { Wow64RevertWow64FsRedirection(ptr); } textBox1.Focus(); } } 程序发布后,从网上下载osk.exe和msswch.dll,放到发布后的目录中。  程序运行后,点击按钮可打开软键盘。 