FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Input · EngineSquared/EngineSquared Wiki · GitHub

Lucas Hauszler edited this page May 3, 2025 · 4 revisions

Input Plugin

The input plugin is responsible for handling user input events such as keyboard and mouse actions. It provides a unified interface for managing input across different platforms and devices.

There are currently two ways of interacting with user input in the engine:

  • Polling: the developer can poll for input events using the utils functions. Polling should occur in user-defined systems.
  • Event-based (only for keyboard and mouse): the developer can add event callbacks using the InputManager resource.

Polling

Polling methods are provided under the ES::Plugin::Input::Utils namespace. The following methods are available:

  • IsKeyPressed: Checks if a specific key is currently pressed.
  • IsMouseButtonPressed: Checks if a specific mouse button is currently pressed.
  • GetMousePosition: Retrieves the current position of the mouse cursor.
  • PrintAvailableControllers: Prints the list of available controllers to the console.
  • IsJoystickPresent: Checks if a specific joystick is currently connected.
  • GetJoystickName: Retrieves the name of a specific joystick.
  • GetJoystickAxis: Retrieves the value of a specific joystick axis.
  • GetJoystickButtons: Retrieves the state of the buttons on a specific joystick.

Event-based

Event-based input handling is available for keyboard and mouse events. The developer can add event callbacks using the InputManager resource.

The InputManager resource is automatically added to the core when the Input plugin is bound, like so:

#include "Input.hpp"

void main() {
    // Create the engine
    auto core = ES::Engine::Core();

    // Bind the Input plugin
    core.AddPlugins<ES::Plugin::Input::Plugin>();
}

It is then possible to get a reference to the InputManager resource using the GetResource method:

#include "Input.hpp"

void TestSystem(ES::Engine::Core &core) {
    // Get the InputManager resource
    auto &inputManager = core.GetResource<ES::Plugin::Input::InputManager>();
}

The InputManager resource provides the following methods for adding event callbacks:

  • RegisterKeyCallback: Registers a callback for all key events (pressed, released, and repeated).
  • RegisterCharCallback: Registers a callback for character input events.
  • RegisterCharModsCallback: Registers a callback for character input events with modifiers.
  • RegisterMouseButtonCallback: Registers a callback for mouse button events (pressed and released).
  • RegisterCursorPosCallback: Registers a callback for mouse cursor position events.
  • RegisterCursorEnterCallback: Registers a callback for mouse cursor enter/leave events.
  • RegisterScrollCallback: Registers a callback for mouse scroll events.
  • RegisterDropCallback: Registers a callback for file drop events.

The public Call(...something) methods to call all the callbacks are public but should not be called directly. They are used internally to be able to be bound with glfw callbacks, which is the reason they are public.

Wiki pages Pages 16

Clone this wiki locally


Back | FazBrowse Home | New Git URL