Classes
class device(display, name)
Bases: object
Input device.
Variables:-
- display (pyglet.canvas.Display) — The display this device is linked to.
- name (str) – The device's name, as defined by the firmware.
- manufacturer (str) – The device's manufacturer, or none if the information isn't accessible.
class Control(name, raw_name=None)
Bases: pyglet.event.EventDispatcher
A device provides single value input. When the device is open, the control value can be accessed. When the value changes, event handlers may be linked to the control and invoked. The device's min and max attributes are presented; the control's value may be outside this range in some situations.
Variables:
- name (str) – The control's name, or None if unknown
- raw_name (str) – The control's unmodified name, as supplied by the operating system; or None if unknown
- inverted (bool) - If True, the value reported is reversed from what the device reported; this is typically done to provide uniformity between operating systems.
class RelativeAxis(name, raw_name=None)
Bases: pyglet.input.base.Control
class AbsoluteAxis(name, min, max, raw_name=None)
Bases: pyglet.input.base.Control
The value of this axis reflects a change in the initial value and indicates a physical measurement taken by the instrument. The advertised range is between min and max.
Variables:
- min (float) — Advertised minimum value.
- max (float) – Maximum value advertised.
class Button(name, raw_name=None)
Bases: pyglet.input.base.Control
A control with a boolean value.
class Joystick(device)
Bases: pyglet.event.EventDispatcher
Joystick-like devices have a high-level interface. Joysticks, gamepads, gaming controllers, and maybe even steering wheels and other input devices fall within this category. Unfortunately, there is no method to discriminate between these various device kinds.
To utilize a joystick, first call open, then inspect the values of x, y, and so on in your game loop. These numbers have been scaled to [-1.0, 1.0].
Attach a joy axis motion event handler to the joystick to receive events when the value of an axis changes. This event gets the Joystick instance, axis name, and current value as arguments.
Variables:
- device (Device) — This joystick interface's underlying device.
- x (float) – The current X (horizontal) value, which ranges from -1.0 (left) to 1.0 (right) (right).
- y (float) – The current y (vertical) value, which ranges from -1.0 (top) to 1.0 (bottom) (bottom).
- z (float) — The current Z value can be anywhere between -1.0 and 1.0. The throttle control is commonly the Z value on joysticks. The Z value is commonly the secondary thumb vertical axis on gaming controllers.
- rx (float) – The current rotational X value can be anywhere between -1.0 and 1.0.
- ry (float) — The current rotational Y value can be anywhere between -1.0 and 1.0.
- rz (float) — The current rotational Z value can be anywhere between -1.0 and 1.0. The RZ number on joysticks is generally the twist of the stick. The RZ value is commonly the secondary thumb horizontal axis on gaming controllers.
- hat_x (int) – Current horizontal hat (POV) position; one of -1 (left), 0 (centre), or 1 (right) (right).
- hat_y (int) – Vertical position of the current hat (POV); one of -1 (bottom), 0 (centre), or 1 (top) (top).
- buttons (bool) — A list of boolean values that indicate the current state of the buttons. These are arranged in ascending order. Thus button 1 has a value at buttons[0], and so on.
- x_control (AbsoluteAxis) – The underlying control for the x value, or None if none exists.
- y_control (AbsoluteAxis) – The underlying control for the y value, or None if none exists.
- z_control (AbsoluteAxis) – Z value's underlying control, or None if none is supplied.
- rx_control (AbsoluteAxis) – Rx value's underlying control, or None if none is provided.
- ry_control (AbsoluteAxis) – The underlying control for the ry value, or None if none exists.
- rz_control (AbsoluteAxis) – The underlying control for the rz value, or None if none exists.
- hat_x_control (AbsoluteAxis) – The underlying control for the hat x value, or None if none exists.
- hat_y_control (AbsoluteAxis) – The underlying control for the hat y value, or None if none exists.
-
button_controls (list of the button) – Button values' underlying controls.
class AppleRemote(device)
Bases: pyglet.event.EventDispatcher
It provides Apple remote control interface at a high level. This interface gives you access to the remote's six buttons. Certain buttons on the remote are treated as a distinct control when pressed and held.
Variables:
- This interface's underlying device is called device (Device).
- left_control (Button) – Button control for the left (prev) button.
- left_hold_control (Button) – Button control for holding the left button (rewind).
- right_control (Button) — Right (next) button button control.
- right_hold_control (Button) – Controls the right button when it is pressed (fast forward).
- up_control (Button) — The control of the up (volume increase) button.
- down_control (Button) - Down (volume drop) button button control.
- select_control (Button) — Select (play/pause) button button control.
- select_hold_control (Button) – Button control for holding the select button.
- menu_control (Button) — The menu button's button control.
- menu_hold_control (Button) – Hold the menu button using this button control.
class Tablet
It provides a tablet device interface at a high level. Tablets, unlike other gadgets, must be opened for a particular window and cannot be used only for that purpose. The open function returns a TabletCanvas object that supports all the tablet's events.
Currently, only one tablet device may be utilized; however, many windows can be opened. The behavior is unknown when more than one tablet is connected.
Functions
get_apple_remote(display=None)
Get yourself an Apple remote control.
The Apple remote is a compact white 6-button remote control that comes standard with most new Apple computers and laptops. Only Mac OS X may be used with the remote.
get_devices(display=None)
Get a list of all input devices that are connected.
get_joysticks(display=None)
Get a list of joysticks that are connected.
get_tablets(display=None)
Obtain a list of tablet computers.
Even if no tablet device is attached, this function may return a simple tablet device (for example, it is not possible on Mac OS X to determine if a tablet device is connected). Even though pyglet returns a list of tablets, it does not yet support multiple tablets, and if more than one is attached, the behavior is unknown.
Exceptions
- class DeviceException
- class DeviceOpenException
- class DeviceExclusiveException
Frequently Asked Questions
How many exception classes are present in pyglet.input?
There are three exceptions present in pyglet.input, and they are class DeviceException, class DeviceOpenException, and class DeviceExclusiveException
What is a pyglet?
Pyglet is a simple yet powerful framework for creating aesthetically rich GUI programs for Windows, Mac OS, and Linux, such as games and multimedia.
What does pyglet.input do?
Pyglet.input module provides a single interface to nearly any input device apart from Windows's standard mouse and keyboard functionality.
Conclusion
In this article, we have extensively discussed the pyglet.input module of python programming language.
We hope this blog has helped you enhance your knowledge regarding the pyglet.input module of python. Some official documentation on pyglet python programming language that can help you improve your understanding is Pygame, pyglet, pyglet documentation, augmented reality, and blender.
Check out this problem - Smallest Distinct Window.
If you would like to learn more, check out our articles on pyglet, python libraries, and the basics of python.
Practice makes a man perfect. To practice and improve yourself in the interview, you can check out Top 100 SQL problems, Interview experience, Coding interview questions, and the Ultimate guide path for interviews.
Do upvote our blog to help other ninjas grow. Happy Coding!