Example #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);
        }
Example #2
0
 public static void CheckKeyShiftState()
 {
     while ((MessagingApi.GetKeyState((int)VKeys.KEY_MENU) & KEY_PRESSED) == KEY_PRESSED ||
            (MessagingApi.GetKeyState((int)VKeys.KEY_CONTROL) & KEY_PRESSED) == KEY_PRESSED ||
            (MessagingApi.GetKeyState((int)VKeys.KEY_SHIFT) & KEY_PRESSED) == KEY_PRESSED)
     {
         Thread.Sleep(1);
     }
 }
Example #3
0
        public static bool GetKeyState(Key key)
        {
            if ((MessagingApi.GetKeyState((int)key.Vk) & 0xF0) == 1)
            {
                return(true);
            }

            return(false);
        }
Example #4
0
        public Key(char c)
        {
            var helper = new Helper {
                Value = MessagingApi.VkKeyScan(c)
            };

            this.Vk        = (MessagingApi.VKeys)helper.Low;
            this.ShiftKey  = MessagingApi.VKeys.NULL;
            this.ShiftType = (MessagingApi.ShiftType)helper.High;
        }
Example #5
0
        private static bool PostMessageSafe(IntPtr hWnd, uint msg, uint wParam, uint lParam)
        {
            bool returnValue = MessagingApi.PostMessage(hWnd, msg, wParam, lParam);

            if (!returnValue)
            {
                // An error occured
                throw new Win32Exception(Marshal.GetLastWin32Error());
            }

            return(true);
        }
Example #6
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);
        }
Example #7
0
        public static void BackgroundMouseClick(IntPtr hWnd, Key key, int x, int y, int delay = 100)
        {
            switch (key.Vk)
            {
            case VKeys.KEY_MBUTTON:
                MessagingApi.PostMessage(hWnd, (int)Message.MBUTTONDOWN, (uint)key.Vk, GetLParam(x, y));
                Thread.Sleep(delay);
                MessagingApi.PostMessage(hWnd, (int)Message.MBUTTONUP, (uint)key.Vk, GetLParam(x, y));
                break;

            case VKeys.KEY_LBUTTON:
                MessagingApi.PostMessage(hWnd, (int)Message.LBUTTONDOWN, (uint)key.Vk, GetLParam(x, y));
                Thread.Sleep(delay);
                MessagingApi.PostMessage(hWnd, (int)Message.LBUTTONUP, (uint)key.Vk, GetLParam(x, y));
                break;

            case VKeys.KEY_RBUTTON:
                MessagingApi.PostMessage(hWnd, (int)Message.RBUTTONDOWN, (uint)key.Vk, GetLParam(x, y));
                Thread.Sleep(delay);
                MessagingApi.PostMessage(hWnd, (int)Message.RBUTTONUP, (uint)key.Vk, GetLParam(x, y));
                break;
            }
        }
Example #8
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);
        }
Example #9
0
 public static void BackgroundMousePosition(IntPtr hWnd, int x, int y)
 {
     MessagingApi.PostMessage(hWnd, (int)WindowsMessages.WM_MOUSEMOVE, 0, GetLParam(x, y));
 }