private void SendKey(int key, bool isDown) { var input = new INPUT(); input.Type = (UInt32)InputType.KEYBOARD; input.Data.Keyboard = new KEYBDINPUT(); input.Data.Keyboard.Vk = (UInt16)key; input.Data.Keyboard.Scan = 0; input.Data.Keyboard.Flags = (isDown) ? 0 : (UInt32)KeyboardFlag.KEYUP; input.Data.Keyboard.Time = 0; input.Data.Keyboard.ExtraInfo = IntPtr.Zero; INPUT[] inputList = new INPUT[1]; inputList[0] = input; SentKey sent = new SentKey(key, isDown); this.sentKeys.Add(sent); uint numberOfSuccessfulSimulatedInputs = SendInput(1, inputList, Marshal.SizeOf(typeof(INPUT))); if (numberOfSuccessfulSimulatedInputs == 0) { KeyControl.TraceLine(string.Format("Failed to send key {0}", key)); this.sentKeys.Remove(sent); } }
private bool IsSentKey(int key, bool isKeyDown) { SentKey sent = new SentKey(key, isKeyDown); if (this.sentKeys.Contains(sent)) { this.sentKeys.Remove(sent); return(true); } return(false); }