Display joystick/controller events under Linux in the command line

Here are a few examples of how to display joysticks and controller data streams in the console under Linux, in my case Arch Linux.

First there is the possibility to query the raw data stream

$ cat /dev/input/js0

Or as a hex dump

$ cat /dev/input/js0 | hexdump

Which looks like so:

0000d40 4bcf 560b fb26 0402 4bd6 560b facd 0402
0000d50 4bd9 560b fb26 0402 4be0 560b faa1 0402
0000d60 4be3 560b fb26 0402 4bea 560b facd 0402

But there is also a more user-friendly way with the tool jstest. Under Arch Linux it is included in the package joyutils.

$ jstest /dev/input/js0

Example output:

Driver version is 2.1.0.
Joystick (Generic X-Box pad) has 8 axes (X, Y, Z, Rx, Ry, Rz, Hat0X, Hat0Y)
and 11 buttons (BtnA, BtnB, BtnX, BtnY, BtnTL, BtnTR, BtnSelect, BtnStart, BtnMode, BtnThumbL, BtnThumbR).
Testing ... (interrupt to exit)
Axes: 0: 0 1: 0 2:-32767 3: 0 4: -1066 5:-32767 6: 0 7: 0 Buttons: 0:off 1:off 2:off 3:off 4:off 5:off 6:off 7:off 8:off 9:off 10:off 

With the --event switch, a pure event stream can also be output.

$ jstest --event /dev/input/js0

Which looks like so:

Event: type 2, time 1443624759, number 4, value -1242
Event: type 2, time 1443624766, number 4, value -1331
Event: type 2, time 1443624772, number 4, value -1242