Input Handling
From FreeGameDevWiki
Some general notes about how input devices are handled in Linux. Extension on how it is different on other OSs are welcome.
Contents |
Joystick Interface - /dev/input/js0
The joydev interface is directly provided by the kernel and available via the device node /dev/input/jsX. The joystick interface is build on top of evdev, not the joystick driver itself.
- provides axes, normalized to a range of -32767-32767
- provides buttons
- provides the joystick name
- allows the remapping of buttons and axis
- allows calibration and axis inversion
- additional informations on the axis and buttons can be derived from the buttonmap and axismap
- can cause trouble with hotplugging, as the device names might end up not starting at 0 (i.e. plug in two joysticks, then remove the one on js0)
Tools: jstest, jstest-gtk, jscal, jscalibrator
Files: /usr/include/linux/input.h
Mouse Interface - /dev/input/mouse0
- /dev/input/mice provides events from all devices combined
- talks PS/2 protocol
Evdev Interface
The evdev interface is a generic interface for all input devices. In addition to input, it is also responsible for some forms of output, such as Force Feedback or LED control.
- provides three input event types:
- ABS - absolute position events (graphic tablet, joystick axis)
- REL - relative position events (mouse)
- KEY - provides button press events (mouse, joystick, keyboard)
- does not provide calibration or remapping
- gives raw non-normalized data
- provides detailed information on axis and buttons
Tools: evdev, fftest
Files: /usr/include/linux/input.h
Libusb
Libusb gives raw access to the USB bus and can be used to write userspace drivers such as [xboxdrv http://pingus.seul.org/~grumbel/xboxdrv/].
uinput
The uinput interface allows the creation of virtual input devices from userspace. It is used by userspace drivers such as [xboxdrv http://pingus.seul.org/~grumbel/xboxdrv/] or CWiid.
Wiimote
The Wiimote can be accessed either directly via bluetooth or via a wrapper library such as libcwiid.
Xorg
- does not provide proper relative motion events, needs hacks to simulate them
- the mouse wheel is handled as button 4 and 5
xinput (Xorg)
Xinput manages input events in Xorg, while it is possible to use it in games, it is much more common in normal applications, such as when using a graphic tablet in Gimp.
- makes use of the /dev/input/event interface
- recent versions supports hotplugging and auto configuration
- provides relative events (could be useful for mouse control in a FPS)
- allows button remapping (xinput set-button-map "ImExPS/2 Logitech Explorer Mouse" 1 2 3)
- gives information on axis range
- seems to have joystick support, but that doesn't seem to be used by anything
Tools: xinput
The Xorg xinput system should not be confused with Microsofts, DirectX successor, XInput. Both are completly unrelated.
SDL
SDL wrappers the OS specific input functions into portable ones.
- input is separated into:
- keyboard events
- joystick button events
- joystick axis events (normalized to -32768, 32767)
- joystick hat events
- joystick ball events
- does not provide information on the axis (i.e. if its a throttle or not)
- mouse motion and button press events
- depending on compile time options it will use either evdev or joydev
- when using joydev, customization is possible via environment variables such as SDL_LINUX_JOYSTICK
- unlike joydev hats are separate and not handled as axis (troublesome with gamepads, as the dpad won't function in games that aren't prepared for it)
- will provide support for multiple mice in 1.3
Tools: sdl-jstest
