Skip to content

Input‐Controller

ScriptCodex13 edited this page Dec 24, 2025 · 4 revisions

Input-Controller

In PC gaming not only the keyboard is used. Lets say you make a game, but you want to also support controllers. In the Zap-Library thats very straight forward.

Step 1 - create a device

You can create a controller class with this line here:

zap::Device controller = zap::AssignController();

You only have to call it once not in the Update loop.

How controller work here

You created a Device now. If you would connect two controllers the first one which connects is now handled by the device named controller. Because we set only one Device. If you would create a second one the second controller connects under this device.

Step 2 - Connection

If you want to check if the device is connected you use:

if(controller.IsConnected())
{
    //check Buttons or Triggers here
}

Step 3 - checking for inputs

The controller has two types of inputs. For one we have got the Buttons which can be handled like the keyboard inputs with a function call:

if(controller.IsConnected())
{
    if(controller.GetButton(zap::ControllerButtonsPS::CROSS, zap::State::PRESSED))
    {
        std::cout << "X pressed !" << std::endl;
    }
}

and also the triggers which return a value. For example a stick or a bumper on your controller. These values are reaching from -1 to 1.

if(controller.IsConnected())
{
    float L2 = controller.GetTrigger(zap::ControllerTriggersPS::L2);

    std::cout << L2 << std::endl;
}

Button Layout

If you use a XBox controller the inputs are very similar. Here are the examples but with the XBox layout.

if(controller.IsConnected())
{
    if(controller.GetButton(zap::ControllerButtonsXB::A, zap::State::PRESSED))
    {
        std::cout << "A pressed !" << std::endl;
    }
}
if(controller.IsConnected())
{
    float LT = controller.GetTrigger(zap::ControllerTriggersXB::LT);

    std::cout << LT << std::endl;
}

Clone this wiki locally