Skip to content

Getting started

Adérito Silva edited this page Jun 18, 2022 · 13 revisions

XInputium was made with the goal of providing powerful features, but without requiring you to write too much code to get things done. Its API offers several ways for you to consume it, but in this page we will cover the most simple way, which is event based.

Before talking about XInputium architecture, let's just see a simple example of how you could integrate XInputium with your application, so you could make button Start show a message box in a hypothetical application:

// This would be the hypothetical application window class.
public class ApplicationWindow : Window
{

    private XGamepad _gamepad;  // This represents the gamepad.

    public new ApplicationWindow()
    {
        // Create a new XGamepad instance, that uses the first connected XInput controller.
        _gamepad = new();
        // Register a dynamic event that listens for the Start button,
        // and calls the ShowMessageBox method when that button is pressed.
        _gamepad.RegisterButtonPressedEvent(XButtons.Start, 
            (s, e) => ShowMessageBox("You've just pressed Start button!"));
    }

    // This would be a hypothetical method of the window, that would be called on each frame.
    protected override void OnRender()
    {
        // Our application is rendering a frame. Notify the input API that it 
        // can now refresh its state and process any input. Any input events
        // will be triggered now.
        _gamepad.Update();
    }

    // This method will be called whenever button Start is pressed.
    public void ShowMessageBox(string text)
    {
        // Show a dialog box that displays the specified text.
    }

}

The code above uses XInputium in the following way:

  1. When the window is instantiated, it creates a new logical XInput device (_gamepad = new()), and registers an event.
  2. On every window frame update, it notifies the logical device, so the logical device can perform the next iteration of its input loop.

Clone this wiki locally