InputCandy by Lost Astronaut

InputCandy focuses on providing input testing and customization for users
of PC and gamepad-friendly platforms (consoles).
It's that classic "control setup" panel system you are accustomed to seeing
in video games small and large, but for GameMaker.
It also is an object-oriented input API, with action matching, and a bunch of device detection features for keyboard, mouse and any SDL controller.
For GMS 2.3.1+
Always get the latest version from https://github.com/LAGameStudio/InputCandy
See a bug? Submit an issue here, or better yet, a Pull Request.
Games Using InputCandy
Using InputCandy but not yet on this list? Submit your game via the Issues tab.
Games that have used or benefitted from or contributed to InputCandy:
Asking Questions
If you need to ask the primary author a question, do so on the Lost Astronaut discord in the #inputcandy channel: https://discord.gg/PN6gS3CAEe
I have posted some additional code there to help people integrate InputCandy with their game. There are many ways to do it, so I've left it over there because you can come up with your own implementation or tie it into your own game in whatever way you choose.
If you have found an issue, simply create one here
Supporting InputCandy
If you download, use, or just simply like this library, please star the above Repo, it helps. :) If you use this library in your
game, please add the provided Lost Astronaut and Image Candy logos to your startup screen if you wish
to give back a little credit to the creators of InputCandy.
Likewise, we'd love to showcase any game you make with InputCandy here on this page, or in a file included with future versions of InputCandy, so please open an "Issue" and announce your game when it's available for others to play, and we'll include it.
Understanding the Situation
InputCandy is good for the following things:
- Provides a quick way of supporting most controllers (mouse, keyboard, and broadly implemented gamepad support) for your game menus. Use InputCandySimple, or the MenuControls example for cross-platform VCS, PC and Linux support (below)
- Provides a way for PC games to permit full Keyboard and Mouse customization. Use ICUI.
- Provides a diagnostic feature useful on multiple platforms to troubleshoot what values are actually coming from a controller when you physically move it. Use rm_InputCandy_diagnostics
- For local multiplayer ("couch" coop etc), InputCandy provides a way for users to select which player uses which controller.
- Adapting to changing configurations
- Remembering previous configurations
- Provide a controller and mouse-friendly UI for customizing controls (ICUI)
- Provide a way for users to see what their controllers are doing, and to test control schemes (ICUI's Test on Simulator)
However, in first writing and later using InputCandy, SDL and GameMaker, I can tell you the following nuggets of wisdom:
- There is no reliable way to detect most controllers, including the most common ones like XBOX and PS4. This is because no one uses the GUID properly and third-party companies fake their GUID information or the GUID information returned to GameMaker is unreliable and differs per platform. The "Gamepad Description" is also not reliable.
- Because there is no reliable way to detect most controllers, use of the SDLDB should be done so only in specific situations and is generally not recommended. It certainly cannot be automagically applied to detected gamepads without user confirmation and one of those "Reverting in 15 seconds..." screens like you see in the Windows desktop when you change resolutions.
- Because there is no reliable way to detect most controllers, you may have to resort to checking "number of buttons, hats and axis" in specific cases which can result in false positives.
- See Issue #2
Example Implementation
In my game, Apolune: Through the Wormhole, InputCandy user-customization of controls is used as a fallback, and before I implemented anything to do with InputCandy, I identified requirements:
- The game targets PCs running Windows OR Linux, OR the VCS Console.
- It would support a maximum of 8 players in local multiplayer.
- The year of development is 2023, so it should support sane, contemporary controller default profiles without players having to use InputCandy at all. Those default profiles were determined by the target platforms. For Steam, the default would be supporting an XBOX controller, since this works well with the SteamDeck, is the most commonly used contemporary PC gamepad, and is most readily supported by GameMaker's default gamepad values. For Linux, I am aware that the axis values are centered on
0.5,0.5 not 0.0,0.0 as it is on Windows. The values range (on Linux) from 0 to 1, while on Windows they go from -1 to 1. Finally, I was targeting the Atari VCS Console, which has two possible native controllers, the VCS Classic and the VCS Modern.
- I still wanted the option for players to be able to fully customize other USB controllers if they so choose.
- It would allow connect and disconnect (hot swapping) of controllers. Allow meaning it will not crash.
Where InputCandy shines is not in the ability to detect controller manufacturers, but rather to detect if they are connected, and to assign them to players and remember that setting. It also works well when adjusting if a player has disconnected a controller during gameplay.
In point 2 above, I'm talking about profiles. What I mean is, specific implementations selectable by the player. While Issue #4 suggests InputCandy provide a formal way of handling this, as it stands in <1.0.0 versions, it is left up to you, the game developer, to handle this because it is really specific to what you are trying to accomplish, ie. what platforms and expectations you have of your user audience.
For example, I chose to support the XBOX Series X/S controller. It is wise to also support the PS4 Dual Shock controller. In 2023, these are the most likely controllers for the PC, not because the game is going to come out on those consoles. Additionally, I targeted 1 other platform, the Atari VCS Console, so I have support built in for the VCS Modern and the VCS Classic.
In my game controller menus, before it even reaches InputCandy, each of the 8 players has a default profile appropriate to the build platform. For Steam builds, it chooses XBOX, and for the VCS it chooses the VCS. Users then have the option of changing the profile to VCS (if they are using it on the VCS or on the PC with VCS hardware), XBOX (if they are using XBOX controllers on the VCS or on the PC), and PS4 (if they are using the PS4 controller), or CUSTOM, which is the InputCandy actions. Note that on the PC, CUSTOM is the default setting for Player 1 when no gamepads are selected, because they must not have a gamepad and need to use InputCandy to handle the keyboard actions.
InputCandy's "assign device to player" ICUI panel is used to allow for specific assignments. Each player has his/her own profile choice (VCS, XBOX, PS4 or CUSTOM). I then wrote a series of functions wrapped around various actions. When these functions are called, for example, CheckFireButtonForPlayer(player_number), it checks my game's settings to see which of the profiles has been chosen for the player. These settings are stored and handled separately from InputCandy's settings.
If CUSTOM is chosen, IC_Match is called, if XBOX, VCS or PS4 is chosen, it calls specific GML functions that will handle those activities. For Apolune: Through the Wormhole, the game is a top-down shooter, so it has the following:
- Primary (true if fire button held)
- Secondary (true if fire button 2 is held)
- Tertiary (true if fire button 3 is held)
- AimLeft (usually a left shoulder, aims the turret on the ship)
- AimRight (usually a right shoulder, aims the turret on the ship)
- Move (a combination of sticks, hats, and d-pads, depending on which gamepad or joystick)
- Menu (the "open menu" button, or the "pause" button, usually a burger, can also be "Select")
- Back (a general "cancel" button, or "back" on some gamepads)
For each of these functions, I check against the player's game settings. Here's an example for the CheckMenu function:
function CheckMenuButtonForPlayer(pn) {
var hand=GetPlayerControllerProfile(pn);
if ( hand == false ) return false; // This means no device is selected. In the future, this may check keyboard only if it is the keyboard-using-player.
var dv=hand.slot_id;
if ( hand.slot_id != none ) {
if ( isPlayerUsingVCSControls(pn) ) { // "VCS"
if ( isPlayerUsingVCSClassic(pn) ) {
return gamepad_button_check_released(dv,gp_face4);
} else { // VCS Modern
return gamepad_button_check_released(dv,gp_shoulderrb);
}
} else if ( isPlayerUsingXBOXControls(pn) ) { // "XBOX"
return gamepad_button_check_released(dv,gp_start);
} else if ( isPlayerUsingPS4Controls(pn) ) { // "PS4"
return gamepad_button_check_released(dv,gp_start);
} else if ( isPlayerUsingInputCandy(pn) ) { // "CUSTOM"
return IC_Match(pn,global.game_actions.menu.index); // Calls InputCandy to test for action
}
} else if ( pn-1 == __INPUTCANDY.player_using_keyboard_mouse ) {
return IC_Match(pn,global.game_actions.menu.index);
// This calls InputCandy to test for action. In the future, this may check keyboard only if it is the keyboard-using-player.
}
}
The way I went about figuring out how to program the above is by testing each controller on each platform using InputCandy's rm_InputCandy_diagnostics, and then writing a special case for each scenario that needed one.
Finally, I want to mention special considerations for the "Move" action. The "Move" action is complicated because I let the user use the d-pad OR the stick. It returns the following values in a struct:
var result={
combined: { x:0, y:0 },
move2: { x:0, y:0 },
move: { x:0, y:0 },
angle: AXIS_NO_VALUE,
angle2: AXIS_NO_VALUE,
left: false,
up: false,
right: false,
down: false,
leftUp: false,
leftDown: false,
rightUp: false,
rightDown: false,
left2: false,
up2: false,
right2: false,
down2: false,
leftUp2: false,
leftDown2: false,
rightUp2: false,
rightDown2: false,
raw: false,
raw2: false
};
In the above struct, the player ship object has to interpret these controls to update ship parameters (speed, direction, etc). The combined value takes the "greater magnitude" of move2 and move vectors. Usually, the player will only be pressing one or the other, but they may be pressing both. It also returns the explicit values for both the move and move2 (d-pad and stick). For the VCS Classic, Move2 is never set so those all appear as false always and shouldn't affect anything else. The raw and raw2 values are the structs returned by global.IC.MatchDirectional(), aka the struct seen in global.ICI.New_ICMoving
MenuControls
You need a generic, broadly usable, keyboard-friendly, and game-controller-friendly way of navigating menus before the player is asked a single configuration question. This is the code I use in Apolune: Through the Wormhole to do this. It is used on all cutscenes, help panels, game menus, and the main menu. It has the ability to guess which player is doing the "accept" action. It also tries to indicate if a VCS controller is present. The MenuControls struct will return "release" signals for "left", "right", "up", "down", "back", "accept", and "cancel" - and you can also access globally the previous state via global.Menucontrols_old_results if you absolutely need to.
This code is built on top of InputCandySimple. It supports VCS, PC games and can be adapted to other consoles. This code is an example of the code used in Apolune: Through the Wormhole, and allows users to navigate game menus when the game first starts up. Using this they can navigate to a menu option that leads to the customization panels available in ICUI.
- Create an object o_MenuControls.
- In o_MenuControls:Create, call Init_MenuControls()
- In o_MenuControls:BeginStep, call MenuControls_top_of_frame()
- In o_MenuControls:PostDraw, call MenuControls_end_of_frame()
- Include o_MenuControls in any room that will serve as your game menu, and optionally during any cut-scene movie or help screen.
- In any object that controls your menus, cut-scenes or help panel, access in a Step by calling var controls=MenuControls();
- Create a script called "MenuControls" and paste in the following: