Exemplo n.º 1
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;
        }
Exemplo n.º 2
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;
		}