Key Mappings
dev.architectury.registry.client.keymappings.KeyMappingRegistry
Register a configurable hotkey (a KeyMapping) that appears in the vanilla Controls screen.
Registering a key
// Categories are registered objects, identified by a namespaced id:
public static final KeyMapping.Category MY_CATEGORY =
KeyMapping.Category.register(Identifier.fromNamespaceAndPath(MyMod.MOD_ID, "main"));
public static final KeyMapping MY_KEY = new KeyMapping(
"key.mymod.do_thing", // translation key for the binding's name
InputConstants.Type.KEYBOARD, // input device
InputConstants.KEY_K, // default key
MY_CATEGORY
);
KeyMappingRegistry.register(MY_KEY);
Register from client-side code. Since Minecraft 26.3 a category is a registered KeyMapping.Category
identified by a namespaced id, rather than a raw translation key string; vanilla derives the name
shown in the Controls screen from that id.
Reacting to the key
Check the mapping during a client tick - consumeClick() returns true once per press:
ClientTickEvent.CLIENT_POST.register(minecraft -> {
while (MY_KEY.consumeClick()) {
// the player pressed your key
}
});
See Client Tick Events.
Changed in 26.3
InputConstants.Type.KEYSYM was renamed to InputConstants.Type.KEYBOARD in Minecraft 26.3. Key
codes are available as InputConstants.KEY_* constants, so a direct GLFW dependency is no longer
needed.