QJoysticks
A simple way to use joysticks with your Qt application
|
Translates keyboard input to joystick input. More...
#include <VirtualJoystick.h>
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 |
QJoystickDevice * | joystick () |
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 |
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.
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().
|
protected |
"Listens" for keyboard presses or releases while any window or widget of the application is focused.
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().
|
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().
|
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().
|
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().
|
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().
|
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().
|
slot |
Enables or disables the virtual joystick device.
Referenced by QJoysticks::setVirtualJoystickEnabled().
|
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().