Beispiel #1
0
        public static void PressOnPoint(IntPtr wndHandle, Point clientPoint)
        {
            var oldPosition = Cursor.Position;

            UserBindings.ClientToScreen(wndHandle, ref clientPoint);
            Cursor.Position = new Point(clientPoint.X, clientPoint.Y);

            var inputMouseDown = new UserBindings.INPUT {
                Type = 0
            };

            inputMouseDown.Data.Mouse.Flags = 0x0002;

            var inputMouseUp = new UserBindings.INPUT {
                Type = 0
            };

            inputMouseUp.Data.Mouse.Flags = 0x0004;

            var inputs = new[] { inputMouseDown };

            UserBindings.SendInput((uint)inputs.Length, inputs, Marshal.SizeOf(typeof(UserBindings.INPUT)));

            Cursor.Position = oldPosition;
        }
Beispiel #2
0
        private static UserBindings.INPUT[] GetCharacterInputs(char character)
        {
            UInt16 scanCode = character;

            var down = new UserBindings.INPUT
            {
                Type = (UInt32)1,
                Data =
                {
                    Keyboard      =
                        new UserBindings.KEYBDINPUT
                    {
                        KeyCode   =              0,
                        Scan      = scanCode,
                        Flags     = (UInt32)0x0004,
                        Time      =              0,
                        ExtraInfo = IntPtr.Zero
                    }
                }
            };

            var up = new UserBindings.INPUT
            {
                Type = (UInt32)1,
                Data =
                {
                    Keyboard      =
                        new UserBindings.KEYBDINPUT
                    {
                        KeyCode   =                         0,
                        Scan      = scanCode,
                        Flags     = (UInt32)(0x0002 | 0x0004),
                        Time      =                         0,
                        ExtraInfo = IntPtr.Zero
                    }
                }
            };

            if ((scanCode & 0xFF00) == 0xE000)
            {
                down.Data.Keyboard.Flags |= (UInt32)0x0001;
                up.Data.Keyboard.Flags   |= (UInt32)0x0001;
            }

            return(new [] { down, up });
        }