using System; using System.Diagnostics; using System.Runtime.InteropServices; namespace SimplySharp { public class SSInterop { // //Returns an 'IntPtr' window handle, otherwise it returns 'IntPtr.Zero': public static IntPtr GetWindowHandleByName(string str) { try { return(Process.GetProcessesByName(str)[0].MainWindowHandle); } catch { return(IntPtr.Zero); } } // public static void KeyboardEvent(ConsoleKey keyCode) { Keybd_Event((byte)keyCode, 0x45, 0x0001 | 0, 0); Keybd_Event((byte)keyCode, 0x45, 0x0001 | 0x0002, 0); } //External functions: [DllImport("Psapi")] public static extern bool EmptyWorkingSet(IntPtr process); [DllImport("user32.dll", EntryPoint = "keybd_event")] public static extern int Keybd_Event(byte bVk, byte bScan, ulong dwFlags, ulong dwExtraInfo); [DllImport("user32.dll")] public static extern IntPtr PostMessage(IntPtr hWnd, uint Msg, IntPtr wParam, long lParam); [DllImport("user32.dll")] public static extern bool ShowWindow(IntPtr hWnd, int nCmdShow); } }