.dev

Modules1 min read

Keybinds

Named server actions that players can rebind.

keybind:1Tier A · Decorate

Good for

  • Party, emote and map keys without chat commands
  • Abilities bound to keys players choose
  • Push-to-ping with how long the key was held

Declare named actions with default keys. They appear in Settings -> Servers under your server's name, where players can rebind them, and presses come back to you. You never need a client mod or a chat command for "open party menu".

Register

Java
teho.keybinds().register("Skyline", Arrays.asList(
        Keybind.builder("party", "Party menu").key('P').description("Open your party").build(),
        Keybind.builder("emote", "Emote").key('B').build(),
        Keybind.builder("ping", "Ping location").key(342).build()));

The first argument is the category heading players see. 342 is GLFW's left Alt key code. Registering again replaces the list.

MethodNotes
builder(id, label)Both required.
key(char)A letter or digit.
key(int)A GLFW key code, for keys that are not letters or digits. Keybind.UNBOUND leaves it unbound.
hold(boolean)Marks the action as one players hold rather than tap.
description(String)Shown under the label in settings.
controller(String)A default controller button.

registered() returns what you registered and clear() removes them.

Handle presses

Java
@EventHandler
public void onKey(TehoKeyEvent event) {
    if (event.getKeybind().equals("party") && event.isPressed()) {
        openPartyMenu(event.getPlayer());
    }
    if (event.getKeybind().equals("ping") && !event.isPressed()) {
        pingLocation(event.getPlayer(), event.getHeldMs());
    }
}

Every action reports both the press and the release, and the release carries how long the key was held. Elsewhere use TehoListener.onKey(player, keybind, pressed, heldMs).