Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


SendInput problem

This topic is 5294 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I''m trying to use SendInput in C# and I''m having trouble declaring everything. According the MSDN this is the syntax: UINT SendInput(UINT nInputs, LPINPUT pInputs, int cbSize ); pInputs is a pointer to an array of INPUT structures. The structure for INPUT is: typedef struct tagINPUT { DWORD type; union {MOUSEINPUT mi; KEYBOARDINPUT ki; HARDWAREINPUT hi; }; }INPUT, *PINPUT; I am only interested in KEYBOARDINPUT at this time so the others can be ignored. I''m having trouble converting these structs to c# (because of the union). Here is my code. public struct KEYBDINPUT { int wVk; int wScan; long dwFlags; long time; long dwExtraInfo; } public struct INPUT { [ FieldOffset(0) ] public int mi; [ FieldOffset(0) ] public int ki; [ FieldOffset(0) ] public int hi; } Now, I''d like use the array input[] to setup the pInputs portion of SendInput. I''d like to use this: input[1].ki.wVk = input[2].ki.wVk = 0x60; //num0 How would i change the structures so that the struct INPUT can use the contents of the KEYBDINPUT struct? I''m not sure if this makes sense. If you dont understand what I mean I can elaborate more.

Share this post

Link to post
Share on other sites
Ok, I think I've almost figured it out. Here is what I have so far.

public struct Input
//public uint type;
public int wVk;
public int wScan;
public int dwFlags;
public int time;
public uint dwExtra;

public static extern uint SendInput(uint nInputs, Input[] inputs,
int cbSize );

private void button1_Click(object sender, System.EventArgs e)
Input[] inputs = new Input[10];

//inputs[0].type = INPUT_KEYBOARD;
inputs[0].wVk = Win32.VK_SPACE;
inputs[0].wScan = 0x39;
//inputs[0].dwFlags = 0;
inputs[0].time = 0;
inputs[0].dwExtra = 0;

//inputs[1].type = INPUT_KEYBOARD;
inputs[1].wVk = Win32.VK_SPACE;
inputs[1].wScan = 0x39;
inputs[1].dwFlags = Win32.KEYEVENTF_KEYUP;
inputs[1].time = 0;
inputs[1].dwExtra = 0;

uint result = Win32.SendInput((uint)inputs.Length, inputs, 20);

20 is the size of the input structure.

I removed the KEYBDINPUT structure and put that into the INPUT structure since I dont need HARDWAREINPUT or MOUSEINPUT. When I run my program I get this error:

The parameter is incorrect. ERROR_INVALID_PARAMETER .

Anyone know whats wrong with this?


[edited by - Zomba on February 20, 2004 11:04:40 PM]

Share this post

Link to post
Share on other sites
Guest Anonymous Poster
i''m having the same problem, trying to move the mouse to a position outside the application. i''ll let you know if i figure it out, good luck

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!