Treat USB Keyboard as Gamepad

5

3

I have a second USB keyboard I'd like my computer to recognize as a gamepad rather than just an extra keyboard. Is this possible on Ubuntu 14.04?

I've seen information on doing the opposite, treating a gamepad as a keyboard, but this is not what I'm looking for.

Ian Hunter

Posted 2014-11-08T04:50:45.697

Reputation: 196

Answers

3

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.

Mikko Tuumanen

Posted 2014-11-08T04:50:45.697

Reputation: 46

An alternative to disabling the keyboard with xinput is to to "grab" the /dev/input/eventX device. See evtest --grab for a command-line program that does it. – dirkt – 2017-03-31T16:36:00.297

I have since purchased some gamepads, and I'm not about to go dig up an old keyboard to try this, but I'm accepting it anyway because I like it. – Ian Hunter – 2017-04-01T14:42:27.130

is there a GUI app available ? I need something that is an alternative to vjoy in windows – Subin – 2018-07-28T18:25:16.127