The temporary brute force solution is to just rename/delete the device files, i.e.:
mv /dev/input/js1 /dev/input/js0
Note however most modern games do not use the
/dev/input/js0 interface at all, so you will need to take care of the
/dev/input/eventX files as well. You can use
evtest to find out which device is your keyboard and joystick. On the next reboot the devices will be back in their old order.
Another slightly less brute force method is via the environment variable:
This forces SDL based games to use js1 instead of js0. I don't think this will work with modern SDL2 based games and it will only work for a single joystick/gamepad, so it's of limited use.
SDL2 does provide an option to configure a joystick and remap buttons, but I don't think it has a facility to reorder devices at the moment.
And finally there is also the "clean" method by writing an udev rule, this will essentially do the same as the
mv hack, but permanently. These rules go to
/etc/udev/rules.d/ and tutorials for writing them can be found scattered around the net, maybe this will help, not sure if it's up to date: