You could disable the keyboard from other applications with "xinput float" or "xinput --disable" or by disabling it in xorg.conf (turn auto add devices off and configure the devices you want)
Then you could write an application that reads events from the floating keyboard or from /dev/input/eventX and sends gamepad events to /dev/uinput.
New uinput device is created with an ioctl to /dev/uinput and events sent by writing uinput_user_dev structs to /dev/uinput. There is a python library for that: http://tjjr.fi/sw/python-uinput/
A quick proof of concept could be written by piping output of "xinput test-xi2 number" to a python-uinput program.