val val - 1 year ago 84
C Question

Lib(s)uinput: creating joystick with more than one button

I can't find information, how create joystick with several buttons on it using

. Example on

import uinput

def main():
events = (
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)

if __name__ == "__main__":

As you can see, in this example using
as button. And how create second button/addictional two

Note: I'm using
as example, application language is

Answer Source

More buttons — more button codes. Originally button codes are defined in the linux/input.h header from userspace perspective, or uapi/linux/input-event-codes.h from the kernel perspective. For python they are duplicated in the As you can see, there are a lot of them and you're mostly interested in things between BTN_JOYSTICK and BTN_THUMBR (but BTN_TRIGGER_HAPPY values are also used by some). The most interesting ones are BTN_THUMB, BTN_PINKIE, BTN_[ABC], BTN_SELECT and BTN_START.

As for additional axis, choose any between ABS_X and ABS_MISC. The most interesting additional ones are ABS_R[XYZ] and ABS_HAT0[XYZ].

So to use that additional buttons/axis you just use these identifiers in the same fashion you use BTN_JOYSTICK with ABS_X and ABS_Y.

Now, another interesting question probably is what values from this list are used by real joysticks that you're trying to emulate. This values can be obtained by using evtest or evemu programs (using real joystick, of course). Some widely available joysticks (Xbox and PS3) were also discussed here (as you can see, joysticks are very different in what button codes they produce). And to be really sure (or to emulate some device you can't check with evtest) you can also take a look at real joystick drivers (just BTN_ and ABS_ things they use).

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download