SoftKeyboard.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. using System;
  2. using System.Configuration;
  3. using System.Windows.Forms;
  4. namespace GCAS.Code
  5. {
  6. public class SoftKeyboard
  7. {
  8. private static System.Diagnostics.Process softKey;
  9. public static void ActiveSoftKeyboard(object sender)
  10. {
  11. var autoSoftKeybord = ConfigurationManager.AppSettings["autoSoftKeybord"];
  12. if (!bool.TryParse(autoSoftKeybord, out bool isAutoSoftKeybord) || !isAutoSoftKeybord)
  13. {
  14. return;
  15. }
  16. //打开软键盘
  17. try
  18. {
  19. if (!System.IO.File.Exists(Environment.SystemDirectory + "\\osk.exe"))
  20. {
  21. return;
  22. }
  23. if (softKey == null || softKey.HasExited)
  24. {
  25. softKey = System.Diagnostics.Process.Start("C:\\Windows\\System32\\osk.exe");
  26. }
  27. else
  28. {
  29. softKey = System.Diagnostics.Process.Start("C:\\Windows\\System32\\osk.exe");
  30. }
  31. var text = (sender as Control);
  32. text.Focus();
  33. text.Leave += Text_Leave;
  34. }
  35. catch (Exception ex)
  36. {
  37. MessageBox.Show(ex.Message);
  38. }
  39. }
  40. private static void Text_Leave(object sender, EventArgs e)
  41. {
  42. if (softKey != null && !softKey.HasExited)
  43. {
  44. softKey.Kill();
  45. }
  46. }
  47. }
  48. }