Panda3D

Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
InputDevice Class Reference

This is a structure representing a single input device. More...

`#include "inputDevice.h"`

Inheritance diagram for InputDevice:

## Classes
class | AxisState
class | BatteryData
class | ButtonState

## Public Types
typedef pvector< AxisState > | Axes
enum class | Axis { none , x , y , z , yaw , pitch , roll , left_x , left_y , left_trigger , right_x , right_y , right_trigger , throttle , rudder , wheel , accelerator , brake , pressure }
typedef pvector< ButtonState > | Buttons
enum class | DeviceClass { unknown , virtual_device , keyboard , mouse , touch , gamepad , flight_stick , steering_wheel , dance_pad , hmd , spatial_mouse , digitizer }
enum class | Feature { pointer , keyboard , tracker , vibration , battery }
enum | State { S_unknown , S_up , S_down }

## Public Member Functions
| InputDevice (const InputDevice &copy)=delete
void | disable_pointer_events ()
| Disables the generation of mouse-movement events.
void | enable_pointer_events ()
| Enables the generation of mouse-movement events.
AxisState | find_axis (Axis axis) const
| Returns the first AnalogAxis found with the given axis, or throw an assert if the axis was not found in the list.
ButtonState | find_button (ButtonHandle handle) const
| Returns the first ButtonState found with the given axis, or throw an assert if the button handle was not found in the list.
virtual TypeHandle | force_init_type ()
AxisState | get_axis (size_t index) const
double | get_axis_value (size_t index) const
| Returns the current position of indicated analog axis (identified by its index number), or 0.0 if the axis is unknown.
BatteryData | get_battery () const
ButtonState | get_button (size_t index) const
ButtonHandle | get_button_map (size_t index) const
| Returns the ButtonHandle that was previously associated with the given index number by a call to map_button(), or ButtonHandle::none() if no button was associated.
DeviceClass | get_device_class () const
std::string | get_manufacturer () const
std::string | get_name () const
size_t | get_num_axes () const
size_t | get_num_buttons () const
unsigned short | get_product_id () const
std::string | get_serial_number () const
TrackerData | get_tracker () const
virtual TypeHandle | get_type () const
unsigned short | get_vendor_id () const
bool | has_battery () const
bool | has_button_event () const
| Returns true if this device has a pending button event (a mouse button or keyboard button down/up), false otherwise.
bool | has_feature (Feature feature) const
| Returns true if the device supports the indicated feature.
bool | has_keyboard () const
| Returns true if the device has a physical keyboard designed for text entry.
bool | has_pointer () const
| Returns true if this is a pointing device.
bool | has_pointer_event () const
| Returns true if this device has a pending pointer event (a mouse movement), or false otherwise.
bool | has_tracker () const
bool | has_vibration () const
| Returns true if the device has vibration motors that can be controlled by calling set_vibration().
bool | is_axis_known (size_t index) const
| Returns true if the state of the indicated analog axis is known, or false if we have never heard anything about this particular axis.
bool | is_button_known (size_t index) const
| Returns true if the state of the indicated button is known, or false if we have never heard anything about this particular button.
bool | is_button_pressed (size_t index) const
| Returns true if the indicated button (identified by its index number) is currently known to be down, or false if it is up or unknown.
bool | is_connected () const
void | map_axis (size_t index, Axis axis)
| Associates the indicated Axis with the axis of the indicated index number.
void | map_button (size_t index, ButtonHandle handle)
| Associates the indicated ButtonHandle with the button of the indicated index number.
InputDevice & | operator= (const InputDevice &copy)=delete
virtual void | output (std::ostream &out) const
| Writes a one-line string describing the device.
void | output_buttons (std::ostream &out) const
| Writes a one-line string of all of the current button states.
void | poll ()
| Polls the input device for new activity, to ensure it contains the latest events.
| PT (ButtonEventList) get_button_events()
| PT (PointerEventList) get_pointer_events()
void | set_connected (bool connected)
| Called to indicate that the device has been disconnected or connected from its host.
void | set_vibration (double strong, double weak)
| Sets the strength of the vibration effect, if supported.
void | write_axes (std::ostream &out, int indent_level) const
| Writes a multi-line description of the current analog axis states.
void | write_buttons (std::ostream &out, int indent_level) const
| Writes a multi-line description of the current button states.
Public Member Functions inherited from TypedReferenceCount
| TypedReferenceCount (const TypedReferenceCount &copy)
void | operator= (const TypedReferenceCount &copy)
Public Member Functions inherited from TypedObject
| TypedObject (const TypedObject &copy)=default
TypedObject * | as_typed_object ()
| Returns the object, upcast (if necessary) to a TypedObject pointer.
const TypedObject * | as_typed_object () const
| Returns the object, upcast (if necessary) to a TypedObject pointer.
int | get_best_parent_from_Set (const std::set< int > &) const
int | get_type_index () const
| Returns the internal index number associated with this object's TypeHandle, a unique number for each different type.
bool | is_exact_type (TypeHandle handle) const
| Returns true if the current object is the indicated type exactly.
bool | is_of_type (TypeHandle handle) const
| Returns true if the current object is or derives from the indicated type.
TypedObject & | operator= (const TypedObject &copy)=default
Public Member Functions inherited from MemoryBase
void | operator delete (void *, void *)
void | operator delete (void *ptr)
void | operator delete[] (void *, void *)
void | operator delete[] (void *ptr)
void * | operator new (size_t size)
void * | operator new (size_t size, void *ptr)
void * | operator new[] (size_t size)
void * | operator new[] (size_t size, void *ptr)
Public Member Functions inherited from ReferenceCount
int | get_ref_count () const
WeakReferenceList * | get_weak_list () const
| Returns the WeakReferenceList associated with this ReferenceCount object.
bool | has_weak_list () const
| Returns true if this particular ReferenceCount object has a WeakReferenceList created, false otherwise.
void | local_object ()
| This function should be called, once, immediately after creating a new instance of some ReferenceCount-derived object on the stack.
void | ref () const
| Explicitly increments the reference count.
bool | ref_if_nonzero () const
| Atomically increases the reference count of this object if it is not zero.
bool | test_ref_count_integrity () const
| Does some easy checks to make sure that the reference count isn't completely bogus.
bool | test_ref_count_nonzero () const
| Does some easy checks to make sure that the reference count isn't zero, or completely bogus.
virtual bool | unref () const
| Explicitly decrements the reference count.
bool | unref_if_one () const
| Atomically decreases the reference count of this object if it is one.
WeakReferenceList * | weak_ref ()
| Adds the indicated PointerToVoid as a weak reference to this object.
void | weak_unref ()
| Removes the indicated PointerToVoid as a weak reference to this object.

