Program.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. using System;
  2. using System.Diagnostics;
  3. using System.Runtime.InteropServices;
  4. using System.Windows.Forms;
  5. using DreamCheeky;
  6. using WindowsInput;
  7. using WindowsInput.Native;
  8. namespace Test.Application
  9. {
  10. class Program
  11. {
  12. [DllImport("user32.dll")]
  13. private static extern bool SetForegroundWindow(IntPtr hWnd);
  14. static void Main()
  15. {
  16. InputSimulator inputSimulator = new InputSimulator();
  17. using (var bigRedButton = new BigRedButton())
  18. {
  19. bigRedButton.LidOpen += (sender, args) => {
  20. var prc = Process.GetProcessesByName("idea64");
  21. if (prc.Length > 0)
  22. {
  23. SetForegroundWindow(prc[0].MainWindowHandle);
  24. }
  25. };
  26. bigRedButton.ButtonPressed += (sender, args) =>
  27. {
  28. var prc = Process.GetProcessesByName("idea64");
  29. if (prc.Length > 0)
  30. {
  31. SetForegroundWindow(prc[0].MainWindowHandle);
  32. inputSimulator.Keyboard.KeyDown(VirtualKeyCode.SHIFT);
  33. inputSimulator.Keyboard.KeyPress(VirtualKeyCode.F9);
  34. inputSimulator.Keyboard.KeyUp(VirtualKeyCode.SHIFT);
  35. }
  36. };
  37. bigRedButton.LidClosed += (sender, args) =>
  38. {
  39. var prc = Process.GetProcessesByName("idea64");
  40. if (prc.Length > 0)
  41. {
  42. inputSimulator.Keyboard.KeyDown(VirtualKeyCode.CONTROL);
  43. inputSimulator.Keyboard.KeyPress(VirtualKeyCode.F2);
  44. inputSimulator.Keyboard.KeyUp(VirtualKeyCode.CONTROL);
  45. }
  46. };
  47. bigRedButton.Start();
  48. Console.WriteLine("Press ENTER to exit");
  49. Console.ReadLine();
  50. }
  51. }
  52. }
  53. }