public static void SimulateKeyDown(VirtualKeyCode keyCode) { var down = new INPUT(); down.Type = (UInt32)InputType.KEYBOARD; down.Data.Keyboard = new KEYBDINPUT(); down.Data.Keyboard.Vk = (UInt16)keyCode; down.Data.Keyboard.Scan =0 down.Data.Keyboard.Flags = 0; down.Data.Keyboard.Time = 0; down.Data.Keyboard.ExtraInfo = IntPtr.Zero; INPUT[] inputList = new INPUT[1]; inputList[0] = down; var numberOfSuccessfulSimulatedInputs = SendInput(1, inputList, Marshal.SizeOf(typeof(INPUT))); if (numberOfSuccessfulSimulatedInputs == 0) throw new Exception(string.Format("The key down simulation for {0} was not successful.", keyCode)); }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)