예제 #1
0
        private static bool SendMessageKeyDown(IntPtr hWnd, VKeys key)
        {
            IntPtr result = MessagingApi.SendMessage(hWnd, (int)Message.KEY_DOWN, (uint)key, GetLParam(1, key, 0, 0, 0, 0));

            //return result != IntPtr.Zero;
            return(true);
        }
예제 #2
0
        public static bool SendChar(IntPtr hWnd, char c, bool checkKeyboardState)
        {
            if (checkKeyboardState)
            {
                CheckKeyShiftState();
            }

            //Send VM_CHAR
            IntPtr result = MessagingApi.SendMessage(hWnd, (int)Message.VM_CHAR, c, 0);

            return(result != IntPtr.Zero);
        }
예제 #3
0
        public static bool SendMessageKey(IntPtr hWnd, Key key, bool alt = false, bool ctrl = false, bool shift = false, int delay = 100)
        {
            CheckKeyShiftState();

            // Key down shift, ctrl, and/or alt
            if (alt)
            {
                if (!SendMessageKeyDown(hWnd, VKeys.KEY_MENU))
                {
                    return(false);
                }
            }
            if (ctrl)
            {
                if (!SendMessageKeyDown(hWnd, VKeys.KEY_CONTROL))
                {
                    return(false);
                }
            }
            if (shift)
            {
                if (!SendMessageKeyDown(hWnd, VKeys.KEY_SHIFT))
                {
                    return(false);
                }
            }

            //Send VM_CHAR
            IntPtr result = MessagingApi.SendMessage(hWnd, (int)Message.VM_CHAR, (uint)key.Vk, GetLParam(1, key.Vk, 0, 0, 0, 0));

            //if (result == IntPtr.Zero)
            //{
            //    return false;
            //}
            Thread.Sleep(delay);

            // Key down shift, ctrl, and/or alt
            if (alt)
            {
                if (!SendMessageKeyUp(hWnd, VKeys.KEY_MENU))
                {
                    return(false);
                }
            }
            if (ctrl)
            {
                if (!SendMessageKeyUp(hWnd, VKeys.KEY_CONTROL))
                {
                    return(false);
                }
            }
            if (shift)
            {
                if (!SendMessageKeyUp(hWnd, VKeys.KEY_SHIFT))
                {
                    return(false);
                }
            }

            return(true);
        }