Keybinds
Client only. Your resource's actions in the game's Settings > Key bindings. Each appears among the game's actions, in one of the game's categories, 'general', 'movement', 'combat', 'chat', 'qam', 'gui', 'photomode' or 'other', or your own, and players rebind it like a game action. The game keeps all actions on separate keys. Choices are saved on the player's computer per server, in %LOCALAPPDATA%\KCDS\keybinds, never in the game's profile, and return when they rejoin. The screen lists only keyboard and mouse keys, so a controller button is the default, or what your script sets with set(). Handlers fire as for Key.bind: in a world, with the game window active and no chat or web view taking typed text. Key names are those of Key. The mouse wheel and keys KCDS does not poll can be chosen but fire nothing. A stopping resource's actions leave the screen.
keybinds.addCategory()
Keybinds.addCategory(id, label)Adds your own category to the key binding screen, after the game's. Adding it again changes its label. Throws a TypeError for an id other than 1 to 24 lower-case letters, digits and single underscores, or an empty label.
keybinds.add()
Keybinds.add(id, options = {})Adds an action to the screen, or changes one you added, keeping its handlers. It starts on its default key until the player or set() picks another. Throws for an id like addCategory's, an empty label, an unknown category, a controller button given as key, a key given as controller, or going past 256 actions across all resources.
keybinds.remove()
Keybinds.remove(id)Removes one of your actions from the screen, and its handlers stop. The player's choice stays saved for when you add it again. Returns false if you have no such action.
keybinds.get()
Keybinds.get(id)One of your actions as now bound, or null: { id, label, category, key, keys, controller, defaultKey, defaultController }. `key` is the first key or null, `keys` lists all the player chose by Key name, and `controller` is a button name or null.
keybinds.list()
Keybinds.list()All actions your resource added, in the form get() gives.
keybinds.categories()
Keybinds.categories()Categories your actions can use: the game's eight, then those your resource added.
keybinds.set()
Keybinds.set(id, binding = {})Binds one of your actions for the player, as if chosen on the screen. The key shows there, and the choice is saved for this server. Fields left out stay as they are, and null unbinds. Use it for your own settings page, and it is the only way to change a controller button. Throws for an action you did not add, a controller button given as key, or a key given as controller.
keybinds.reset()
Keybinds.reset(id)Returns one of your actions to its default key and controller button, forgetting the player's choice. Throws for an action you did not add.
keybinds.on()
Keybinds.on(id, stateOrHandler, handler)Calls a handler when the action's key or controller button goes down, up or both, following whatever the player binds. The handler receives (id, 'down' or 'up'). Throws for an action you did not add.
keybinds.off()
Keybinds.off(id, state, handler)Removes your handlers of an action, or only those of one state or handler, if given. Returns true if one was removed.