panda3d.core.InputDevice

class InputDevice

Bases: TypedReferenceCount

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

New in version 1.10.0.

Inheritance diagram

Inheritance diagram of InputDevice

hasFeature(feature: Feature) → bool

Returns true if the device supports the indicated feature.

mapButton(index: size_t, handle: ButtonHandle) → None

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.

mapAxis(index: size_t, axis: Axis) → None

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.

findButton(handle: ButtonHandle) → ButtonState

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

Return type

ButtonState

findAxis(axis: Axis) → AxisState

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

Return type

AxisState

setVibration(strong: float, weak: float) → None

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.

enablePointerEvents() → None

Enables the generation of mouse-movement events.

disablePointerEvents() → None

Disables the generation of mouse-movement events.

poll() → None

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.

hasButtonEvent() → bool

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

getButtonEvents() → ButtonEventList

Returns the list of recently-generated ButtonEvents. The list is also cleared.

Return type

ButtonEventList

hasPointerEvent() → bool

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

getPointerEvents() → PointerEventList

Returns a PointerEventList containing all the recent pointer events. Clears the list.

Return type

PointerEventList

output(out: ostream) → None

Writes a one-line string describing the device.

static getClassType() → TypeHandle
Return type

TypeHandle

property name

The human-readable name of this input device.

Returns a human-readable name for the device. Not necessarily unique.

Return type

string

property manufacturer

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

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

Return type

string

property serial_number

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

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

Return type

string

property vendor_id

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

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

Return type

int

property product_id

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

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

Return type

int

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

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

Return type

bool

property device_class

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

Returns an identification of the general type of device. If this could not be determined, returns DeviceClass.unknown.

Return type

DeviceClass

property tracker

Getters for the various types of device data.

Returns the TrackerData associated with the input device’s tracker. This only makes sense if hasTracker() also returns true.

Return type

TrackerData

property battery

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

Return type

BatteryData

property buttons

Make device buttons and axes iterable

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

Return type

Sequence[ButtonState]

property axes

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

Return type

Sequence[AxisState]

enum DeviceClass

This enum contains information that can be used to identify the type of input device.

enumerator unknown = 0

It is not known what type of device this is.

enumerator virtual_device = 1

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

enumerator keyboard = 2

A physical, alphabetical keyboard.

enumerator mouse = 3
enumerator touch = 4
enumerator gamepad = 5

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

enumerator flight_stick = 6
enumerator steering_wheel = 7
enumerator dance_pad = 8
enumerator hmd = 9

Head-mounted display.

enumerator spatial_mouse = 10

3D mouse, such as produced by 3Dconnexion.

enumerator digitizer = 11

A graphics tablet with stylus/pen.

enum Feature
enumerator pointer = 0

The device provides absolute screen coordinates.

enumerator keyboard = 1

The device has an interface for providing text input.

enumerator tracker = 2

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

enumerator vibration = 3

The device can produce force feedback.

enumerator battery = 4

The device provides information about battery life.

enum Axis
enumerator none = 0
enumerator x = 1

Generic translational axes

enumerator y = 2
enumerator z = 3
enumerator yaw = 4

Generic rotational axes, used by joysticks and 3D mice

enumerator pitch = 5
enumerator roll = 6
enumerator left_x = 7

Gamepad

enumerator left_y = 8
enumerator left_trigger = 9
enumerator right_x = 10
enumerator right_y = 11
enumerator right_trigger = 12
enumerator throttle = 13

Flight stick specific

enumerator rudder = 14

When available separately from yaw

enumerator wheel = 15

Steering wheel / pedals

enumerator accelerator = 16
enumerator brake = 17
enumerator pressure = 18

Pen pressure

enum State
enumerator S_unknown = 0
enumerator S_up = 1
enumerator S_down = 2
class ButtonState
__init__(param0: ButtonState) → None
property known

True if the button state is currently known.

Return type

bool

property pressed

True if the button is currently known to be pressed.

Return type

bool

property handle

getter for ButtonHandle InputDevice::ButtonState::handle;

Return type

ButtonHandle

class AxisState
__init__(param0: AxisState) → None
property axis
Getter

getter for InputDevice::Axis InputDevice::AxisState::axis;

Setter

setter for InputDevice::Axis InputDevice::AxisState::axis;

Return type

Axis

property value
Getter

getter for double InputDevice::AxisState::value;

Setter

setter for double InputDevice::AxisState::value;

Return type

float

property known
Getter

getter for bool InputDevice::AxisState::known;

Setter

setter for bool InputDevice::AxisState::known;

Return type

bool

class BatteryData
__init__() → None
__init__(param0: BatteryData) → None
property level

Ranges from 0 through max_level.

Getter

getter for short int InputDevice::BatteryData::level;

Setter

setter for short int InputDevice::BatteryData::level;

Return type

int

property max_level

Maximum value of ‘level’ field.

Getter

getter for short int InputDevice::BatteryData::max_level;

Setter

setter for short int InputDevice::BatteryData::max_level;

Return type

int

Buttons

alias of pvector_ButtonState

Axes

alias of pvector_AxisState