Program.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. namespace KeyBoard2
  7. {
  8. internal class Program
  9. {
  10. static void Main(string[] args)
  11. {
  12. string exePath = @"D:\work\WindowsFormsTest\KeyBoard2\bin\Debug\CCOnScreenKeyboard.exe"; // 替换为你的 exe 路径
  13. string argsParam = "1 \r\n-ShowNumPad"; // 如果有参数,例如 "config.txt"
  14. try
  15. {
  16. // 1. 启动程序(隐藏模式)
  17. Console.WriteLine("正在启动程序...");
  18. CCOnScreenKeyBoardClass.Start(exePath, argsParam, hidden: true);
  19. // 模拟程序运行一段时间
  20. System.Threading.Thread.Sleep(3000);
  21. // 2. 检查状态
  22. if (CCOnScreenKeyBoardClass.IsRunning)
  23. {
  24. Console.WriteLine("程序正在运行中。");
  25. }
  26. // 3. 关闭程序
  27. Console.WriteLine("正在关闭程序...");
  28. CCOnScreenKeyBoardClass.Stop(forceKill: false); // 先尝试优雅关闭
  29. Console.WriteLine("操作完成。");
  30. }
  31. catch (Exception ex)
  32. {
  33. Console.WriteLine($"发生错误: {ex.Message}");
  34. }
  35. }
  36. }
  37. }