2

I'm trying to spoof a PS3 controller and send analog stick directional input to a specific program, but i can't figure out how the INPUT.hi struct works. I can send keypresses over with

INPUT keys;
keys.type = INPUT_KEYBOARD;
keys.ki.dwFlags = KEYEVENTF_SCANCODE;
keys.ki.wScan = 0x11;//hex for 'w' key
SendInput(1, &keys, sizeof(INPUT));
Sleep(60);//delay to ensure game doesnt drop keypress
keys.ki.dwFlags = KEYEVENTF_SCANCODE | KEYEVENTF_KEYUP;
SendInput(1, &keys, sizeof(INPUT));

and i believe that sending over joystick commands would work similarly, something like

INPUT analogSticks;
analogSticks.type = INPUT_HARDWARE;
analogSticks.hi.uMsg = WM_INPUT;
analogSticks.hi.wParamL = //what are the values for these?
analogSticks.hi.wParamH = //what are the values for these?
SendInput(1, &analogSticks, sizeof(INPUT));

but trying out different values for wParamL and wParamH doesnt do anything. Am i doing something wrong, and/or is there a way i can input specific angles, say, if i were to put in 45, i could generate a joystick signal that would correspond to that angle, much like i can do with keypresses?

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
frankcrisanti
  • 41
  • 1
  • 6
  • The values of `wParamL` and `wParamH` combine to form the `wParam` for the specified `uMsg`. Unfortunately, for `WM_INPUT`, this is either `RIM_INPUT` or `RIM_INPUTSINK`, with the actual input data sent in `lParam` instead. I have a feeling that either a) `WM_INPUT` isn't the correct message for `SendInput()`, or b) worse, that you won't be able to spoof a PS3 controller with `SendInput()`. Unfortunately, I don't know for sure; I'm only basing this off MSDN and I have no expertise here, sorry. Good luck. – andlabs Feb 22 '15 at 21:31

1 Answers1

2

It looks like i cant do this with the winapi, but the joystick driver vJoy vjoystick.sourceforge.net/ works perfectly, and their sdk http://vjoystick.sourceforge.net/site/index.php/dev/87-writing-a-feeder-application2 clearly explains how to spoof joystick input.

Another option is http://developer.mbed.org/users/wim/notebook/usb-joystick-device/, which appears to work similarly.

frankcrisanti
  • 41
  • 1
  • 6