Keymap module

add_mapping

procedureSource

Binds key with the given modifiers to a registered procedure (is_proc) or a command string. Rebinding the same key and modifiers replaces the old binding. Returns whether it worked, and if not, why. Set respect_ignore_modifier_keys to false to have the binding ignore the keymap's ignore_modifier_keys setting.

Example↗
#import "Input";

set: Keymap_Set;
map := add_keymap(*set, "game");
add_proc(map, "jump", () { /* ... */ });

flags: Event.Modifier_Flags;
ok, reason := add_mapping(map, .SPACEBAR, flags, true, "jump", true);
assert(ok);
ok, reason = add_mapping(map, .ENTER, flags, true, "missing", true);
assert(!ok && reason == .UNKNOWN_COMMAND);
reset_keymaps(*set);
add_mapping :: (
    keymap: *Keymap,
    key: Key_Code,
    modifier_flags: Event.Modifier_Flags,
    respect_ignore_modifier_keys: bool,
    command: string,
    is_proc: bool
) -> (success: bool, error_type: Add_Mapping_Error_Type)

Parameters

keymap: *Keymap
modifier_flags: Event.Modifier_Flags
respect_ignore_modifier_keys: bool
command: string
is_proc: bool

Returns

success: bool

See also