Skip to content

How to use the SendInput method correctly? #817

Answered by AArnott
vitkuz573 asked this question in Q&A
Discussion options

You must be logged in to vote

Ultimately I think your error is that you create a span of zero length, and then try to 'fill' it, but nothing will happen because it's empty.

-var inputs = new Span<INPUT>();
-inputs.Fill(input);
+var inputs = new Span<INPUT>(ref input);

But that relies on a new constructor for .NET 7. If you're not that lucky, this will also work:

Span<INPUT> inputs = stackalloc INPUT[1];
inputs[0] = input;

I would also touch up a bit of the other syntax, leaving me with:

var input = new INPUT
{
    type = INPUT_TYPE.INPUT_MOUSE,
    Anonymous =
    {
        mi = new MOUSEINPUT
        {
            dwFlags = MOUSE_EVENT_FLAGS.MOUSEEVENTF_WHEEL,
            dx = 0,
            dy = 0,
            time = 0

Replies: 1 comment 8 replies

Comment options

You must be logged in to vote
8 replies
@vitkuz573
Comment options

@Zintom
Comment options

@vitkuz573
Comment options

@AArnott
Comment options

@Zintom
Comment options

Answer selected by vitkuz573
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants