Hi everyone! I have worked hard for getting this to work, but finally figured this out! here is code to add in your agk code to have XBOX controller interaction. here is code to add in your template.h:
#include <Xinput.h>
#pragma comment(lib, "XInput.lib")
//inside the app class
public:
void XBOX(int);
XINPUT_STATE GetState();
bool IsConnected();
void Vibrate(left leftVal = 0, int rightVal = 0);
int getXboxButton();
private:
XINPUT_STATE _controllerState;
int _controllerNum;
now functions to add in your template.cpp:
void app::XBOX(int PlayerNumber)
{
_controllerNum = PlayerNumber - 1;
}
XINPUT_STATE app::GetState()
{
ZeroMemory(& _controllerState, sizeof(XINPUT_STATE));
XInputGetState(_controllerNum, &-controllerState);
return _controllerState;
}
bool app::IsConnected()
{
ZeroMemory(& _controllerState, sizeof(XINPUT_STATE));
DWORD result = XInputGetState(_controllerNum, &_controllerState);
if(result == ERROR_SUCCESS)
{
return true;
}else{
return false;
}
}
void app::Vibrate(int leftVal, int rightVal)
{
XINPUT_VIBRATION vibration;
ZeroMemory(&vibration, sizeof(XINPUT_VIBRATION));
vibration.wLeftMotorSpeed = leftVal;
vibration.wRightMotorSpeed = rightVal;
XInputSetState(_controllerNum,&vibration);
}
int app::getXboxButton()
{
if(IsCOnnected())
{
if(GetState().Gamepad.wButtons & XINPUT_GAMEPAD_A)
{
return 1;
}
}
}
the other buttons for the xbox controller are also Y,B and X in replacement of the A in XINPUT_GAMEPAD_. You can also access the joysticks by doing the GETState().Gamepad.sThumbLX/sThumbLY/sThumbRX/sThumbRY. I hope this small tutorial helped!
edit: here is a link for all of the buttons:
http://msdn.microsoft.com/en-us/library/windows/desktop/microsoft.directx_sdk.reference.xinput_gamepad(v=vs.85).aspx
hello there!