Raiyan Toufiq

i want a mod where i can set multiple keybind also support mouse bind in the slot like [c] = [c] + [right mouse button ] + [ ] + [ ] ------> tougle optiion like [ o ] for this one then so on the c = c + right mouse click means if i press c it will register c and mouse right click at the same time and i make more like this also with left click also the mouse side buttons and keyboard button with keyboard button like [ c ] = [ c ] + [b] and all this will only work when we are playing the game like the minecraft's keybind section only works when playing not typing or in gui or others and there will be option to make as many of this thing i want up to 16

and the gui to confiq this mod will open on f8 and there will be no chance to change this f8 from keybind section from option

this mod is for 1.21.11 fabric

Kodari AI
KodariMon at 9:03 pm 4
ComboKeyBinds
ComboKeyBinds is a Fabric mod for Minecraft 1.21.11 that allows players to create up to 16 custom key combinations, triggering multiple inputs simultaneously. Each combo can combine keyboard keys, mouse buttons (left, right, side buttons), and other keyboard keys in any order. Combos only activate during gameplay, not while typing or in GUIs. The configuration GUI opens with F8 (non-rebindable) and lets players assign, edit, and manage their custom key combinations with an intuitive slot-based interface.
  • Add up to 16 mappings, each with a trigger, three output slots, and an optional toggle key.

  • Open the editor with fixed F8; capture keyboard and mouse buttons directly.

  • Save mappings locally and apply them only during focused gameplay.

Built the Fabric 1.21.11 mod. Press F8 in-game to add up to 16 mappings, capture keyboard or mouse buttons, and assign optional toggle keys.

Outputs activate Minecraft keybindings, rather than sending raw input to other applications or mods that bypass Minecraft’s keybinding system.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
gradle.properties
manifest.kod
settings.gradle
Code
7 355
src/client/java/com/kodari/multikeybind/MultiKeybindClient.java
package com.kodari.multikeybind;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.option.KeyBinding;
import net.minecraft.client.util.InputUtil;
import org.lwjgl.glfw.GLFW;

import java.io.Reader;
import java.io.Writer;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class MultiKeybindClient implements ClientModInitializer {
    static final int LIMIT = 16;
    static final Gson GSON = new GsonBuilder().setPrettyPrinting().create();
    static final Path FILE = FabricLoader.getInstance().getConfigDir().resolve("multikeybind.json");
    static Config config = new Config();
    private static final Set<Input> activeOutputs = new HashSet<>();
    private static boolean f8Down;

    public static class Input {
        public boolean mouse;
        public int code;

        public Input(boolean mouse, int code) { this.mouse = mouse; this.code = code; }

        boolean valid() {
            return mouse ? code >= 0 && code <= GLFW.GLFW_MOUSE_BUTTON_LAST
                    : code >= GLFW.GLFW_KEY_SPACE && code <= GLFW.GLFW_KEY_LAST && code != GLFW.GLFW_KEY_F8;
        }

        boolean down(long window) {
            return valid() && (mouse ? GLFW.glfwGetMouseButton(window, code) == GLFW.GLFW_PRESS
                    : GLFW.glfwGetKey(window, code) == GLFW.GLFW_PRESS);
        }

        InputUtil.Key key() {
            return (mouse ? InputUtil.Type.MOUSE : InputUtil.Type.KEYSYM).createFromCode(code);
        }

        String display() {
            if (mouse) return switch (code) {
                case 0 -> "Mouse Left";
                case 1 -> "Mouse Right";
                case 2 -> "Mouse Middle";
                default -> "Mouse " + (code + 1);
            };
            String name = GLFW.glfwGetKeyName(code, 0);
            return name != null ? name.toUpperCase(java.util.Locale.ROOT) : "Key " + code;
        }

        @Override public boolean equals(Object other) {
            return other instanceof Input input && mouse == input.mouse && code == input.code;
        }
        @Override public int hashCode() { return 31 * Boolean.hashCode(mouse) + code; }
    }

    public static class Rule {
        public Input trigger;
        public Input[] outputs = new Input[3];
        public Input toggle;
        public boolean enabled = true;
        transient boolean toggleDown;
    }

    public static class Config {
        public List<Rule> rules = new ArrayList<>();
    }

    @Override public void onInitializeClient() {
        load();
        ClientTickEvents.START_CLIENT_TICK.register(MultiKeybindClient::tick);
    }

    static void save() {
        try {
            Files.createDirectories(FILE.getParent());
            try (Writer writer = Files.newBufferedWriter(FILE)) { GSON.toJson(config, writer); }
        } catch (Exception e) {
            System.err.println("Multi Keybind: could not save configuration: " + e);
        }
    }

    private static void load() {
        if (!Files.exists(FILE)) return;
        try (Reader reader = Files.newBufferedReader(FILE)) {
            Config loaded = GSON.fromJson(reader, Config.class);
            if (loaded == null || loaded.rules == null) return;
            loaded.rules.removeIf(rule -> rule == null);
            if (loaded.rules.size() > LIMIT) loaded.rules = new ArrayList<>(loaded.rules.subList(0, LIMIT));
            for (Rule rule : loaded.rules) {
                if (rule.outputs == null || rule.outputs.length != 3) {
                    Input[] fixed = new Input[3];
                    if (rule.outputs != null) System.arraycopy(rule.outputs, 0, fixed, 0, Math.min(3, rule.outputs.length));
                    rule.outputs = fixed;
                }
            }
            config = loaded;
        } catch (Exception e) {
            System.err.println("Multi Keybind: could not load configuration: " + e);
        }
    }

    private static void tick(MinecraftClient client) {
        long window = client.getWindow().getHandle();
        boolean playing = client.player != null && client.world != null && client.currentScreen == null && client.isWindowFocused();
        boolean f8 = client.isWindowFocused() && GLFW.glfwGetKey(window, GLFW.GLFW_KEY_F8) == GLFW.GLFW_PRESS;
        if (playing && f8 && !f8Down) {
            client.setScreen(new BindScreen());
            playing = false;
        }
        f8Down = f8;

        if (client.currentScreen instanceof BindScreen screen && client.isWindowFocused()) screen.captureTick(window);

        Set<Input> next = new HashSet<>();
        for (Rule rule : config.rules) {
            boolean toggle = playing && rule.toggle != null && rule.toggle.down(window);
            if (toggle && !rule.toggleDown) {
                rule.enabled = !rule.enabled;
                save();
            }
            rule.toggleDown = toggle;
            if (playing && rule.enabled && rule.trigger != null && rule.trigger.down(window)) {
                for (Input output : rule.outputs) if (output != null && output.valid()) next.add(output);
            }
        }

        Set<Input> affected = new HashSet<>(activeOutputs);
        affected.addAll(next);
        for (Input input : affected) {
            boolean physical = playing && input.down(window);
            boolean synthetic = next.contains(input);
            if (synthetic && !activeOutputs.contains(input) && !physical) KeyBinding.onKeyPressed(input.key());
            KeyBinding.setKeyPressed(input.key(), physical || synthetic);
        }
        activeOutputs.clear();
        activeOutputs.addAll(next);
    }
}