Resource icon

lib-register-keybinding 0.0.2

For Users:
This mod is used by other mods to add the ability to customize keybindings. Copy the folder from the zip to your Mods folder to install. No other setup is required.

For Developers:
You can add a keybinding to your mod without this mod, but if you want to show the keybinding in the options screen for customizing user's keybindings, you can use this mod to do it.

In a UI Script, you will want to run something like this to register your keybinding, once you have registered it in the database.

JavaScript:
import * as ekm from "/core/ui/options/editors/editor-keyboard-mapping.js";

try {
    const hasLibRegisterKeybindingMod = Modding.getInstalledMods().some(mod => mod.id === 'lib-register-keybinding');

    if (hasLibRegisterKeybindingMod && typeof ekm.registerKey !== 'undefined') {
        ekm.registerKey('my-custom-keybinding-action-id'); // the custom id of your keybinding, as specified in the database
        console.log('MyMod: Registered key-binding in options menu.');
    } else {
        console.error('MyMod: Could not register key-binding in options menu.  Did you remember to include the lib-register-keybinding mod?');
    }
} catch (e) {
    console.error('MyMod: Error registering key-binding in options menu.', e);
}

This setup will allow your mod to continue working if this library is not installed, the user just won't be able to customize the keybinding.

You will also need to run this code in both the shell scope and the game scope if you want it customizable in both places.

It should be noted that users will need to install THIS mod to make it work with your mod, so your mod instruction should tell them to install this mod, too.
  • Like
Reactions: Finwickle
Author
maddachshund
Downloads
245
Views
708
First release
Last update

Ratings

0.00 star(s) 0 ratings

Latest updates

  1. Allow customizing keybindings in shell AND game

    Previous version only allowed registering keybindings in the shell (main menu outside of the...
Back
Top Bottom