jkuhlmann / gainput

Cross-platform C++ input library supporting gamepads, keyboard, mouse, touch
http://gainput.johanneskuhlmann.de/
MIT License
858 stars 103 forks source link
android android-ndk c-plus-plus cmake engine game-engine game-engine-library gamepad games gestures input ios keyboard linux low-level macos mouse multi-touch unified-interface windows

This project is archived. It's neither maintained nor developed anymore.

Gainput Build Status MIT licensed

Gainput is the awesome C++ input library for your game:

Usage

#include <gainput/gainput.h>

enum Button
{
    ButtonConfirm
};

gainput::InputManager manager;
manager.SetDisplaySize(displayWidth, displayHeight);
const gainput::DeviceId keyboardId = manager.CreateDevice<gainput::InputDeviceKeyboard>();
const gainput::DeviceId mouseId = manager.CreateDevice<gainput::InputDeviceMouse>();
const gainput::DeviceId padId = manager.CreateDevice<gainput::InputDevicePad>();
const gainput::DeviceId touchId = manager.CreateDevice<gainput::InputDeviceTouch>();

gainput::InputMap map(manager);
map.MapBool(ButtonConfirm, keyboardId, gainput::KeyReturn);
map.MapBool(ButtonConfirm, mouseId, gainput::MouseButtonLeft);
map.MapBool(ButtonConfirm, padId, gainput::PadButtonA);
map.MapBool(ButtonConfirm, touchId, gainput::Touch0Down);

while (running)
{
    manager.Update();

    // May need some platform-specific message handling here

    if (map.GetBoolWasDown(ButtonConfirm))
    {
        // Confirmed!
    }
}

Features

Building

By default, Gainput is built using CMake.

  1. Run mkdir build
  2. Run cmake ..
  3. Run make
  4. The library can be found in lib/, the executables in samples/.

Contributing

Everyone is welcome to contribute to the library. If you find any problems, you can submit them using GitHub's issue system. If you want to contribute code, you should fork the project and then send a pull request.

Dependencies

Gainput has a minimal number of external dependencies to make it as self-contained as possible. It uses the platforms' default ways of getting inputs and doesn't use the STL.

Testing

Generally, testing should be done by building and running Gainput on all supported platforms. The samples in the samples/ folder should be used in order to determine if the library is functional.

The unit tests in the test/ folder are built by the normal CMake build. The executable can be found in the test/ folder. All build configurations and unit tests are built and run by Travis CI whenever something is pushed into the repository.

Alternatives