Example #1
0
        private void SendKeyUp(short key)
        {
            if (Marshal.SizeOf(new IntPtr()) == 8)//64位系统
            {
                Input64[] input = new Input64[1];
                input[0].type = INPUT.KEYBOARD;
                input[0].ki.wVk = key;
                input[0].ki.dwFlags = KeyboardConstaint.KEYEVENTF_KEYUP;
                input[0].ki.time = NativeMethods.GetTickCount();

                if (NativeMethods.SendInput64((uint)input.Length, input, Marshal.SizeOf(input[0])) < input.Length)
                {
                    throw new Win32Exception(Marshal.GetLastWin32Error());
                }
            }
            else
            {
                Input32[] input = new Input32[1];
                input[0].type = INPUT.KEYBOARD;
                input[0].ki.wVk = key;
                input[0].ki.dwFlags = KeyboardConstaint.KEYEVENTF_KEYUP;
                input[0].ki.time = NativeMethods.GetTickCount();

                if (NativeMethods.SendInput((uint)input.Length, input, Marshal.SizeOf(input[0])) < input.Length)
                {
                    throw new Win32Exception(Marshal.GetLastWin32Error());
                }
            }
        }
Example #2
0
 internal static extern UInt32 SendInput64(UInt32 nInputs, Input64[] pInputs, Int32 cbSize);