simvx.core.shortcuts

Named keyboard shortcuts: a binding, or a chord of two, mapped to a callback.

A shortcut is a binding like any other, Key.CTRL + Key.S, and a key press matches it by the rule every binding is read by: a binding holding a modifier is exact, so Ctrl+S is not Ctrl+Shift+S, and Key.DELETE alone ignores modifiers. A chord is two bindings pressed one after the other, (Key.CTRL + Key.K, Key.CTRL + Key.C).

An editor hears keys in the capture phase and hands each press here, so a shortcut fires ahead of whatever control has focus::

mgr = ShortcutManager()
mgr.register("save", Key.CTRL + Key.S, save)
mgr.register("comment", (Key.CTRL + Key.K, Key.CTRL + Key.C), toggle_comment)

@on_input(KeyEvent, capture=True)
def _shortcut(self, event):
    return (event.pressed and mgr.handle(event)) or None

A player’s rebinds persist through :attr:bindings_map and

meth:

load_bindings, in the engine’s one written spelling ("ctrl+s").

Module Contents

Classes

Shortcut

One registered shortcut: its name, the bindings pressed in turn, and what it does.

ShortcutManager

Registry of named shortcuts, with chords and rebinding.

Data

API

simvx.core.shortcuts.log

‘getLogger(…)’

simvx.core.shortcuts.ShortcutKeys

None

class simvx.core.shortcuts.Shortcut(name: str, steps: tuple[simvx.core.input.events.InputBinding, ...], callback: collections.abc.Callable[[], object], description: str = '', category: str = '')[source]

One registered shortcut: its name, the bindings pressed in turn, and what it does.

Initialization

__slots__

(‘name’, ‘steps’, ‘callback’, ‘description’, ‘category’)

property label: str[source]

What a menu or a palette prints for it: "ctrl+s", a chord as "ctrl+k, ctrl+c".

class simvx.core.shortcuts.ShortcutManager[source]

Registry of named shortcuts, with chords and rebinding.

A name is unique: registering one again replaces it.

Initialization

register(name: str, keys: simvx.core.shortcuts.ShortcutKeys, callback: collections.abc.Callable[[], object], description: str = '', category: str = '') → None[source]

Register (or replace) the shortcut name.

Args: name: Unique identifier, such as "save". keys: A key (Key.F5), a binding (Key.CTRL + Key.S) or a chord of two ((Key.CTRL + Key.K, Key.CTRL + Key.C)). callback: Called with no arguments when it fires. description: For search and display. category: A grouping, such as "File".

unregister(name: str) → None[source]

Remove a shortcut by name. Raises KeyError if not found.

rebind(name: str, keys: simvx.core.shortcuts.ShortcutKeys) → None[source]

Point an existing shortcut at other keys, keeping its callback. KeyError if name is unknown.

handle(event: simvx.core.input.events.KeyEvent) → bool[source]

Fire the shortcut event completes, or start the chord it begins; True when it matched.

Only a press is a shortcut, and an auto-repeat is not a new one.

tick(dt: float) → None[source]

Advance the chord timeout. Call once per frame.

get(name: str) → simvx.core.shortcuts.Shortcut | None[source]

The shortcut registered as name, or None.

search(query: str) → list[simvx.core.shortcuts.Shortcut][source]

The shortcuts whose name, description or category contain query, ignoring case.

property bindings_map: dict[str, Any][source]

{name: spelling} for every shortcut, in the engine’s written form: "ctrl+s", a chord a list.

load_bindings(bindings: collections.abc.Mapping[str, Any]) → None[source]

Rebind registered shortcuts from {name: spelling}, as :attr:bindings_map writes it.

A name nothing registered is skipped; a spelling that is not a key binding is logged and skipped, so one bad entry in a player’s file does not cost them the rest.