## Static Public Member Functions
static std::string | format_axis (Axis axis)
| Returns a string describing the given axis enumerant.
static std::string | format_device_class (DeviceClass dc)
| Returns a string describing the given device class enumerant.
static TypeHandle | get_class_type ()
static void | init_type ()
Static Public Member Functions inherited from TypedReferenceCount
static TypeHandle | get_class_type ()
static void | init_type ()
Static Public Member Functions inherited from TypedObject
static TypeHandle | get_class_type ()
static void | init_type ()
| This function is declared non-inline to work around a compiler bug in g++ 2.96.
Static Public Member Functions inherited from ReferenceCount
static TypeHandle | get_class_type ()
static void | init_type ()

## Public Attributes
Axes | _axes
BatteryData | _battery_data
Buttons | _buttons
PointerData | _pointer_data
TrackerData | _tracker_data
| get_axis
| Returns the axis state that is set at the given index, or throw an assert if the index was not found in the list.
| get_battery
| Returns a rough indication of the battery level, ranging from 0 (completely empty battery) to the indicated max_level value.
| get_button
| Returns the ButtonState that is set at the given index, or throw an assert if the index was not found in the list.
| get_device_class
| Returns an identification of the general type of device.
| get_manufacturer
| Returns a string containing the manufacturer of the device, if this information is known.
| get_name
| Returns a human-readable name for the device.
| get_num_axes
| Returns the number of analog axes known to the InputDevice.
| get_num_buttons
| Returns the number of buttons known to the device.
| get_product_id
| Returns a string containing the USB product ID of the device, if this information is known.
| get_serial_number
| Returns a string containing the serial number of the device, if this information is known.
| get_tracker
| Returns the TrackerData associated with the input device's tracker.
| get_vendor_id
| Returns a string containing the USB vendor ID of the device, if this information is known.
| has_battery
| Returns true if the device may be able to provide information about its battery life.
| has_tracker
| Returns true if the device features a tracker that can track position and/or orientation in 3D space.
| is_connected
| Returns true if the device is still connected and able to receive data, false otherwise.
Public Attributes inherited from TypedObject
| get_type
Public Attributes inherited from ReferenceCount
| get_ref_count
| Returns the current reference count.

## Detailed Description

This is a structure representing a single input device.

Input devices may have zero or more buttons, pointers, or axes associated with them, and optionally a motion tracker.

