summaryrefslogtreecommitdiff
path: root/Source/Core/InputCommon/ControllerInterface
diff options
context:
space:
mode:
authorMichael Maltese <michael.joseph.maltese@gmail.com>2016-08-09 19:54:59 -0700
committerMichael Maltese <michael.joseph.maltese@gmail.com>2016-08-09 19:54:59 -0700
commitd1594f9529a99f56d7ed3fb4267efe3b893c9ce0 (patch)
treefbaa30e5dd250256c14bfaa0039837444c87568d /Source/Core/InputCommon/ControllerInterface
parenta5cc054bd1a111c00991664e6f7ac42aac092d5b (diff)
use a std::map instead of running through the AOS
Diffstat (limited to 'Source/Core/InputCommon/ControllerInterface')
-rw-r--r--Source/Core/InputCommon/ControllerInterface/Quartz/QuartzKeyboardAndMouse.h1
-rw-r--r--Source/Core/InputCommon/ControllerInterface/Quartz/QuartzKeyboardAndMouse.mm39
2 files changed, 19 insertions, 21 deletions
diff --git a/Source/Core/InputCommon/ControllerInterface/Quartz/QuartzKeyboardAndMouse.h b/Source/Core/InputCommon/ControllerInterface/Quartz/QuartzKeyboardAndMouse.h
index 0f5eafc895..3dd352a003 100644
--- a/Source/Core/InputCommon/ControllerInterface/Quartz/QuartzKeyboardAndMouse.h
+++ b/Source/Core/InputCommon/ControllerInterface/Quartz/QuartzKeyboardAndMouse.h
@@ -24,6 +24,7 @@ private:
private:
CGKeyCode m_keycode;
+ std::string m_name;
};
class Cursor : public Input
diff --git a/Source/Core/InputCommon/ControllerInterface/Quartz/QuartzKeyboardAndMouse.mm b/Source/Core/InputCommon/ControllerInterface/Quartz/QuartzKeyboardAndMouse.mm
index dea495feb9..6827353913 100644
--- a/Source/Core/InputCommon/ControllerInterface/Quartz/QuartzKeyboardAndMouse.mm
+++ b/Source/Core/InputCommon/ControllerInterface/Quartz/QuartzKeyboardAndMouse.mm
@@ -13,20 +13,7 @@ namespace Quartz
{
KeyboardAndMouse::Key::Key(CGKeyCode keycode) : m_keycode(keycode)
{
-}
-
-ControlState KeyboardAndMouse::Key::GetState() const
-{
- return CGEventSourceKeyState(kCGEventSourceStateHIDSystemState, m_keycode) != 0;
-}
-
-std::string KeyboardAndMouse::Key::GetName() const
-{
- static const struct
- {
- const CGKeyCode code;
- const char* const name;
- } named_keys[] = {
+ static const std::map<CGKeyCode, std::string> named_keys = {
{kVK_ANSI_A, "A"},
{kVK_ANSI_B, "B"},
{kVK_ANSI_C, "C"},
@@ -127,18 +114,28 @@ std::string KeyboardAndMouse::Key::GetName() const
{kVK_RightOption, "Right Alt"},
};
- for (auto& named_key : named_keys)
- if (named_key.code == m_keycode)
- return named_key.name;
+ if (named_keys.find(m_keycode) != named_keys.end())
+ m_name = named_keys.at(m_keycode);
+ else
+ m_name = "Key " + std::to_string(m_keycode);
+}
- return "Key " + std::to_string(m_keycode);
+ControlState KeyboardAndMouse::Key::GetState() const
+{
+ return CGEventSourceKeyState(kCGEventSourceStateHIDSystemState, m_keycode) != 0;
+}
+
+std::string KeyboardAndMouse::Key::GetName() const
+{
+ return m_name;
}
KeyboardAndMouse::KeyboardAndMouse(void* window)
{
- // All ANSI keycodes in <HIToolbox/Events.h> are 0x7e or lower
- for (int i = 0; i < 0x80; i++)
- AddInput(new Key(i));
+ // All keycodes in <HIToolbox/Events.h> are 0x7e or lower. If you notice
+ // keys that aren't being recognized, bump this number up!
+ for (int keycode = 0; keycode < 0x80; ++keycode)
+ AddInput(new Key(keycode));
m_windowid = [[reinterpret_cast<NSView*>(window) window] windowNumber];