diff --git a/repos/os/src/server/event_filter/key_code_by_name.h b/repos/os/src/server/event_filter/key_code_by_name.h index 881f9f11a1..a2a975a427 100644 --- a/repos/os/src/server/event_filter/key_code_by_name.h +++ b/repos/os/src/server/event_filter/key_code_by_name.h @@ -36,6 +36,24 @@ namespace Event_filter { } throw Unknown_key(); } + + /* + * \throw Unknown_key + */ + template + void for_each_key_with_name(Key_name const &name, FN const &fn) + { + bool found = false; + for (unsigned i = 0; i < Input::KEY_MAX; i++) { + Input::Keycode const code = Input::Keycode(i); + if (name == Input::key_name(code)) { + fn(code); + found = true; + } + } + if (!found) + throw Unknown_key(); + } } #endif /* _EVENT_FILTER__KEY_CODE_BY_NAME_H_ */ diff --git a/repos/os/src/server/event_filter/remap_source.h b/repos/os/src/server/event_filter/remap_source.h index 2283e974bf..890b5e93cb 100644 --- a/repos/os/src/server/event_filter/remap_source.h +++ b/repos/os/src/server/event_filter/remap_source.h @@ -106,13 +106,13 @@ class Event_filter::Remap_source : public Source, Source::Filter Key_name const key_name = node.attribute_value("name", Key_name()); try { - Input::Keycode const code = key_code_by_name(key_name); - - if (node.has_attribute("to")) { - Key_name const to = node.attribute_value("to", Key_name()); - try { _keys[code].code = key_code_by_name(to); } - catch (Unknown_key) { warning("ignoring remap rule ", node); } - } + for_each_key_with_name(key_name, [&] (Input::Keycode code) { + if (node.has_attribute("to")) { + Key_name const to = node.attribute_value("to", Key_name()); + try { _keys[code].code = key_code_by_name(to); } + catch (Unknown_key) { warning("ignoring remap rule ", node); } + } + }); } catch (Unknown_key) { warning("invalid key name ", key_name); }