-
Notifications
You must be signed in to change notification settings - Fork 49
Keybinds system
Oen44 edited this page Oct 7, 2024
·
2 revisions
- Arrow keys are reserved and can NOT be used
- Default keybinds can NOT share keys (you will be warned if it occurs)
- Not every keybind is currently added, contributions in that matter are welcome
- Some OTC keybinds are bound to UI/UX and should not be part of this Keybinds system
- Action Bar is currently (yet) not integrated
Best place to add is init
(or whatever onLoad
executes) of your module.
Keybind.new(category, action, primary, secondary, alone)
- category (string) - category name, eg. "Dialogs"
- action (string) - action name, eg. "Open Options" (creating "Dialogs: Open Options" name)
- primary (string | table) - default primary key to trigger action, if used as string (can be empty but not nil), it will be applied to both Chat Modes, otherwise use table:
{
[CHAT_MODE.ON] = "key", (can be empty)
[CHAT_MODE.OFF] = "key" (can be empty)
}
- secondary (string | table) - same as primary key
- alone (bool, optional) - if true, action can be bound to only single key without modifiers (Ctrl, Alt, Shift)
Keybind.new("Dialogs", "Open Options", "Ctrl+O", "")
Keybind.new("Chat", "Send current chat line", { [CHAT_MODE.ON] = "Enter", [CHAT_MODE.OFF] = "" }, "") -- table for primary, string for secondary
Keybind.new("Movement", "Go North", {[CHAT_MODE.ON] = "", [CHAT_MODE.OFF] = "W"}, {[CHAT_MODE.ON] = "Numpad8", [CHAT_MODE.OFF] = ""}, true)
Creating keybinds is not enough, you have to make them do something. Binding is separated for multiple reasons but the most important one is that not everything is ready and loaded when client starts, some modules require player to enter the game to bind the keys. Must be used AFTER Keybind.new
.
Keybind.bind(category, action, callbacks, widget)
- category (string) - category name, eg. "Dialogs"
- action (string) - action name, eg. "Open Options"
- callbacks (table) - table with table of config values:
{
{
type = (KEY_DOWN | KEY_UP | KEY_PRESS),
callback = (function),
alone = (bool)
},
-- can be multiple (see game_walking)
{
type = (KEY_DOWN | KEY_UP | KEY_PRESS),
callback = (function),
alone = (bool)
}
}
- widget (UIWidget, optional) - widget that should listen to key events (if not provided it will default to Root)
Keybind.bind("UI", "Toggle Full Map", {
{
type = KEY_DOWN,
callback = toggleFullMap,
}
})
Keybind.bind("Movement", "Go " .. DirectionString[North], {
{
type = KEY_DOWN,
callback = function() changeWalkDir(dir) end,
alone = true
},
{
type = KEY_UP,
callback = function() changeWalkDir(dir, true) end,
alone = true
},
{
type = KEY_PRESS,
callback = function(c, k, ticks) smartWalk(dir, ticks) end
}
}, gameRootPanel)
Best place to add is terminate
(or whatever onUnload
executes) of your module. This is required, altho there is a check to prevent duplicate Keybinds, it is better to delete unused one before they readded in init
or somewhere.
Keybind.delete(category, action)
- category (string) - category name, eg. "Dialogs"
- action (string) - action name, eg. "Open Options"
Keybind.delete("Dialogs", "Open Options")