If you want to use an Xbox 360 Controller with your computer, you can use an Xbox 360 Controller for Windows. Or, you can use an Xbox 360 Wireless Controller together with an Xbox 360 Wireless Gaming Receiver for Windows.

XInputGetState function takes as parameters the index controller (they can be connected to more than one) as well as with the state of the structure where the return value of buttons:

1: {

2:

3: DWORD dwPacketNumber;

4:

5: XINPUT_GAMEPAD Gamepad;

6:

7: } XINPUT_STATE, *PXINPUT_STATE;

8:

9:

10: typedef struct _XINPUT_GAMEPAD

11:

12: {

13:

14: WORD wButtons;

15:

16: BYTE bLeftTrigger;

17:

18: BYTE bRightTrigger;

19:

20: SHORT sThumbLX;

21:

22: SHORT sThumbLY;

23:

24: SHORT sThumbRX;

25:

26: SHORT sThumbRY;

27:

28: } XINPUT_GAMEPAD, *PXINPUT_GAMEPAD;

Buttons coded bits:

1:#define XINPUT_GAMEPAD_DPAD_UP 0x0001

2:#define XINPUT_GAMEPAD_DPAD_DOWN 0x0002

3:#define XINPUT_GAMEPAD_DPAD_LEFT 0x0004

4:#define XINPUT_GAMEPAD_DPAD_RIGHT 0x0008

5:#define XINPUT_GAMEPAD_START 0x0010

6:#define XINPUT_GAMEPAD_BACK 0x0020

7:#define XINPUT_GAMEPAD_LEFT_THUMB 0x0040

8:#define XINPUT_GAMEPAD_RIGHT_THUMB 0x0080

9:#define XINPUT_GAMEPAD_LEFT_SHOULDER 0x0100

10:#define XINPUT_GAMEPAD_RIGHT_SHOULDER 0x0200

11:#define XINPUT_GAMEPAD_A 0x1000

12:#define XINPUT_GAMEPAD_B 0x2000

13:#define XINPUT_GAMEPAD_X 0x4000

14:#define XINPUT_GAMEPAD_Y 0x8000

Slightly more complicated is the values ​​of the hammers and two joysticks. The values ​​of X, Y, are within SHRT_MIN-SHRT_MAX (-32768 +32767), and for the hammers _UI8_MAX (255). Usually in games, these values ​​are normalized to -1.0 +1.0. Also for joystick should consider the so-called dead zone. Return values ​​axes at the neutral position can vary from zero, and to disregard them use the default values ​​of "dead zones", which should be computed by the following algorithm:

XInput game controller sample

This sample demonstrates the use of the XInput APIs in a C++ app.

In addition to the functions directly related to the status polling controller to XInput also includes management features vibrating motor and is connected accessory, such as a voice recorder with a headset or audio to the headset. Support also has a joystick for managed code in the library and XNA Monogame .

Get in touch?

So if your building a game or have built a game for Windows 8 with Controller support please get in touch as I would love to share your experience!