July 25th, 2013, 08:56 AM
using SendInput to control mouse for games
Hello, I am making a program to map keys and mouse input to 360 controller using XInput I have the keys working fine with SendInput my problem comes from when I try to control the mouse pointer with the analog stick heres the code I was using for down direction on the left thumbstick this code is inside the message loop.
the other directions generally follow the same idea.
if(controller1->GetState().Gamepad.sThumbRX > XINPUT_GAMEPAD_RIGHT_THUMB_DEADZONE)
mouseposition.x += controller1->GetState().Gamepad.sThumbRX/10000;
ip.type = INPUT_MOUSE;
ip.mi.dwExtraInfo = GetMessageExtraInfo();
ip.mi.mouseData = 0;
ip.mi.time = 0;
ip.mi.dx = mouseposition.x *(65536/screen_x);
ip.mi.dy = mouseposition.y *(65536/screen_y);
ip.mi.dwFlags = MOUSEEVENTF_MOVE | MOUSEEVENTF_ABSOLUTE;
it works fine outside of the stalker game im testing it with "not the best speed though" but in the game
if I move the thumbstick I get weird results. Example: Holding the thumbstickin the right direction and rotating on the game makes the movement stutter.
I have looked all over for an answer to why this happens but I cant find any examples of XInput with SendInput for controlling games.
Whats the problem and is there a better way than using SendInput?
July 26th, 2013, 07:43 AM
Re: using SendInput to control mouse for games
there is only one "generic" way to generate mouse/keyboard input and that's SendInput (or their now obsolete lower level counterparts).
SendInput essentially does little else than "sit between" your computer and the mouse/keyboard and stuffs the input queue with mouse moves/buttonclicks/keyclicks in the same way as the mouse/keyboard generate them.
In fact, a program can't typically distinguish between the two (altough you can figure it out if you wanted to).
However, that doesn't mean applications have no other means to get in put. Some of the DirectX input features don't work with the "input queue" but rather directly talk to the hardware. If the game you're talking about uses this method, then SendInput may only partially work. To control via these methods, would essentially mean you create a virtual driver where your application decides what the "inputdevice" is doing.
Also... A mouse is not an analog device, it has digital relative movement. If you're trying to use a game controller then the success at making that work will depend on how successfull you can make that controller "appear to behave like a mouse" as well as how the game reacts to movement
Trying to make A game designed for a mouse, work with somethign other than a mouse. doesn't always work well. it may be awkward, and even take some getting used to the concept. Even games that have been directly ported from consoles (with a controller) and are recoded to work with a keyboard/mouse don't always "feel right" when you play them.
Tags for this Thread
Click Here to Expand Forum to Full Width
This is a CodeGuru survey question.