Panda3D
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...

Inheritance diagram for InputDevice:
TypedReferenceCount TypedObject ReferenceCount GraphicsWindowInputDevice LinuxJoystickDevice

Classes

class  AxisState
 
class  BatteryData
 
class  ButtonState
 

Public Types

enum  Axis {
  none = 0, x = 1, y = 2, z = 3,
  yaw = 4, pitch = 5, roll = 6, left_x = 7,
  left_y = 8, left_trigger = 9, right_x = 10, right_y = 11,
  right_trigger = 12, throttle = 13, rudder = 14, wheel = 15,
  accelerator = 16, brake = 17
}
 
enum  DeviceClass {
  unknown = 0, virtual_device = 1, keyboard = 2, mouse = 3,
  touch = 4, gamepad = 5, flight_stick = 6, steering_wheel = 7,
  dance_pad = 8, hmd = 9, spatial_mouse = 10
}
 
enum  Feature {
  pointer = 0, keyboard = 2, tracker = 2, vibration = 3,
  battery = 4
}
 
enum  State { S_unknown = 0, S_up = 1, S_down = 2 }
 

Public Member Functions

 disablePointerEvents ()
 Disables the generation of mouse-movement events. More...
 
 enablePointerEvents ()
 Enables the generation of mouse-movement events. More...
 
InputDevice::AxisState findAxis (InputDevice::Axis axis)
 Returns the first AnalogAxis found with the given axis, or throw an assert if the axis was not found in the list. More...
 
InputDevice::ButtonState findButton (ButtonHandle handle)
 Returns the first ButtonState found with the given axis, or throw an assert if the button handle was not found in the list. More...
 
ButtonEventList getButtonEvents ()
 Returns the list of recently-generated ButtonEvents. More...
 
PointerEventList getPointerEvents ()
 Returns a PointerEventList containing all the recent pointer events. More...
 
bool hasButtonEvent ()
 Returns true if this device has a pending button event (a mouse button or keyboard button down/up), false otherwise. More...
 
bool hasFeature (InputDevice::Feature feature)
 Returns true if the device supports the indicated feature. More...
 
bool hasPointerEvent ()
 Returns true if this device has a pending pointer event (a mouse movement), or false otherwise. More...
 
 mapAxis (int index, InputDevice::Axis axis)
 Associates the indicated Axis with the axis of the indicated index number. More...
 
 mapButton (int index, ButtonHandle handle)
 Associates the indicated ButtonHandle with the button of the indicated index number. More...
 
 output (Ostream out)
 Writes a one-line string describing the device. More...
 
 poll ()
 Polls the input device for new activity, to ensure it contains the latest events. More...
 
 setVibration (double strong, double weak)
 Sets the strength of the vibration effect, if supported. More...
 
- Public Member Functions inherited from TypedObject
TypeHandle getType ()
 
int getTypeIndex ()
 Returns the internal index number associated with this object's TypeHandle, a unique number for each different type. More...
 
bool isExactType (TypeHandle handle)
 Returns true if the current object is the indicated type exactly. More...
 
bool isOfType (TypeHandle handle)
 Returns true if the current object is or derives from the indicated type. More...
 
- Public Member Functions inherited from ReferenceCount
int getRefCount ()
 Returns the current reference count. More...
 
 ref ()
 Explicitly increments the reference count. More...
 
bool testRefCountIntegrity ()
 Does some easy checks to make sure that the reference count isn't completely bogus. More...
 
bool testRefCountNonzero ()
 Does some easy checks to make sure that the reference count isn't zero, or completely bogus. More...
 
bool unref ()
 Explicitly decrements the reference count. More...
 

Static Public Member Functions

static TypeHandle getClassType ()
 
- Static Public Member Functions inherited from TypedReferenceCount
static TypeHandle getClassType ()
 
- Static Public Member Functions inherited from TypedObject
static TypeHandle getClassType ()
 
- Static Public Member Functions inherited from ReferenceCount
static TypeHandle getClassType ()
 

Public Attributes

InputDevice::Axes _axes
 
InputDevice::BatteryData _battery_data
 
InputDevice::Buttons _buttons
 
PointerData _pointer_data
 
TrackerData _tracker_data
 
InputDevice::AxisState axes []
 
InputDevice::BatteryData battery
 Returns a rough indication of the battery level, ranging from 0 (completely empty battery) to the indicated max_level value. More...
 
InputDevice::ButtonState buttons []
 Make device buttons and axes iterable. More...
 
bool connected
 This is false if we know that the device is not currently connected. May report false positives if we can't know this with certainty. More...
 
