LitDev.LDTextWindow.SendKey C# (CSharp) Method

SendKey() public static method

Send a key to a window. This is the same a typing the key into a window.
public static SendKey ( Primitive window, Primitive key ) : void
window Primitive The window title e.g. TextWindow.Title or GraphicsWindow.Title.
key Primitive The key to send e.g. "Return"
return void
        public static void SendKey(Primitive window, Primitive key)
        {
            try
            {
                Key _key = (Key)kc.ConvertFromString(key);
                int _keycode = KeyInterop.VirtualKeyFromKey(_key);
                IntPtr _hWnd = User32.FindWindow(null, window);
                User32.PostMessage(_hWnd, User32.WM_KEYDOWN, _keycode, 0);
            }
            catch (Exception ex)
            {
                Utilities.OnError(Utilities.GetCurrentMethod(), ex);
            }
        }