Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
pulp::view::KeyMapping Class Reference

Manages keyboard shortcuts with configurable bindings. More...

#include <app_framework.hpp>

Public Member Functions

void add_command (Command cmd)
void remove_command (CommandID id)
bool handle_key (const KeyEvent &event)
 Try to handle a key event by matching against registered shortcuts.
const std::vector< Command > & commands () const
 Get all registered commands.
std::vector< const Command * > commands_in_category (const std::string &category) const
 Get commands in a specific category.
void rebind (CommandID id, KeyShortcut shortcut)
 Rebind a command's shortcut.
bool save_bindings (const std::filesystem::path &path) const
 Save keybindings to a JSON file.
bool load_bindings (const std::filesystem::path &path)
 Load keybindings from a JSON file (overrides defaults).

Detailed Description

Manages keyboard shortcuts with configurable bindings.

keys.add_command({1, "Save", "File", KeyShortcut{KeyCode::s, kModCmd},
[&] { save(); }});
keys.add_command({2, "Undo", "Edit", KeyShortcut{KeyCode::z, kModCmd},
[&] { undo(); }});
// In key event handler:
if (keys.handle_key(event)) return true;
Manages keyboard shortcuts with configurable bindings.
Definition app_framework.hpp:63
void add_command(Command cmd)
bool handle_key(const KeyEvent &event)
Try to handle a key event by matching against registered shortcuts.
@ kModCmd
Command (macOS) — alias for platform primary modifier.
Definition input_events.hpp:21
@ s
Definition input_events.hpp:41
@ z
Definition input_events.hpp:42
A keyboard shortcut (key + modifiers).
Definition app_framework.hpp:23

Member Function Documentation

◆ add_command()

void pulp::view::KeyMapping::add_command ( Command cmd)

◆ commands()

const std::vector< Command > & pulp::view::KeyMapping::commands ( ) const
inline

Get all registered commands.

◆ commands_in_category()

std::vector< const Command * > pulp::view::KeyMapping::commands_in_category ( const std::string & category) const

Get commands in a specific category.

◆ handle_key()

bool pulp::view::KeyMapping::handle_key ( const KeyEvent & event)

Try to handle a key event by matching against registered shortcuts.

Returns
True if a matching command was found and executed.

◆ load_bindings()

bool pulp::view::KeyMapping::load_bindings ( const std::filesystem::path & path)

Load keybindings from a JSON file (overrides defaults).

◆ rebind()

void pulp::view::KeyMapping::rebind ( CommandID id,
KeyShortcut shortcut )

Rebind a command's shortcut.

◆ remove_command()

void pulp::view::KeyMapping::remove_command ( CommandID id)

◆ save_bindings()

bool pulp::view::KeyMapping::save_bindings ( const std::filesystem::path & path) const

Save keybindings to a JSON file.


The documentation for this class was generated from the following file: