Ejemplo n.º 1
0
        internal static Input FromKeyCode(VirtualKeyCode keyCode, KeyDirection direction)
        {
            KeyEventFlags flags = 0;

            if (keyCode.IsExtendedKey())
            {
                flags |= KeyEventFlags.ExtendedKey;
            }
            if (direction == KeyDirection.Up)
            {
                flags |= KeyEventFlags.KeyUp;
            }

            return(new Input
            {
                Type = InputType.Keyboard,
                Data = new KeyboardInput
                {
                    KeyCode = keyCode,
                    ScanCode = 0,
                    Flags = flags,
                    Time = 0,
                    ExtraInfo = IntPtr.Zero
                }
            });
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Effectively sends the keyboard input command.
        /// </summary>
        /// <param name="keyCode">The key code to send. Can be the scan code or the virtual key code.</param>
        /// <param name="keyFlags">Flag if the key should be pressed or released.</param>
        private static void SendInput(ushort keyCode, KeyEventFlags keyFlags)
        {
            // Add the extended flag if the flag is set or the keycode is prefixed with the byte 0xE0
            // See https://msdn.microsoft.com/en-us/library/windows/desktop/ms646267(v=vs.85).aspx
            if ((keyCode & 0xFF00) == 0xE0)
            {
                keyFlags |= KeyEventFlags.KEYEVENTF_EXTENDEDKEY;
            }

            // Prepare the basic object
            var keyboardInput = new KEYBDINPUT
            {
                dwExtraInfo = User32.GetMessageExtraInfo(),
                dwFlags     = keyFlags,
            };

            if (keyFlags.HasFlag(KeyEventFlags.KEYEVENTF_SCANCODE) ||
                keyFlags.HasFlag(KeyEventFlags.KEYEVENTF_UNICODE))
            {
                keyboardInput.wScan = keyCode;
            }
            else
            {
                keyboardInput.wVk = keyCode;
            }

            SendInput(keyboardInput);
            Wait.For(TimeSpan.FromMilliseconds(10));
        }
Ejemplo n.º 3
0
 public static void KeyEvent(KeyEventFlags key, KeyEventFlags value)
 {
     keybd_event((byte)key,
                 0,
                 (int)value,
                 0);
 }
Ejemplo n.º 4
0
 public KeyEventInfo(VirtualKey vkCode, ScanCode scanCode, KeyEventFlags flags, uint time, UIntPtr dwExtraInfo)
     : this()
 {
     VkCode      = vkCode;
     ScanCode    = scanCode;
     Flags       = flags;
     Time        = time;
     DwExtraInfo = dwExtraInfo;
 }
 public ScanBarEvent(long downTime, long eventTime, KeyEventActions action, Keycode code, int repeat, MetaKeyStates metaState, int deviceId, int scancode, KeyEventFlags flags, InputSourceType source) : base(downTime, eventTime, action, code, repeat, metaState, deviceId, scancode, flags, source)
 {
 }
 public ScanBarEvent(long time, string characters, int deviceId, KeyEventFlags flags) : base(time, characters, deviceId, flags)
 {
 }
Ejemplo n.º 7
0
 public static void KeyboardEvent(System.Windows.Forms.Keys VirtualKeyCode, KeyEventFlags Flags)
 {
     keybd_event((byte)VirtualKeyCode, (byte)0, (int)Flags, 0);
 }