Xbox360 controller C integration

The following implementation is a simple example code to integrate an Xbox360 controller into a C-based program. It reads the values of the controller axis and the buttons and displays them on the screen. The following picture shows the output of the code:

In this case, the buttons „A“ and „TL“, which is the top-left button, were pressed. The project is called xboxControllerClient can be downloaded from my repository at

The whole configuration is in the header file xboxController.h. There the mapping of the buttons and the axis is implemented. The data will be stored in a struct called xboxCtrl. It is also is in the header file. The following example shows how to use the code:

#include "xboxController.h"

int main(int argc, char **argv) {

 if (initXboxContoller(XBOX_DEVICE) >= 0) {
  xboxCtrl* xbox = getXboxDataStruct();

  printf("xbox controller detected axis:\t\t%d\nbuttons:\t%d\nidentifier:\t%s\n",
    xbox->numOfAxis, xbox->numOfButtons, xbox->identifier);

  while (1) {

 return 0;

The method initXboxContoller(XBOX_DEVICE) opens a connection to the device /dev/input/js0. This device is set as the default device. To change this, change the value of XBOX_DEVICE. Next, the method getXboxDataStruct() returns a pointer to the data stuct xboxCtrl. In this struct, all information is stored. You can update the information with a periodic call of readXboxData(xbox). To print the state of the Xbox controller, you should call printXboxCtrlValues(xbox).