These devices are brought under a common interface because there is such a large range of devices out there that may support any number of these types of axes, we couldn't even begin to cover them with type-specific subclasses.

Use the various has_() and get_num_() methods to determine information about the device capabilities. For instance, has_keyboard() will give an indication that you can receive keystroke events from this device, and get_num_buttons() will tell you that the device may send button events.

There is the DeviceType enumeration, however, which will (if known) contain identification of the general category of devices this fits in, such as keyboard, mouse, gamepad, or flight stick.

Since
  1.10.0

Definition at line 53 of file inputDevice.h.

## Member Typedef Documentation

## ◆ Axes

typedef pvector<AxisState> InputDevice::Axes

Definition at line 338 of file inputDevice.h.

## ◆ Buttons

typedef pvector<ButtonState> InputDevice::Buttons

Definition at line 337 of file inputDevice.h.

## Member Enumeration Documentation

## ◆ Axis

enum class InputDevice::Axis
| strong

Definition at line 105 of file inputDevice.h.

## ◆ DeviceClass

enum class InputDevice::DeviceClass
| strong

Definition at line 57 of file inputDevice.h.

## ◆ Feature

enum class InputDevice::Feature
| strong

Definition at line 88 of file inputDevice.h.

## ◆ State

enum InputDevice::State

Definition at line 139 of file inputDevice.h.

## Constructor & Destructor Documentation

## ◆ InputDevice()

InputDevice::InputDevice | ( |  | ) |
| inline

Definition at line 19 of file inputDevice.I.

## ◆ ~InputDevice()

InputDevice::~InputDevice | ( |  | ) |
| virtual

Definition at line 38 of file inputDevice.cxx.

## Member Function Documentation

## ◆ disable_pointer_events()

void InputDevice::disable_pointer_events | ( |  | ) |
| inline

Disables the generation of mouse-movement events.

Definition at line 362 of file inputDevice.I.

## ◆ enable_pointer_events()

void InputDevice::enable_pointer_events | ( |  | ) |
| inline

Enables the generation of mouse-movement events.

Definition at line 353 of file inputDevice.I.

## ◆ find_axis()

InputDevice::AxisState InputDevice::find_axis | ( | InputDevice::Axis | axis | ) | const
| inline

Returns the first AnalogAxis found with the given axis, or throw an assert if the axis was not found in the list.

Definition at line 316 of file inputDevice.I.

## ◆ find_button()

InputDevice::ButtonState InputDevice::find_button | ( | ButtonHandle | handle | ) | const
| inline

Returns the first ButtonState found with the given axis, or throw an assert if the button handle was not found in the list.

Definition at line 252 of file inputDevice.I.

## ◆ force_init_type()

virtual TypeHandle InputDevice::force_init_type | ( |  | ) |
| inline virtual

Reimplemented from TypedReferenceCount.

Definition at line 358 of file inputDevice.h.

## ◆ format_axis()

std::string InputDevice::format_axis | ( | Axis | axis | ) |
| static

Returns a string describing the given axis enumerant.

Definition at line 591 of file inputDevice.cxx.

## ◆ format_device_class()

std::string InputDevice::format_device_class | ( | DeviceClass | dc | ) |
| static

Returns a string describing the given device class enumerant.

Definition at line 546 of file inputDevice.cxx.

## ◆ get_axis_value()

double InputDevice::get_axis_value | ( | size_t | index | ) | const
| inline

Returns the current position of indicated analog axis (identified by its index number), or 0.0 if the axis is unknown.

The normal range of a single axis is -1.0 to 1.0.

Definition at line 293 of file inputDevice.I.

## ◆ get_button_map()

ButtonHandle InputDevice::get_button_map | ( | size_t | index | ) | const
| inline

Returns the ButtonHandle that was previously associated with the given index number by a call to map_button(), or ButtonHandle::none() if no button was associated.

Definition at line 203 of file inputDevice.I.

## ◆ get_class_type()

static TypeHandle InputDevice::get_class_type | ( |  | ) |
| inline static

Definition at line 347 of file inputDevice.h.

## ◆ get_type()

virtual TypeHandle InputDevice::get_type | ( |  | ) | const
| inline virtual

Reimplemented from TypedReferenceCount.

Definition at line 355 of file inputDevice.h.

## ◆ has_button_event()

bool InputDevice::has_button_event | ( |  | ) | const

Returns true if this device has a pending button event (a mouse button or keyboard button down/up), false otherwise.

If this returns true, the particular event may be extracted via get_button_event().

Definition at line 58 of file inputDevice.cxx.

