Skip to content

KcdMp.onKeyBinding

Registers a function for a key binding the server declared.

A key binding is a named key the game mode declared with its RegisterKeyBinding: it starts on the mode’s default key, and a player can put it on another with the command KcdMp_bind in the game’s F9 window - when the server has opened that window to its players (it is closed by default). fn(pressed) is called with true when the key goes down and false when it comes up, on whichever key the player has it. The name is the binding’s name as the mode declared it - a name is 1 to 64 characters of a-z 0-9 _ . : -, and the mode’s are at most 32.

Every frame of the interface that is ready hears every press; each handler is called only for the name it asked for. The handler only ever runs for a binding the mode has declared: until then the registration is harmless and silent. The game does not get the key while it is bound, and a press is never delivered while a page holds the keyboard, the chat box or the F9 window is open, or one of the game’s own menus is up. A key that went down always gets its release. A page that was not ready when the key went down hears nothing of it, and a press over the frame’s message budget is dropped like any other message - a release never is.

KcdMp.onKeyBinding(name, fn)
Parameter Type
name string the binding’s name
fn (pressed: boolean) => void called on the key’s press and release

() => void - a function that takes the handler off again

KcdMp.onKeyBinding("toggle_map", (pressed) => {
if (pressed) toggleMap();
});

KcdMp.focus · the Focus and visibility group of the index