using System; using System.Configuration; using System.Windows.Forms; namespace GCAS.Code { public class SoftKeyboard { private static System.Diagnostics.Process softKey; public static void ActiveSoftKeyboard(object sender) { var autoSoftKeybord = ConfigurationManager.AppSettings["autoSoftKeybord"]; if (!bool.TryParse(autoSoftKeybord, out bool isAutoSoftKeybord) || !isAutoSoftKeybord) { return; } //打开软键盘 try { if (!System.IO.File.Exists(Environment.SystemDirectory + "\\osk.exe")) { return; } if (softKey == null || softKey.HasExited) { softKey = System.Diagnostics.Process.Start("C:\\Windows\\System32\\osk.exe"); } else { softKey = System.Diagnostics.Process.Start("C:\\Windows\\System32\\osk.exe"); } var text = (sender as Control); text.Focus(); text.Leave += Text_Leave; } catch (Exception ex) { MessageBox.Show(ex.Message); } } private static void Text_Leave(object sender, EventArgs e) { if (softKey != null && !softKey.HasExited) { softKey.Kill(); } } } }