GithubHelp home page GithubHelp logo

mapleaph / qjoysticks Goto Github PK

View Code? Open in Web Editor NEW

This project forked from alex-spataru/qjoysticks

0.0 1.0 0.0 6.47 MB

Joystick input library for Qt

License: MIT License

QMake 0.25% C 93.61% C++ 4.72% CMake 0.94% Objective-C 0.48%

qjoysticks's Introduction

QJoysticks library

The QJoysticks library allows your Qt application to read input from both real joysticks/gamepads (using SDL) and a virtual joystick (using the keyboard).

SDL binaries and headers for Windows and OS X are already included in this library. Linux uses will need to install libsdl2-dev using the package manager of their distro of choice.

Online documentation can be found here.

Screenshot

Integrating QJoysticks with your projects

  1. Copy this folder in your "3rd-party" folder.
  2. Include the QJoysticks project include (pri) file using the include() function.
  3. That's all! Check the example project as a reference for your project.

Note for Windows users

In some cases, SDL will redefine the main() function, which may cause compilation problems. In order to fix this, you may need to use this ugly hack.

QML compatibility

This library can be used from QML, just register it as a context property when initializing your QML engine (check the example for more information).

Example Project

I have created a simple example with QML, in which the user can select a joystick and see live feedback from each joystick axis, button and POV.

WTFs Section

1. What are the joystick IDs and how are they assigned?

Each joystick has an numerical ID, which is used by the library and you to access joystick information. The ID is assigned based on the order in which a joystick was attached. Joystick IDs are always congruent to the lists returned by the following functions:

QStringList joystickNames = QJoysticks::getInstance()->deviceNames();
QList<QJoystickDevice*> joysticks = QJoysticks::getInstance()->inputDevices();

NOTE: The virtual joystick will always be the last joystick to be registered, in other words, it will always have the greatest numerical ID.

2. What is the virtual joystick?

The virtual joystick uses your computer keyboard to generate axis, button and POV events. The keyboard mappings are:

Keyboard Keys Joystick Mappings
W,A,S,D Left Stick
I,J,K,L Right Stick
Arrow Keys POV hat
Q,E Left Trigger
U,O Right Trigger
0,1,2,3,4,5,6,7,8,9 Joystick Buttons

NOTE: For the moment, I have not implemented support for custom mappings.

The virtual joystick can be enabled or disabled with the following function:

// Enable the virtual joystick
QJoysticks::getInstance()->setVirtualJoystickEnabled (true);

// Disable the virtual joystick
QJoysticks::getInstance()->setVirtualJoystickEnabled (false);

3. How are joystick events reported?

The QJosyticks library reports joystick events with the following signals:

// Only for C++ applications
void POVEvent (const QJoystickPOVEvent& event);
void axisEvent (const QJoystickAxisEvent& event);
void buttonEvent (const QJoystickButtonEvent& event);

// For C++ applications & QML applications
void povChanged (const int js, const int pov, const int angle);
void axisChanged (const int js, const int axis, const double value);
void buttonChanged (const int js, const int button, const bool pressed);

For more info regarding the C++ only signals, check this file.

3. How are axis values reported?

This library reports an axis value with a range from -1.0 to 1.0 (with 0.0 being neutral). You can customize the axis range of the virtual joystick with the following function:

QJoysticks::getInstance()->setVirtualJoystickAxisRange (0.8);

You cannot customize the axis range of the SDL joysticks.

License

This project is licensed under the MIT license. For more information, check the LICENSE file.

qjoysticks's People

Contributors

alex-spataru avatar bollos00 avatar more-errors avatar franciscoquintana avatar marcusbirkin avatar theodorlindberg avatar xxzl0130 avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.