And pull KeycodeToName into its own function

This commit is contained in:
Michael Maltese 2016-08-09 19:59:45 -07:00
parent d1594f9529
commit 0f5951e324
2 changed files with 12 additions and 5 deletions

View File

@ -12,6 +12,9 @@ namespace ciface
{ {
namespace Quartz namespace Quartz
{ {
std::string KeycodeToName(const CGKeyCode keycode);
class KeyboardAndMouse : public Core::Device class KeyboardAndMouse : public Core::Device
{ {
private: private:

View File

@ -11,8 +11,8 @@ namespace ciface
{ {
namespace Quartz namespace Quartz
{ {
KeyboardAndMouse::Key::Key(CGKeyCode keycode) : m_keycode(keycode)
{ std::string KeycodeToName(const CGKeyCode keycode) {
static const std::map<CGKeyCode, std::string> named_keys = { static const std::map<CGKeyCode, std::string> named_keys = {
{kVK_ANSI_A, "A"}, {kVK_ANSI_A, "A"},
{kVK_ANSI_B, "B"}, {kVK_ANSI_B, "B"},
@ -114,10 +114,14 @@ KeyboardAndMouse::Key::Key(CGKeyCode keycode) : m_keycode(keycode)
{kVK_RightOption, "Right Alt"}, {kVK_RightOption, "Right Alt"},
}; };
if (named_keys.find(m_keycode) != named_keys.end()) if (named_keys.find(keycode) != named_keys.end())
m_name = named_keys.at(m_keycode); return named_keys.at(keycode);
else else
m_name = "Key " + std::to_string(m_keycode); return "Key " + std::to_string(keycode);
}
KeyboardAndMouse::Key::Key(CGKeyCode keycode) : m_keycode(keycode), m_name(KeycodeToName(keycode))
{
} }
ControlState KeyboardAndMouse::Key::GetState() const ControlState KeyboardAndMouse::Key::GetState() const