首先我們說的鍵盤指的是:tabtip和osk。但這兩個所在的位置不同,樣貌也不一樣
C:\Windows\System32\osk.exe
C:\Program Files\Common Files\microsoft shared\ink\TabTip.exe
調用之前,最好先殺一下之前的鍵盤進程
var processes = Process.GetProcessesByName(Path.GetFileNameWithoutExtension("TabTip")); foreach (var p in processes) { p.Kill(); }
最后啟動鍵盤進程
var commonFilesPath = Environment.GetFolderPath(Environment.SpecialFolder.CommonProgramFiles); //程序集目標平台為X86時,獲取到的是x86的Program Files,但TabTip.exe始終在Program Files目錄下 if (commonFilesPath.Contains("Program Files (x86)")) { commonFilesPath = commonFilesPath.Replace("Program Files (x86)", "Program Files"); } var tabTipPath = Path.Combine(commonFilesPath, @"microsoft shared\ink\TabTip.exe"); if (File.Exists(tabTipPath)) { ProcessStartInfo psi = new ProcessStartInfo { FileName = tabTipPath, UseShellExecute = true, CreateNoWindow = true }; Process.Start(psi); }