예제 #1
0
        public static INPUT AddKeyDown(VirtualKeyCode keyCode)
        {
            var down =
                new INPUT
            {
                Type = (UInt32)InputType.Keyboard,
                Data =
                {
                    Keyboard      =
                        new KEYBDINPUT
                    {
                        KeyCode   = (UInt16)keyCode,
                        Scan      = (UInt16)(User32Native.MapVirtualKey((UInt32)keyCode,           0) & 0xFFU),
                        Flags     = IsExtendedKey(keyCode) ? (UInt32)KeyboardFlag.ExtendedKey : 0,
                        Time      =                                                             0,
                        ExtraInfo = IntPtr.Zero
                    }
                }
            };

            return(down);
        }
예제 #2
0
        public static INPUT AddKeyUp(VirtualKeyCode keyCode)
        {
            var up =
                new INPUT
            {
                Type = (UInt32)InputType.Keyboard,
                Data =
                {
                    Keyboard      =
                        new KEYBDINPUT
                    {
                        KeyCode = (UInt16)keyCode,
                        Scan    = (UInt16)(User32Native.MapVirtualKey((UInt32)keyCode, 0) & 0xFFU),
                        Flags   = (UInt32)(IsExtendedKey(keyCode)
                                    ? KeyboardFlag.KeyUp | KeyboardFlag.ExtendedKey
                                    : KeyboardFlag.KeyUp),
                        Time      =                                                   0,
                        ExtraInfo = IntPtr.Zero
                    }
                }
            };

            return(up);
        }