## ◆ has_feature()

bool InputDevice::has_feature | ( | Feature | feature | ) | const
| inline

Returns true if the device supports the indicated feature.

Definition at line 97 of file inputDevice.I.

Referenced by has_keyboard(), has_pointer(), and has_vibration().

## ◆ has_keyboard()

bool InputDevice::has_keyboard | ( |  | ) | const
| inline

Returns true if the device has a physical keyboard designed for text entry.

Definition at line 114 of file inputDevice.I.

References has_feature().

## ◆ has_pointer()

bool InputDevice::has_pointer | ( |  | ) | const
| inline

Returns true if this is a pointing device.

Definition at line 106 of file inputDevice.I.

References has_feature().

## ◆ has_pointer_event()

bool InputDevice::has_pointer_event | ( |  | ) | const

Returns true if this device has a pending pointer event (a mouse movement), or false otherwise.

If this returns true, the particular event may be extracted via get_pointer_event().

Definition at line 81 of file inputDevice.cxx.

## ◆ has_vibration()

bool InputDevice::has_vibration | ( |  | ) | const
| inline

Returns true if the device has vibration motors that can be controlled by calling set_vibration().

Definition at line 132 of file inputDevice.I.

References has_feature().

## ◆ init_type()

static void InputDevice::init_type | ( |  | ) |
| inline static

Definition at line 350 of file inputDevice.h.

## ◆ is_axis_known()

bool InputDevice::is_axis_known | ( | size_t | index | ) | const
| inline

Returns true if the state of the indicated analog axis is known, or false if we have never heard anything about this particular axis.

Definition at line 330 of file inputDevice.I.

## ◆ is_button_known()

bool InputDevice::is_button_known | ( | size_t | index | ) | const
| inline

Returns true if the state of the indicated button is known, or false if we have never heard anything about this particular button.

Definition at line 229 of file inputDevice.I.

## ◆ is_button_pressed()

bool InputDevice::is_button_pressed | ( | size_t | index | ) | const
| inline

Returns true if the indicated button (identified by its index number) is currently known to be down, or false if it is up or unknown.

Definition at line 216 of file inputDevice.I.

## ◆ map_axis()

void InputDevice::map_axis | ( | size_t | index,
|  | InputDevice::Axis | axis )
| inline

Associates the indicated Axis with the axis of the indicated index number.

Pass Axis::none to turn off any association.

It is not necessary to call this if you simply want to query the state of the various axes by index number.

Definition at line 278 of file inputDevice.I.

## ◆ map_button()

void InputDevice::map_button | ( | size_t | index,
|  | ButtonHandle | button )
| inline

Associates the indicated ButtonHandle with the button of the indicated index number.

When the given button index changes state, a corresponding ButtonEvent will be generated with the given ButtonHandle. Pass ButtonHandle::none() to turn off any association.

It is not necessary to call this if you simply want to query the state of the various buttons by index number; this is only necessary in order to generate ButtonEvents when the buttons change state.

Definition at line 188 of file inputDevice.I.

## ◆ output()

void InputDevice::output | ( | std::ostream & | out | ) | const
| virtual

Writes a one-line string describing the device.

Reimplemented in ClientButtonDevice, and ClientDevice.

Definition at line 379 of file inputDevice.cxx.

## ◆ output_buttons()

void InputDevice::output_buttons | ( | std::ostream & | out | ) | const

Writes a one-line string of all of the current button states.

Definition at line 439 of file inputDevice.cxx.

References InputDevice::ButtonState::is_known.

Referenced by ClientButtonDevice::output().

## ◆ poll()

void InputDevice::poll | ( |  | ) |

Polls the input device for new activity, to ensure it contains the latest events.

This will only have any effect for some types of input devices; others may be updated automatically, and this method will be a no-op.

Definition at line 47 of file inputDevice.cxx.

## ◆ set_connected()

void InputDevice::set_connected | ( | bool | connected | ) |
| inline

Called to indicate that the device has been disconnected or connected from its host.

Definition at line 382 of file inputDevice.I.

Referenced by ClientDevice::disconnect().

## ◆ set_vibration()

void InputDevice::set_vibration | ( | double | strong,
|  | double | weak )
| inline

Sets the strength of the vibration effect, if supported.

The values are clamped to 0-1 range. The first value axes the low-frequency rumble motor, whereas the second axes the high-frequency motor, if present.

Definition at line 344 of file inputDevice.I.

## ◆ write_axes()

void InputDevice::write_axes | ( | std::ostream & | out,
|  | int | indent_level ) const

