using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using DreamCheeky;
using WindowsInput;
using WindowsInput.Native;

namespace Test.Application
{
    class Program
    {
        [DllImport("user32.dll")]
        private static extern bool SetForegroundWindow(IntPtr hWnd);
        static void Main()
        {
            InputSimulator inputSimulator = new InputSimulator();
            using (var bigRedButton = new BigRedButton())
            {
                bigRedButton.LidOpen += (sender, args) => {
                    var prc = Process.GetProcessesByName("idea64");
                    if (prc.Length > 0)
                    {
                        SetForegroundWindow(prc[0].MainWindowHandle);
                    }
                };
                bigRedButton.ButtonPressed += (sender, args) =>
                {
                    var prc = Process.GetProcessesByName("idea64");
                    if (prc.Length > 0)
                    {
                        SetForegroundWindow(prc[0].MainWindowHandle);
                        inputSimulator.Keyboard.KeyDown(VirtualKeyCode.SHIFT);
                        inputSimulator.Keyboard.KeyPress(VirtualKeyCode.F9);
                        inputSimulator.Keyboard.KeyUp(VirtualKeyCode.SHIFT);
                    }
                    
                };
                bigRedButton.LidClosed += (sender, args) =>
                {
                    var prc = Process.GetProcessesByName("idea64");
                    if (prc.Length > 0)
                    {
                        inputSimulator.Keyboard.KeyDown(VirtualKeyCode.CONTROL);
                        inputSimulator.Keyboard.KeyPress(VirtualKeyCode.F2);
                        inputSimulator.Keyboard.KeyUp(VirtualKeyCode.CONTROL);
                    }
                };
                bigRedButton.Start();

                Console.WriteLine("Press ENTER to exit");
                Console.ReadLine();
            }
        }
    }
 
}
