/// <summary> /// Send a mock of pressed keyboard combination. /// Use this method for sending copy/paste/cut commands. /// </summary> /// <param name="modifier">Key modifier.</param> /// <param name="key">The function key.</param> private void SendKey(Modifier modifier, System.Windows.Forms.Keys key) { Input[] inputs = new Input[4]; // Modifier key down Input structInput = new Input(); structInput.Type = INPUT_KEYBOARD; structInput.KeyboardInput.Scan = 0; structInput.KeyboardInput.Time = 0; structInput.KeyboardInput.Flags = 0; structInput.KeyboardInput.ExtraInfo = GetMessageExtraInfo(); structInput.KeyboardInput.KeyCode = (ushort)modifier; inputs[0] = structInput; // Function key down structInput = new Input(); structInput.Type = INPUT_KEYBOARD; structInput.KeyboardInput.Scan = 0; structInput.KeyboardInput.Time = 0; structInput.KeyboardInput.Flags = 0; structInput.KeyboardInput.ExtraInfo = GetMessageExtraInfo(); structInput.KeyboardInput.KeyCode = (ushort)key; inputs[1] = structInput; // Modifier key up structInput = new Input(); structInput.Type = INPUT_KEYBOARD; structInput.KeyboardInput.Scan = 0; structInput.KeyboardInput.Time = 0; structInput.KeyboardInput.Flags = KEYEVENTF_KEYUP; structInput.KeyboardInput.ExtraInfo = GetMessageExtraInfo(); structInput.KeyboardInput.KeyCode = (ushort)modifier; inputs[2] = structInput; // Function key up structInput = new Input(); structInput.Type = INPUT_KEYBOARD; structInput.KeyboardInput.Scan = 0; structInput.KeyboardInput.Time = 0; structInput.KeyboardInput.Flags = KEYEVENTF_KEYUP; structInput.KeyboardInput.ExtraInfo = GetMessageExtraInfo(); structInput.KeyboardInput.KeyCode = (ushort)key; inputs[3] = structInput; uint returnInt = SendInput(4, inputs, Marshal.SizeOf(structInput)); }
private static extern uint SendInput(uint nInputs, Input[] pInputs, int cbSize);