Hi all,
I've started to play around with a XBone controller using the XInput API.
So far I've managed to retrieve all buttons and sticks input without a problem.
The only thing I don't understand, is how the rumble function works.
I know how to enable it with XINPUT_VIBRATION and the motor speeds (0 to 65xxx).
But if I try to disable rumbling by setting the motor speeds to 0, the rumbling doesn't stop.
Do you have any idea what I'm doing wrong?
Below is the code of the simple test application.
Any input is appreciated.
while(!done) { XINPUT_STATE state; ZeroMemory(&state, sizeof(XINPUT_STATE)); dwResult = XInputGetState(controllerId, &state); if(dwResult != ERROR_SUCCESS) // controller NOT connected? { MessageBox(NULL, L"XBox controller error - state not retrieved", L"Whoops...", MB_ICONERROR); } // DIGITAL BUTTONS if(((state.Gamepad.wButtons & XINPUT_GAMEPAD_A) != 0)) MessageBox(NULL, L"A", L"XBone", MB_OK); // A button if(((state.Gamepad.wButtons & XINPUT_GAMEPAD_B) != 0)) MessageBox(NULL, L"B", L"XBone", MB_OK); // B button if(((state.Gamepad.wButtons & XINPUT_GAMEPAD_X) != 0)) // X button + RUMBLE { XINPUT_VIBRATION rumbler; rumbler.wLeftMotorSpeed = 25000; rumbler.wRightMotorSpeed = 25000; XInputSetState(controllerId, &rumbler); //MessageBox(NULL, L"X - rumble ON", L"XBone", MB_OK); } if(((state.Gamepad.wButtons & XINPUT_GAMEPAD_Y) != 0)) // Y button + RUMBLE OFF { XINPUT_VIBRATION rumblerOff; rumblerOff.wLeftMotorSpeed = 0; rumblerOff.wRightMotorSpeed = 0; XInputSetState(controllerId, &rumblerOff); //MessageBox(NULL, L"Y - rumble OFF", L"XBone", MB_OK); } // Escape if(GetAsyncKeyState(VkKeyScan(VK_ESCAPE)) & 0x8000) done = true; }
Another question, do I need to use XInputEnable(true/false) when my application goes in/ out of scope?
It doesn't seem to work with all XInput versions.
I'm currently including <xinput.h> and linking Xinput9_1_0.lib