Studying everything that is on uinput / suinput , I did not understand how to create several buttons on the joystick. In the python-uinput example (pseudo-code — the real code will be in C):

 import uinput def main(): events = ( uinput.BTN_JOYSTICK, uinput.ABS_X + (0, 255, 0, 0), uinput.ABS_Y + (0, 255, 0, 0), ) with uinput.Device(events) as device: for i in range(20): # syn=False to emit an "atomic" (5, 5) event. device.emit(uinput.ABS_X, 5, syn=False) device.emit(uinput.ABS_Y, 5) device.emit_click(uinput.BTN_JOYSTICK) if __name__ == "__main__": main() 

Ok, but I need to create some buttons / axes. And how to do it?

1 answer 1

(I duplicate my own answer from Stack English)

If you need additional buttons - it means that additional codes of buttons are needed. Button codes are initially defined by the linux/input.h for user space and uapi/linux/input-event-codes.h from the kernel side. For the python library, the codes are duplicated in ev.py As you can see, there are a lot of codes, in this case, of interest is everything between BTN_JOYSTICK and BTN_THUMBR (but sometimes the values ​​from the BTN_TRIGGER_HAPPY set are BTN_TRIGGER_HAPPY ). Top BTN_THUMB are BTN_THUMB , BTN_PINKIE , BTN_[ABC] , BTN_SELECT and BTN_START .

With the additional axes the same story, you can use anything from the list between ABS_X and ABS_MISC . The most popular of the additional - ABS_R[XYZ] and ABS_HAT0[XYZ] .

These identifiers are used in the same way as the BTN_JOYSTICK with ABS_X and ABS_Y , thus making additional buttons / axes.

What else might be interesting in this regard is what codes are used by real joysticks that we are trying to emulate. These codes can be obtained using the programs evtest or evemu (for this, of course, you need real joysticks). Some common joysticks (Xbox3 and PiEs3) were discussed (eng) here (as you can see, the codes used by the joysticks vary greatly depending on the model). Well, to find out for sure (or to emulate a joystick that is not physically accessible), you can look at the nuclear drivers for joysticks (especially what values ​​they use from BTN_ and ABS_ ).