Skip to content

nicolobos77/InputMap

Repository files navigation

InputMap for GameMaker

InputMap is a flexible input handling system for GameMaker that allows you to map multiple input sources — such as keyboard, mouse, gamepad, and touch — to a single named action.

Instead of checking each device separately, you can query the state of an action using a single string, similar to how GameMaker handles keyboard input.
For example:

if (Input.action_pressed("jump")) { /* Do something */ }

Key Features:

  • Map multiple devices to a single action.
  • Supports:
    • Keyboard
    • Mouse
    • Gamepad (buttons and axis)
    • Touch
  • Query input with:
    • Input.action_pressed(name)
    • Input.action_released(name)
    • Input.action_down(name)
    • Easy setup and clean code.

How to Use:

1 - Instance the constructor on a global variable

globalvar Input;
Input = new InputMap();

2 - Define actions

Input.action_add("left");
Input.action_add("up");
Input.action_add("down");
Input.action_add("right");

3 - Map devices to actions

Input.action_set_input("left", {
    keyboard: [ord("A"), vk_left],
    gamepad : [gp_padl, -gp_axislh],
    touch   : ["left"]
});

Input.action_set_input("right", {
    keyboard: [ord("D"), vk_right],
    gamepad : [gp_padr, gp_axislh],
    mouse   : [mb_right]
});

Input.action_set_input("up", {
    keyboard: [ord("W"), vk_up],
    gamepad : [gp_padu, -gp_axislv],
    mouse   : [MB_WHEELS.UP]
});

Input.action_set_input("down", {
    keyboard: [ord("S"), vk_down],
    gamepad : [gp_padd, gp_axislv],
    mouse   : [MB_WHEELS.DOWN]
});

4 - Checking input

Anywhere in your code (Step Event of other objects):

if (Input.action_pressed("left")) {
    x -= 4;
}

if (Input.action_down("up")) {
    y -= 4;
}

if (Input.action_released("down")) {
    show_debug_message("Stopped pressing DOWN");
}

5 - Add touch control

To add a custom touch control, follow these steps:

  1. Create a new object that inherits from obj_touch_parent.
  2. In Variable Definitions, set the variable touch_name to the touch identifier you assigned to an action in Input.action_set_input().
    For example:
    touch_name = "left";
  3. In Create event call
    event_inherited();
  4. Optionally, implement custom behavior in the following functions:
     pressed = function (_touch_id, _touch_x, _touch_y) {
         // Called when the touch starts
     }
     
     down = function (_touch_id, _touch_x, _touch_y) {
         // Called while the touch is held
     }
     
     released = function (_touch_id, _touch_x, _touch_y) {
         // Called when the touch ends
     }

How it works

  • action_add(name): Registers a new action.
  • action_set_input(name, map): Assigns multiple device inputs to the action.
  • action_pressed(name): Returns true if the action was pressed this step.
  • action_down(name): Returns true while the action is held.
  • action_released(name): Returns true if the action was released this step.

Example Use Cases

  • Platformer movement (keyboard, gamepad, or touch)
  • Menu navigation (mouse wheel, arrow keys, joystick)
  • Multi-device multiplayer

Notes

  • Gamepad axis mapping supports positive and negative directions.
  • Touch input uses named areas or gestures (e.g., "left").

About

GameMaker input mapping system

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published