/// <summary> /// Scroll the horizontal mouse wheel by the specified amount. /// </summary> public void AddMouseHorizontalWheelScroll(int scrollAmount) { var scroll = new INPUT { Type = InputType.Mouse }; scroll.Data.Mouse.Flags = MouseFlag.HorizontalWheel; scroll.Data.Mouse.MouseData = (uint)scrollAmount; _inputList.Add(scroll); }
/// <summary> /// Adds a mouse button up for the specified button. /// </summary> public void AddMouseButtonUp(MouseButton button) { var buttonUp = new INPUT { Type = (uint)InputType.Mouse }; MouseFlag flg; switch (button) { case MouseButton.MiddleButton: flg = MouseFlag.MiddleUp; break; case MouseButton.RightButton: flg = MouseFlag.RightUp; break; default: flg = MouseFlag.LeftUp; break; } buttonUp.Data.Mouse.Flags = flg; _inputList.Add(buttonUp); }
/// <summary> /// Adds a mouse button up for the specified button. /// </summary> public void AddMouseXButtonUp(int xButtonId) { var buttonUp = new INPUT { Type = InputType.Mouse }; buttonUp.Data.Mouse.Flags = MouseFlag.XUp; buttonUp.Data.Mouse.MouseData = (uint)xButtonId; _inputList.Add(buttonUp); }
/// <summary> /// Adds a mouse button down for the specified button. /// </summary> public void AddMouseButtonDown(MouseButton button) { var buttonDown = new INPUT { Type = InputType.Mouse }; MouseFlag flg; switch (button) { case MouseButton.MiddleButton: flg = MouseFlag.MiddleDown; break; case MouseButton.RightButton: flg = MouseFlag.RightDown; break; default: flg = MouseFlag.LeftDown; break; } buttonDown.Data.Mouse.Flags = flg; _inputList.Add(buttonDown); }
/// <summary> /// Adds a mouse button down for the specified button. /// </summary> public void AddMouseXButtonDown(int xButtonId) { var buttonDown = new INPUT { Type = InputType.Mouse }; buttonDown.Data.Mouse.Flags = MouseFlag.XDown; buttonDown.Data.Mouse.MouseData = (uint)xButtonId; _inputList.Add(buttonDown); }
/// <summary> /// Move the mouse to the absolute position on the virtual desktop. /// </summary> public void AddAbsoluteMouseMovementOnVirtualDesktop(int absoluteX, int absoluteY) { var movement = new INPUT { Type = InputType.Mouse }; movement.Data.Mouse.Flags = MouseFlag.Move | MouseFlag.Absolute | MouseFlag.VirtualDesk; movement.Data.Mouse.X = absoluteX; movement.Data.Mouse.Y = absoluteY; _inputList.Add(movement); }
/// <summary> /// Moves the mouse relative to its current position. /// </summary> public void AddRelativeMouseMovement(int x, int y) { var movement = new INPUT { Type = InputType.Mouse }; movement.Data.Mouse.Flags = MouseFlag.Move; movement.Data.Mouse.X = x; movement.Data.Mouse.Y = y; _inputList.Add(movement); }
/// <summary> /// Adds the character to the list of <see cref="INPUT"/> messages. /// </summary> /// <param name="character">The <see cref="System.Char"/> to be added to the list of <see cref="INPUT"/> messages.</param> public void AddCharacter(char character) { ushort scanCode = character; var down = new INPUT { Type = InputType.Keyboard, Data = { Keyboard = new KeyboardInput { KeyCode = 0, Scan = scanCode, Flags = KeyboardFlag.Unicode, Time = 0, ExtraInfo = IntPtr.Zero } } }; var up = new INPUT { Type = InputType.Keyboard, Data = { Keyboard = new KeyboardInput { KeyCode = 0, Scan = scanCode, Flags = KeyboardFlag.KeyUp | KeyboardFlag.Unicode, Time = 0, ExtraInfo = IntPtr.Zero } } }; // Handle extended keys: // If the scan code is preceded by a prefix byte that has the value 0xE0 (224), // we need to include the KEYEVENTF_EXTENDEDKEY flag in the Flags property. if ((scanCode & 0xFF00) == 0xE000) { down.Data.Keyboard.Flags |= KeyboardFlag.ExtendedKey; up.Data.Keyboard.Flags |= KeyboardFlag.ExtendedKey; } _inputList.Add(down); _inputList.Add(up); }
/// <summary> /// Adds a key up to the list of <see cref="INPUT"/> messages. /// </summary> /// <param name="keyCode">The <see cref="KeyCode"/>.</param> public void AddKeyUp(KeyCode keyCode) { var up = new INPUT { Type = InputType.Keyboard, Data = { Keyboard = new KeyboardInput { KeyCode = (ushort)keyCode, Scan = 0, Flags = IsExtendedKey(keyCode) ? KeyboardFlag.KeyUp | KeyboardFlag.ExtendedKey : KeyboardFlag.KeyUp, Time = 0, ExtraInfo = IntPtr.Zero } } }; _inputList.Add(up); }
public static extern uint SendInput(uint numberOfInputs, INPUT[] inputs, int sizeOfInputStructure);