From 0f5951e324f2685e25f04c353d14b348fc6ba6f6 Mon Sep 17 00:00:00 2001 From: Michael Maltese Date: Tue, 9 Aug 2016 19:59:45 -0700 Subject: [PATCH] And pull KeycodeToName into its own function --- .../Quartz/QuartzKeyboardAndMouse.h | 3 +++ .../Quartz/QuartzKeyboardAndMouse.mm | 14 +++++++++----- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/Source/Core/InputCommon/ControllerInterface/Quartz/QuartzKeyboardAndMouse.h b/Source/Core/InputCommon/ControllerInterface/Quartz/QuartzKeyboardAndMouse.h index 3dd352a003..5c0daa6846 100644 --- a/Source/Core/InputCommon/ControllerInterface/Quartz/QuartzKeyboardAndMouse.h +++ b/Source/Core/InputCommon/ControllerInterface/Quartz/QuartzKeyboardAndMouse.h @@ -12,6 +12,9 @@ namespace ciface { namespace Quartz { + +std::string KeycodeToName(const CGKeyCode keycode); + class KeyboardAndMouse : public Core::Device { private: diff --git a/Source/Core/InputCommon/ControllerInterface/Quartz/QuartzKeyboardAndMouse.mm b/Source/Core/InputCommon/ControllerInterface/Quartz/QuartzKeyboardAndMouse.mm index 6827353913..18f3e553f3 100644 --- a/Source/Core/InputCommon/ControllerInterface/Quartz/QuartzKeyboardAndMouse.mm +++ b/Source/Core/InputCommon/ControllerInterface/Quartz/QuartzKeyboardAndMouse.mm @@ -11,8 +11,8 @@ namespace ciface { namespace Quartz { -KeyboardAndMouse::Key::Key(CGKeyCode keycode) : m_keycode(keycode) -{ + +std::string KeycodeToName(const CGKeyCode keycode) { static const std::map named_keys = { {kVK_ANSI_A, "A"}, {kVK_ANSI_B, "B"}, @@ -114,10 +114,14 @@ KeyboardAndMouse::Key::Key(CGKeyCode keycode) : m_keycode(keycode) {kVK_RightOption, "Right Alt"}, }; - if (named_keys.find(m_keycode) != named_keys.end()) - m_name = named_keys.at(m_keycode); + if (named_keys.find(keycode) != named_keys.end()) + return named_keys.at(keycode); 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