Example #1
0
        public InputBuilder AddKeyUp(Win32Constants.VirtualKeys keyCode)
        {
            var up =
                new Win32Types.INPUT {
                type = Win32Types.INPUTTYPE.INPUT_KEYBOARD,
//                    Data ={
//                        Keyboard =
//                            new Win32Types.KEYBDINPUT{
//                                KeyCode = (UInt16) keyCode,
//                                Scan = 0,
//                                Flags = (UInt32) (IsExtendedKey(keyCode)
//                                    ? KeyboardFlag.KeyUp | KeyboardFlag.ExtendedKey
//                                    : KeyboardFlag.KeyUp),
//                                Time = 0,
//                                ExtraInfo = IntPtr.Zero
//                            }
//                    }
            };
            var keybdinput = new Win32Types.KEYBDINPUT {
                wVk     = keyCode,
                wScan   = 0,
                dwFlags =
                    IsExtendedKey(keyCode)
                        ? Win32Constants.KeyboardEvent.KEYEVENTF_KEYUP |
                    Win32Constants.KeyboardEvent.KEYEVENTF_EXTENDEDKEY
                        : Win32Constants.KeyboardEvent.KEYEVENTF_KEYUP,
                time        = 0,
                dwExtraInfo = IntPtr.Zero
            };

            up.mkhi.ki = keybdinput;
            _inputList.Add(up);
            return(this);
        }
Example #2
0
        public InputBuilder AddCharacter(char character)
        {
            UInt16 scanCode = character;

            var down = new Win32Types.INPUT {
                type = Win32Types.INPUTTYPE.INPUT_KEYBOARD,
            };
            var keybdinput = new Win32Types.KEYBDINPUT {
                wVk         = 0,
                wScan       = scanCode,
                dwFlags     = Win32Constants.KeyboardEvent.KEYEVENTF_UNICODE,
                time        = 0,
                dwExtraInfo = IntPtr.Zero
            };

            down.mkhi.ki = keybdinput;
            var up = new Win32Types.INPUT {
                type = Win32Types.INPUTTYPE.INPUT_KEYBOARD,
//                Data ={
//                    Keyboard =
//                        new Win32Types.KEYBDINPUT{
//                            KeyCode = 0,
//                            Scan = scanCode,
//                            Flags =
//                                (UInt32) (KeyboardFlag.KeyUp | KeyboardFlag.Unicode),
//                            Time = 0,
//                            ExtraInfo = IntPtr.Zero
//                        }
//                }
            };

            keybdinput = new Win32Types.KEYBDINPUT {
                wVk         = 0,
                wScan       = scanCode,
                dwFlags     = Win32Constants.KeyboardEvent.KEYEVENTF_KEYUP | Win32Constants.KeyboardEvent.KEYEVENTF_UNICODE,
                time        = 0,
                dwExtraInfo = IntPtr.Zero
            };
            up.mkhi.ki = keybdinput;
            // Handle extended keys:
            // If the scan code is preceded by a prefix byte that has the value 0xE0 (224),
            // we need to include the KEYEVENTF_EXTENDEDKEY flag in the Flags property.
            if ((scanCode & 0xFF00) == 0xE000)
            {
                down.mkhi.ki.dwFlags |= Win32Constants.KeyboardEvent.KEYEVENTF_EXTENDEDKEY;
                up.mkhi.ki.dwFlags   |= Win32Constants.KeyboardEvent.KEYEVENTF_EXTENDEDKEY;
            }

            _inputList.Add(down);
            _inputList.Add(up);
            return(this);
        }
Example #3
0
        public InputBuilder AddKeyDown(Win32Constants.VirtualKeys keyCode)
        {
            var down = new Win32Types.INPUT {
                type = Win32Types.INPUTTYPE.INPUT_KEYBOARD,
            };
            var keybdinput = new Win32Types.KEYBDINPUT {
                wVk         = keyCode,
                wScan       = 0,
                dwFlags     = IsExtendedKey(keyCode) ? Win32Constants.KeyboardEvent.KEYEVENTF_EXTENDEDKEY : 0,
                time        = 0,
                dwExtraInfo = IntPtr.Zero
            };

            down.mkhi.ki = keybdinput;
            _inputList.Add(down);
            return(this);
        }