private void SendKey(char chr, bool key_up) { Input[] input = new Input[1]; input[0].type = INPUT.KEYBOARD; input[0].ki.wVk = KeyboardConstaint.VK_NONE; input[0].ki.wScan = (short) chr; input[0].ki.time = NativeMethods.GetTickCount(); input[0].ki.dwFlags = KeyboardConstaint.KEYEVENTF_UNICODE; if (key_up) { input[0].ki.dwFlags += KeyboardConstaint.KEYEVENTF_KEYUP; } uint res = NativeMethods.SendInput((uint)input.Length, input, Marshal.SizeOf(input[0])); if (res < input.Length) { throw new Win32Exception(Marshal.GetLastWin32Error()); } }
internal static extern UInt32 SendInput(UInt32 nInputs, Input[] pInputs, Int32 cbSize);