InputDevice::DeviceClass device_class
 This contains an identification of the general type of device. If this could not be determined, it is set to DC_unknown. More...
 
String manufacturer
 The device's manufacturer, or the empty string if not known. More...
 
String name
 The human-readable name of this input device. More...
 
unsigned short int product_id
 USB product ID of the device, or 0 if not known. More...
 
String serial_number
 The device's serial number, or the empty string if not known. More...
 
TrackerData tracker
 Getters for the various types of device data. More...
 
unsigned short int vendor_id
 USB vendor ID of the device, or 0 if not known. More...
 
- Public Attributes inherited from TypedObject
TypeHandle type
 Returns the TypeHandle representing this object's type. More...
 
- Public Attributes inherited from ReferenceCount
int ref_count
 The current reference count. More...
 

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

Member Enumeration Documentation

◆ Axis

enum Axis
Enumerator
none 

Generic translational axes.

yaw 

Generic rotational axes, used by joysticks and 3D mice.

pitch 
roll 
left_x 

Gamepad.

left_y 
left_trigger 
right_x 
right_y 
right_trigger 
throttle 

Flight stick specific.

rudder 

When available separately from yaw.

wheel 

Steering wheel / pedals.

accelerator 
brake 

◆ DeviceClass

Enumerator
unknown 

It is not known what type of device this is.

virtual_device 

This means that the device doesn't correspond to a physical device, but rather to a dynamic source of input events.

keyboard 

A physical, alphabetical keyboard.

The device has an interface for providing text input.

mouse 
touch 
gamepad 

A gamepad with action buttons, a D-pad, and thumbsticks.

flight_stick 
steering_wheel 
dance_pad 
hmd 

Head-mounted display.

spatial_mouse 

3D mouse, such as produced by 3Dconnexion.

◆ Feature

enum Feature
Enumerator
pointer 

The device provides absolute screen coordinates.

keyboard 

A physical, alphabetical keyboard.

The device has an interface for providing text input.

tracker 

The device has a motion tracker, such as an HMD.

vibration 

The device can produce force feedback.

battery 

The device provides information about battery life.

◆ State

enum State
Enumerator
S_unknown 
S_up 
S_down 

Member Function Documentation

◆ disablePointerEvents()

disablePointerEvents ( )

Disables the generation of mouse-movement events.

◆ enablePointerEvents()

enablePointerEvents ( )

Enables the generation of mouse-movement events.

◆ findAxis()

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

◆ findButton()

InputDevice::ButtonState findButton ( ButtonHandle  handle)

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

◆ getButtonEvents()

ButtonEventList getButtonEvents ( )

Returns the list of recently-generated ButtonEvents.

The list is also cleared.

◆ getClassType()

static TypeHandle getClassType ( )
static

◆ getPointerEvents()

PointerEventList getPointerEvents ( )

Returns a PointerEventList containing all the recent pointer events.

Clears the list.

◆ hasButtonEvent()

bool hasButtonEvent ( )

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().

◆ hasFeature()

bool hasFeature ( InputDevice::Feature  feature)

Returns true if the device supports the indicated feature.

◆ hasPointerEvent()

bool hasPointerEvent ( )

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().

◆ mapAxis()

mapAxis ( int  index,
InputDevice::Axis  axis 
)

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.

◆ mapButton()

mapButton ( int  index,
ButtonHandle  handle 
)

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.

◆ output()

output ( Ostream  out)

Writes a one-line string describing the device.

◆ poll()

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.

◆ setVibration()

setVibration ( double  strong,
double  weak 
)

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.

Member Data Documentation

◆ _axes

InputDevice::Axes _axes

◆ _battery_data

InputDevice::BatteryData _battery_data

◆ _buttons

InputDevice::Buttons _buttons

◆ _pointer_data

PointerData _pointer_data

◆ _tracker_data

TrackerData _tracker_data

◆ axes

◆ battery

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

◆ buttons

Make device buttons and axes iterable.

◆ connected

bool connected

This is false if we know that the device is not currently connected. May report false positives if we can't know this with certainty.

◆ device_class

This contains an identification of the general type of device. If this could not be determined, it is set to DC_unknown.

◆ manufacturer

String manufacturer

The device's manufacturer, or the empty string if not known.

◆ name

String name

The human-readable name of this input device.

◆ product_id

unsigned short int product_id

USB product ID of the device, or 0 if not known.

◆ serial_number

String serial_number

The device's serial number, or the empty string if not known.

◆ tracker

TrackerData tracker

Getters for the various types of device data.

◆ vendor_id

unsigned short int vendor_id

USB vendor ID of the device, or 0 if not known.