openMSX
KeyCodeSetting.cc
Go to the documentation of this file.
1#include "KeyCodeSetting.hh"
2#include "CommandException.hh"
3
4namespace openmsx {
5
7 std::string_view name_, static_string_view description_,
8 Keys::KeyCode initialValue)
9 : Setting(commandController_, name_, description_,
10 TclObject(Keys::getName(initialValue)), SAVE)
11{
12 setChecker([](TclObject& newValue) {
13 const auto& str = newValue.getString();
14 if (Keys::getCode(str) == Keys::K_NONE) {
15 throw CommandException("Not a valid key: ", str);
16 }
17 });
18 init();
19}
20
21std::string_view KeyCodeSetting::getTypeString() const
22{
23 return "key";
24}
25
27{
28 return Keys::getCode(getValue().getString());
29}
30
31} // namespace openmsx
KeyCodeSetting(CommandController &commandController, std::string_view name, static_string_view description, Keys::KeyCode initialValue)
Keys::KeyCode getKey() const noexcept
std::string_view getTypeString() const override
Returns a string describing the setting type (integer, string, ..) Could be used in a GUI to pick an ...
void setChecker(std::function< void(TclObject &)> checkFunc_)
Set value-check-callback.
Definition: Setting.hh:160
const TclObject & getValue() const final
Gets the current value of this setting as a TclObject.
Definition: Setting.hh:142
zstring_view getString() const
Definition: TclObject.cc:120
static_string_view
KeyCode
Constants that identify keys and key modifiers.
Definition: Keys.hh:26
KeyCode getCode(string_view name)
Translate key name to key code.
Definition: Keys.cc:330
std::string getName(KeyCode keyCode)
Translate key code to key name.
Definition: Keys.cc:730
This file implemented 3 utility functions:
Definition: Autofire.cc:9