Пример #1
0
        private bool SendVKeyNative64(int vKey, bool?obExtKey, char?optUnicodeChar,
                                      bool bDown)
        {
            NativeMethods.SpecializedKeyboardINPUT64[] pInput = new
                                                                NativeMethods.SpecializedKeyboardINPUT64[1];

            pInput[0].Type = NativeMethods.INPUT_KEYBOARD;

            if (optUnicodeChar.HasValue && WinUtil.IsAtLeastWindows2000)
            {
                pInput[0].VirtualKeyCode = 0;
                pInput[0].ScanCode       = (ushort)optUnicodeChar.Value;
                pInput[0].Flags          = ((bDown ? 0 : NativeMethods.KEYEVENTF_KEYUP) |
                                            NativeMethods.KEYEVENTF_UNICODE);
            }
            else
            {
                IntPtr hKL = m_swiCurrent.KeyboardLayout;

                if (optUnicodeChar.HasValue)
                {
                    vKey = (int)(NativeMethods.VkKeyScan3(optUnicodeChar.Value,
                                                          hKL) & 0xFFU);
                }

                pInput[0].VirtualKeyCode = (ushort)vKey;
                pInput[0].ScanCode       = (ushort)(NativeMethods.MapVirtualKey3(
                                                        (uint)vKey, NativeMethods.MAPVK_VK_TO_VSC, hKL) & 0xFFU);
                pInput[0].Flags = GetKeyEventFlags(vKey, obExtKey, bDown);
            }

            pInput[0].Time      = 0;
            pInput[0].ExtraInfo = NativeMethods.GetMessageExtraInfo();

            Debug.Assert(Marshal.SizeOf(typeof(NativeMethods.SpecializedKeyboardINPUT64)) == 40);
            if (NativeMethods.SendInput64Special(1, pInput,
                                                 Marshal.SizeOf(typeof(NativeMethods.SpecializedKeyboardINPUT64))) != 1)
            {
                return(false);
            }

            return(true);
        }
Пример #2
0
        private static bool SendVKeyNative64(int vKey, char?optUnicodeChar, bool bDown)
        {
            NativeMethods.SpecializedKeyboardINPUT64[] pInput = new
                                                                NativeMethods.SpecializedKeyboardINPUT64[1];

            pInput[0].Type = NativeMethods.INPUT_KEYBOARD;

            if (optUnicodeChar.HasValue && WinUtil.IsAtLeastWindows2000)
            {
                pInput[0].VirtualKeyCode = 0;
                pInput[0].ScanCode       = (ushort)optUnicodeChar.Value;
                pInput[0].Flags          = ((bDown ? 0 : NativeMethods.KEYEVENTF_KEYUP) |
                                            NativeMethods.KEYEVENTF_UNICODE);
            }
            else             // Standard VKey
            {
                if (optUnicodeChar.HasValue)
                {
                    vKey = (int)(NativeMethods.VkKeyScan(optUnicodeChar.Value) & 0xFF);
                }

                pInput[0].VirtualKeyCode = (ushort)vKey;
                pInput[0].ScanCode       = (ushort)(NativeMethods.MapVirtualKey(
                                                        (uint)vKey, 0) & 0xFF);
                pInput[0].Flags = ((bDown ? 0 : NativeMethods.KEYEVENTF_KEYUP) |
                                   (IsExtendedKeyEx(vKey) ? NativeMethods.KEYEVENTF_EXTENDEDKEY : 0));
            }

            pInput[0].Time      = 0;
            pInput[0].ExtraInfo = NativeMethods.GetMessageExtraInfo();

            Debug.Assert(Marshal.SizeOf(typeof(NativeMethods.SpecializedKeyboardINPUT64)) == 40);
            if (NativeMethods.SendInput64Special(1, pInput,
                                                 Marshal.SizeOf(typeof(NativeMethods.SpecializedKeyboardINPUT64))) != 1)
            {
                return(false);
            }

            return(true);
        }
Пример #3
0
        private static bool SendModifierVKey64Unchecked(int vKey, bool bDown)
        {
            NativeMethods.SpecializedKeyboardINPUT64[] pInput = new
                                                                NativeMethods.SpecializedKeyboardINPUT64[1];

            pInput[0].Type           = NativeMethods.INPUT_KEYBOARD;
            pInput[0].VirtualKeyCode = (ushort)vKey;
            pInput[0].ScanCode       = (ushort)(NativeMethods.MapVirtualKey(
                                                    (uint)vKey, 0) & 0xFF);
            pInput[0].Flags = ((bDown ? 0 : NativeMethods.KEYEVENTF_KEYUP) |
                               (IsExtendedKeyEx(vKey) ? NativeMethods.KEYEVENTF_EXTENDEDKEY : 0));
            pInput[0].Time      = 0;
            pInput[0].ExtraInfo = NativeMethods.GetMessageExtraInfo();

            Debug.Assert(Marshal.SizeOf(typeof(NativeMethods.SpecializedKeyboardINPUT64)) == 40);
            if (NativeMethods.SendInput64Special(1, pInput,
                                                 Marshal.SizeOf(typeof(NativeMethods.SpecializedKeyboardINPUT64))) != 1)
            {
                return(false);
            }

            return(true);
        }