QJoysticks
A simple way to use joysticks with your Qt application
Public Slots | Signals | Public Member Functions | Protected Member Functions | Private Slots | Private Attributes | List of all members
VirtualJoystick Class Reference

Translates keyboard input to joystick input. More...

#include <VirtualJoystick.h>

Inheritance diagram for VirtualJoystick:

Public Slots

void setJoystickID (int id)
 
void setAxisRange (qreal range)
 
void setJoystickEnabled (bool enabled)
 

Signals

void enabledChanged ()
 
void povEvent (const QJoystickPOVEvent &event)
 
void axisEvent (const QJoystickAxisEvent &event)
 
void buttonEvent (const QJoystickButtonEvent &event)
 

Public Member Functions

qreal axisRange () const
 
bool joystickEnabled () const
 
QJoystickDevicejoystick ()
 

Protected Member Functions

bool eventFilter (QObject *object, QEvent *event)
 

Private Slots

void readAxes (int key, bool pressed)
 
void readPOVs (int key, bool pressed)
 
void readButtons (int key, bool pressed)
 
void processKeyEvent (QKeyEvent *event, bool pressed)
 

Private Attributes

qreal m_axisRange
 
bool m_joystickEnabled
 
QJoystickDevice m_joystick
 

Detailed Description

Translates keyboard input to joystick input.

This class implements a virtual joystick device that uses the computer's keyboard as means to get the axis, button and POV values of the joystick.

Member Function Documentation

qreal VirtualJoystick::axisRange ( ) const

Returns the current axis range of the joystick. The axis range is an absolute value that represents the maximum value that the joystick can have.

For example, the QJoystick system supports an axis range of 1 (-1 to 1). If you set an axis range of 0.8 to the virtual joystick, then it will report values ranging from -0.8 to 0.8.

Referenced by readAxes().

bool VirtualJoystick::eventFilter ( QObject *  object,
QEvent *  event 
)
protected

"Listens" for keyboard presses or releases while any window or widget of the application is focused.

Note
This function may or may not detect keyboard events when the application is not focused. This depends on the operating system and the window manager that is being used.

References processKeyEvent().

QJoystickDevice * VirtualJoystick::joystick ( )

Returns a pointer to the virtual josytick device. This can be used if you need to customize the virtual joystick (e.g. add new axes or buttons).

Referenced by readAxes(), readButtons(), readPOVs(), and QJoysticks::updateInterfaces().

bool VirtualJoystick::joystickEnabled ( ) const

Returns true if the virtual joystick is enabled.

Referenced by processKeyEvent(), readAxes(), readButtons(), and readPOVs().

void VirtualJoystick::processKeyEvent ( QKeyEvent *  event,
bool  pressed 
)
privateslot

Called when the event filter detects a keyboard event.

This function prompts the joystick to update its axis, button and POV values based on the keys that have been pressed or released.

References joystickEnabled(), readAxes(), readButtons(), and readPOVs().

Referenced by eventFilter().

void VirtualJoystick::readAxes ( int  key,
bool  pressed 
)
privateslot

Polls the keyboard events and if required, reports a change in the axis values of the virtual joystick device.

References QJoystickAxisEvent::axis, axisRange(), joystick(), and joystickEnabled().

Referenced by processKeyEvent().

void VirtualJoystick::readButtons ( int  key,
bool  pressed 
)
privateslot

Polls the keyboard events and if required, reports a change in the button values of the virtual joystick device.

References QJoystickButtonEvent::button, joystick(), and joystickEnabled().

Referenced by processKeyEvent().

void VirtualJoystick::readPOVs ( int  key,
bool  pressed 
)
privateslot

Polls the keyboard events and if required, reports a change in the POV/hat values of the virtual joystick device.

References joystick(), joystickEnabled(), and QJoystickPOVEvent::pov.

Referenced by processKeyEvent().

void VirtualJoystick::setAxisRange ( qreal  range)
slot

Changes the axis range that the joystick can use. For example, if you set an axis range of 0.8, then axis values will be reported from -0.8 to 0.8.

If you set an axis range of 1 (maximum), then the joystick will report axis values ranging from -1 to 1.

Referenced by QJoysticks::setVirtualJoystickRange().

void VirtualJoystick::setJoystickEnabled ( bool  enabled)
slot

Enables or disables the virtual joystick device.

Referenced by QJoysticks::setVirtualJoystickEnabled().

void VirtualJoystick::setJoystickID ( int  id)
slot

Sets the ID of the virtual joystick device. The QJoysticks will automatically change the ID of the virtual joystick when it scans for new joysticks.

The virtual joystick will ALWAYS be the last joystick to be registered.

References QJoystickDevice::id.

Referenced by QJoysticks::updateInterfaces().


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