geode.Keybind reads and writes key combinations. A keybind is a plain table.
| Field | Type | Notes |
|---|---|---|
key |
number | a key code |
modifiers |
number | a bit mask of held modifier keys |
Use geode.cocos.enumKeyCodes.KEY_* values for key.
Use geode.KeyboardModifier constants for modifiers.
fromString returns nil and an error message on a bad string.
See globals Error shapes.
geode.Keybind.fromString(str: string) -> ({ key: number, modifiers: number }?, string?)Parses a string such as "Ctrl+A" into a keybind.
Modifier and key tokens use + with no spaces.
Returns the keybind, or nil and an error message.
geode.Keybind.toString(keybind: { key: number, modifiers: number }) -> stringTurns a keybind back into a readable string.
geode.Keybind.createNode(keybind: { key: number, modifiers: number }) -> CCNode?Builds a node that shows the keybind. Returns the node, or nil if it could not be made.
local kb, err = geode.Keybind.fromString("Ctrl+A")
if not kb then return print(err) end
print(geode.Keybind.toString(kb)) -- Ctrl+A
local node = geode.Keybind.createNode(kb)
if node then someMenu:addChild(node) endsrc/bindings/geode/GeodeSmallBindings.cpp