pyglet.input

Joystick, tablet and USB HID device support.

This module provides a unified interface to almost any input device, besides the regular mouse and keyboard support provided by Window. At the lowest level, get_devices can be used to retrieve a list of all supported devices, including joysticks, tablets, space controllers, wheels, pedals, remote controls, keyboards and mice. The set of returned devices varies greatly depending on the operating system (and, of course, what’s plugged in).

At this level pyglet does not try to interpret what a particular device is, merely what controls it provides. A Control can be either a button, whose value is either True or False, or a relative or absolute-valued axis, whose value is a float. Sometimes the name of a control can be provided (for example, x, representing the horizontal axis of a joystick), but often not. In these cases the device API may still be useful – the user will have to be asked to press each button in turn or move each axis separately to identify them.

Higher-level interfaces are provided for joysticks, tablets and the Apple remote control. These devices can usually be identified by pyglet positively, and a base level of functionality for each one provided through a common interface.

To use an input device:

  1. Call get_devices, get_apple_remote or get_joysticks to retrieve and identify the device.
  2. For low-level devices (retrieved by get_devices), query the devices list of controls and determine which ones you are interested in. For high-level interfaces the set of controls is provided by the interface.
  3. Optionally attach event handlers to controls on the device.
  4. Call Device.open to begin receiving events on the device. You can begin querying the control values after this time; they will be updated asynchronously.
  5. Call Device.close when you are finished with the device (not needed if your application quits at this time).

To use a tablet, follow the procedure above using get_tablets, but note that no control list is available; instead, calling Tablet.open returns a TabletCanvas onto which you should set your event handlers.

Note

Since pyglet 1.2

Modules

evdev_constants Event constants from /usr/include/linux/input.h

Classes

AbsoluteAxis An axis whose value represents a physical measurement from the device.
AppleRemote High-level interface for Apple remote control.
Button A control whose value is boolean.
Control Single value input provided by a device.
Device Input device.
Joystick High-level interface for joystick-like devices.
RelativeAxis An axis whose value represents a relative change from the previous
Tablet High-level interface to tablet devices.

Functions

get_apple_remote([display]) Get the Apple remote control device.
get_devices([display]) Get a list of all attached input devices.
get_joysticks([display]) Get a list of attached joysticks.
get_tablets([display]) Get a list of tablets.

Notes

Defined

  • base
  • sys

Table Of Contents

Previous topic

dump_wintab Function

Next topic

pyglet.input.evdev_constants