7#include "keyboard_key.hpp"
9#include "../os_detect.hpp"
10#include "../command.hpp"
11#include <unordered_map>
34 void add_system_command(command cmd)
noexcept {
35 ttlet i =
std::find(system.cbegin(), system.cend(), cmd);
36 if (i == system.cend()) {
37 system.push_back(cmd);
42 void add_ignored_command(command cmd)
noexcept {
44 if (i == ignored.
cend()) {
50 void add_user_command(command cmd)
noexcept {
52 if (i == user.
cend()) {
58 void update_cache()
noexcept {
59 cache.
reserve(std::ssize(system) + std::ssize(user));
61 for (ttlet cmd: system) {
63 if (i == cache.
cend()) {
68 for (ttlet cmd: ignored) {
70 if (i != cache.
cend()) {
75 for (ttlet cmd: user) {
77 if (i == cache.
cend()) {
92 void addSystemBinding(
keyboard_key key, command command)
noexcept {
93 bindings[key].add_system_command(command);
96 void addIgnoredBinding(
keyboard_key key, command command)
noexcept {
97 bindings[key].add_ignored_command(command);
100 void addUserBinding(
keyboard_key key, command command)
noexcept {
101 bindings[key].add_user_command(command);
109 ttlet i = bindings.
find(key);
110 if (i != bindings.
cend()) {
111 return i->second.get_commands();
113 return empty_commands;
133 if constexpr (OperatingSystem::current == OperatingSystem::Windows) {
140 void loadUserBindings(
URL url) {
Definition keyboard_bindings.hpp:16
void loadBindings(URL url, bool system_binding)
Load bindings from a JSON file.
void saveUserBindings(URL url)
Save user bindings This will save all bindings that are different from the system bindings.
void clear() noexcept
Clear all bindings.
Definition keyboard_bindings.hpp:122
void loadSystemBindings()
Load system bindings.
Definition keyboard_bindings.hpp:132
std::vector< command > const & translate(keyboard_key key) const noexcept
translate a key press in the empty-context to a command.
Definition keyboard_bindings.hpp:106
A key in combination with modifiers.
Definition keyboard_key.hpp:20