Writes a multi-line description of the current analog axis states.

Definition at line 503 of file inputDevice.cxx.

References indent().

## ◆ write_buttons()

void InputDevice::write_buttons | ( | std::ostream & | out,
|  | int | indent_level ) const

Writes a multi-line description of the current button states.

Definition at line 469 of file inputDevice.cxx.

References indent(), and InputDevice::ButtonState::is_known.

## Member Data Documentation

## ◆ _axes

Axes InputDevice::_axes

Definition at line 340 of file inputDevice.h.

## ◆ _battery_data

BatteryData InputDevice::_battery_data

Definition at line 343 of file inputDevice.h.

## ◆ _buttons

Buttons InputDevice::_buttons

Definition at line 339 of file inputDevice.h.

## ◆ _pointer_data

PointerData InputDevice::_pointer_data

Definition at line 342 of file inputDevice.h.

## ◆ _tracker_data

TrackerData InputDevice::_tracker_data

Definition at line 344 of file inputDevice.h.

## ◆ get_axis

InputDevice::AxisState InputDevice::get_axis
| inline

Returns the axis state that is set at the given index, or throw an assert if the index was not found in the list.

Definition at line 259 of file inputDevice.h.

## ◆ get_battery

InputDevice::BatteryData InputDevice::get_battery
| inline

Returns a rough indication of the battery level, ranging from 0 (completely empty battery) to the indicated max_level value.

Definition at line 255 of file inputDevice.h.

## ◆ get_button

InputDevice::ButtonState InputDevice::get_button
| inline

Returns the ButtonState that is set at the given index, or throw an assert if the index was not found in the list.

Definition at line 258 of file inputDevice.h.

## ◆ get_device_class

InputDevice::DeviceClass InputDevice::get_device_class
| inline

Returns an identification of the general type of device.

If this could not be determined, returns DeviceClass.unknown.

Definition at line 248 of file inputDevice.h.

Referenced by InputDeviceManager::get_devices().

## ◆ get_manufacturer

std::string InputDevice::get_manufacturer
| inline

Returns a string containing the manufacturer of the device, if this information is known.

Definition at line 231 of file inputDevice.h.

## ◆ get_name

std::string InputDevice::get_name
| inline

Returns a human-readable name for the device.

Not necessarily unique.

Definition at line 228 of file inputDevice.h.

Referenced by ClientDevice::disconnect(), ClientButtonDevice::output(), and ClientDevice::output().

## ◆ get_num_axes

size_t InputDevice::get_num_axes
| inline

Returns the number of analog axes known to the InputDevice.

This number may change as more axes are discovered.

Definition at line 259 of file inputDevice.h.

## ◆ get_num_buttons

size_t InputDevice::get_num_buttons
| inline

Returns the number of buttons known to the device.

This includes those buttons whose state has been seen, as well as buttons that have been associated with a ButtonHandle even if their state is unknown. This number may change as more buttons are discovered.

Definition at line 258 of file inputDevice.h.

## ◆ get_product_id

unsigned short InputDevice::get_product_id
| inline

Returns a string containing the USB product ID of the device, if this information is known.

Definition at line 240 of file inputDevice.h.

## ◆ get_serial_number

std::string InputDevice::get_serial_number
| inline

Returns a string containing the serial number of the device, if this information is known.

Definition at line 234 of file inputDevice.h.

## ◆ get_tracker

TrackerData InputDevice::get_tracker
| inline

Returns the TrackerData associated with the input device's tracker.

This only makes sense if has_tracker() also returns true.

Definition at line 254 of file inputDevice.h.

## ◆ get_vendor_id

unsigned short InputDevice::get_vendor_id
| inline

Returns a string containing the USB vendor ID of the device, if this information is known.

Definition at line 237 of file inputDevice.h.

## ◆ has_battery

bool InputDevice::has_battery
| inline

Returns true if the device may be able to provide information about its battery life.

Definition at line 255 of file inputDevice.h.

## ◆ has_tracker

bool InputDevice::has_tracker
| inline

Returns true if the device features a tracker that can track position and/or orientation in 3D space.

Definition at line 254 of file inputDevice.h.

## ◆ is_connected

bool InputDevice::is_connected
| inline

Returns true if the device is still connected and able to receive data, false otherwise.

May return false positives.

Definition at line 244 of file inputDevice.h.

Referenced by ClientDevice::~ClientDevice(), and ClientDevice::disconnect().

The documentation for this class was generated from the following files:

- panda/src/device/inputDevice.h
- panda/src/device/inputDevice.cxx
- panda/src/device/inputDevice.I