diff --git a/Source/Core/InputCommon/Src/ControllerInterface/OSX/NamedKeys.h b/Source/Core/InputCommon/Src/ControllerInterface/OSX/NamedKeys.h new file mode 100644 index 0000000000..961e9ad795 --- /dev/null +++ b/Source/Core/InputCommon/Src/ControllerInterface/OSX/NamedKeys.h @@ -0,0 +1,174 @@ +{ kHIDUsage_KeyboardErrorRollOver, "ErrorRollOver" }, +{ kHIDUsage_KeyboardPOSTFail, "POSTFail" }, +{ kHIDUsage_KeyboardErrorUndefined, "ErrorUndefined" }, +{ kHIDUsage_KeyboardA, "A" }, +{ kHIDUsage_KeyboardB, "B" }, +{ kHIDUsage_KeyboardC, "C" }, +{ kHIDUsage_KeyboardD, "D" }, +{ kHIDUsage_KeyboardE, "E" }, +{ kHIDUsage_KeyboardF, "F" }, +{ kHIDUsage_KeyboardG, "G" }, +{ kHIDUsage_KeyboardH, "H" }, +{ kHIDUsage_KeyboardI, "I" }, +{ kHIDUsage_KeyboardJ, "J" }, +{ kHIDUsage_KeyboardK, "K" }, +{ kHIDUsage_KeyboardL, "L" }, +{ kHIDUsage_KeyboardM, "M" }, +{ kHIDUsage_KeyboardN, "N" }, +{ kHIDUsage_KeyboardO, "O" }, +{ kHIDUsage_KeyboardP, "P" }, +{ kHIDUsage_KeyboardQ, "Q" }, +{ kHIDUsage_KeyboardR, "R" }, +{ kHIDUsage_KeyboardS, "S" }, +{ kHIDUsage_KeyboardT, "T" }, +{ kHIDUsage_KeyboardU, "U" }, +{ kHIDUsage_KeyboardV, "V" }, +{ kHIDUsage_KeyboardW, "W" }, +{ kHIDUsage_KeyboardX, "X" }, +{ kHIDUsage_KeyboardY, "Y" }, +{ kHIDUsage_KeyboardZ, "Z" }, +{ kHIDUsage_Keyboard1, "1" }, +{ kHIDUsage_Keyboard2, "2" }, +{ kHIDUsage_Keyboard3, "3" }, +{ kHIDUsage_Keyboard4, "4" }, +{ kHIDUsage_Keyboard5, "5" }, +{ kHIDUsage_Keyboard6, "6" }, +{ kHIDUsage_Keyboard7, "7" }, +{ kHIDUsage_Keyboard8, "8" }, +{ kHIDUsage_Keyboard9, "9" }, +{ kHIDUsage_Keyboard0, "0" }, +{ kHIDUsage_KeyboardReturnOrEnter, "Return" }, +{ kHIDUsage_KeyboardEscape, "Escape" }, +{ kHIDUsage_KeyboardDeleteOrBackspace, "Delete" }, +{ kHIDUsage_KeyboardTab, "Tab" }, +{ kHIDUsage_KeyboardSpacebar, "Spacebar" }, +{ kHIDUsage_KeyboardHyphen, "-" }, +{ kHIDUsage_KeyboardEqualSign, "=" }, +{ kHIDUsage_KeyboardOpenBracket, "[" }, +{ kHIDUsage_KeyboardCloseBracket, "]" }, +{ kHIDUsage_KeyboardBackslash, "\\" }, +{ kHIDUsage_KeyboardNonUSPound, "Non-US #" }, +{ kHIDUsage_KeyboardSemicolon, ";" }, +{ kHIDUsage_KeyboardQuote, "'" }, +{ kHIDUsage_KeyboardGraveAccentAndTilde, "Tilde" }, +{ kHIDUsage_KeyboardComma, "," }, +{ kHIDUsage_KeyboardPeriod, "." }, +{ kHIDUsage_KeyboardSlash, "/" }, +{ kHIDUsage_KeyboardCapsLock, "Caps Lock" }, +{ kHIDUsage_KeyboardF1, "F1" }, +{ kHIDUsage_KeyboardF2, "F2" }, +{ kHIDUsage_KeyboardF3, "F3" }, +{ kHIDUsage_KeyboardF4, "F4" }, +{ kHIDUsage_KeyboardF5, "F5" }, +{ kHIDUsage_KeyboardF6, "F6" }, +{ kHIDUsage_KeyboardF7, "F7" }, +{ kHIDUsage_KeyboardF8, "F8" }, +{ kHIDUsage_KeyboardF9, "F9" }, +{ kHIDUsage_KeyboardF10, "F10" }, +{ kHIDUsage_KeyboardF11, "F11" }, +{ kHIDUsage_KeyboardF12, "F12" }, +{ kHIDUsage_KeyboardPrintScreen, "Print Screen" }, +{ kHIDUsage_KeyboardScrollLock, "Scroll Lock" }, +{ kHIDUsage_KeyboardPause, "Pause" }, +{ kHIDUsage_KeyboardInsert, "Insert" }, +{ kHIDUsage_KeyboardHome, "Home" }, +{ kHIDUsage_KeyboardPageUp, "Page Up" }, +{ kHIDUsage_KeyboardDeleteForward, "Delete Forward" }, +{ kHIDUsage_KeyboardEnd, "End" }, +{ kHIDUsage_KeyboardPageDown, "Page Down" }, +{ kHIDUsage_KeyboardRightArrow, "Right Arrow" }, +{ kHIDUsage_KeyboardLeftArrow, "Left Arrow" }, +{ kHIDUsage_KeyboardDownArrow, "Down Arrow" }, +{ kHIDUsage_KeyboardUpArrow, "Up Arrow" }, +{ kHIDUsage_KeypadNumLock, "Keypad Clear" }, +{ kHIDUsage_KeypadSlash, "Keypad /" }, +{ kHIDUsage_KeypadAsterisk, "Keypad *" }, +{ kHIDUsage_KeypadHyphen, "Keypad -" }, +{ kHIDUsage_KeypadPlus, "Keypad +" }, +{ kHIDUsage_KeypadEnter, "Keypad Enter" }, +{ kHIDUsage_Keypad1, "Keypad 1" }, +{ kHIDUsage_Keypad2, "Keypad 2" }, +{ kHIDUsage_Keypad3, "Keypad 3" }, +{ kHIDUsage_Keypad4, "Keypad 4" }, +{ kHIDUsage_Keypad5, "Keypad 5" }, +{ kHIDUsage_Keypad6, "Keypad 6" }, +{ kHIDUsage_Keypad7, "Keypad 7" }, +{ kHIDUsage_Keypad8, "Keypad 8" }, +{ kHIDUsage_Keypad9, "Keypad 9" }, +{ kHIDUsage_Keypad0, "Keypad 0" }, +{ kHIDUsage_KeypadPeriod, "Keypad ." }, +{ kHIDUsage_KeyboardNonUSBackslash, "Non-US \\" }, +{ kHIDUsage_KeyboardApplication, "Application" }, +{ kHIDUsage_KeyboardPower, "Power" }, +{ kHIDUsage_KeypadEqualSign, "Keypad =" }, +{ kHIDUsage_KeyboardF13, "F13" }, +{ kHIDUsage_KeyboardF14, "F14" }, +{ kHIDUsage_KeyboardF15, "F15" }, +{ kHIDUsage_KeyboardF16, "F16" }, +{ kHIDUsage_KeyboardF17, "F17" }, +{ kHIDUsage_KeyboardF18, "F18" }, +{ kHIDUsage_KeyboardF19, "F19" }, +{ kHIDUsage_KeyboardF20, "F20" }, +{ kHIDUsage_KeyboardF21, "F21" }, +{ kHIDUsage_KeyboardF22, "F22" }, +{ kHIDUsage_KeyboardF23, "F23" }, +{ kHIDUsage_KeyboardF24, "F24" }, +{ kHIDUsage_KeyboardExecute, "Execute" }, +{ kHIDUsage_KeyboardHelp, "Help" }, +{ kHIDUsage_KeyboardMenu, "Menu" }, +{ kHIDUsage_KeyboardSelect, "Select" }, +{ kHIDUsage_KeyboardStop, "Stop" }, +{ kHIDUsage_KeyboardAgain, "Again" }, +{ kHIDUsage_KeyboardUndo, "Undo" }, +{ kHIDUsage_KeyboardCut, "Cut" }, +{ kHIDUsage_KeyboardCopy, "Copy" }, +{ kHIDUsage_KeyboardPaste, "Paste" }, +{ kHIDUsage_KeyboardFind, "Find" }, +{ kHIDUsage_KeyboardMute, "Mute" }, +{ kHIDUsage_KeyboardVolumeUp, "Volume Up" }, +{ kHIDUsage_KeyboardVolumeDown, "Volume Down" }, +{ kHIDUsage_KeyboardLockingCapsLock, "Locking Caps Lock" }, +{ kHIDUsage_KeyboardLockingNumLock, "Locking Num Lock" }, +{ kHIDUsage_KeyboardLockingScrollLock, "Locking Scroll Lock" }, +{ kHIDUsage_KeypadComma, "Keypad Comma" }, +{ kHIDUsage_KeypadEqualSignAS400, "Keypad Equal Sign for AS/400" }, +{ kHIDUsage_KeyboardInternational1, "International1" }, +{ kHIDUsage_KeyboardInternational2, "International2" }, +{ kHIDUsage_KeyboardInternational3, "International3" }, +{ kHIDUsage_KeyboardInternational4, "International4" }, +{ kHIDUsage_KeyboardInternational5, "International5" }, +{ kHIDUsage_KeyboardInternational6, "International6" }, +{ kHIDUsage_KeyboardInternational7, "International7" }, +{ kHIDUsage_KeyboardInternational8, "International8" }, +{ kHIDUsage_KeyboardInternational9, "International9" }, +{ kHIDUsage_KeyboardLANG1, "LANG1" }, +{ kHIDUsage_KeyboardLANG2, "LANG2" }, +{ kHIDUsage_KeyboardLANG3, "LANG3" }, +{ kHIDUsage_KeyboardLANG4, "LANG4" }, +{ kHIDUsage_KeyboardLANG5, "LANG5" }, +{ kHIDUsage_KeyboardLANG6, "LANG6" }, +{ kHIDUsage_KeyboardLANG7, "LANG7" }, +{ kHIDUsage_KeyboardLANG8, "LANG8" }, +{ kHIDUsage_KeyboardLANG9, "LANG9" }, +{ kHIDUsage_KeyboardAlternateErase, "AlternateErase" }, +{ kHIDUsage_KeyboardSysReqOrAttention, "SysReq/Attention" }, +{ kHIDUsage_KeyboardCancel, "Cancel" }, +{ kHIDUsage_KeyboardClear, "Clear" }, +{ kHIDUsage_KeyboardPrior, "Prior" }, +{ kHIDUsage_KeyboardReturn, "Return" }, +{ kHIDUsage_KeyboardSeparator, "Separator" }, +{ kHIDUsage_KeyboardOut, "Out" }, +{ kHIDUsage_KeyboardOper, "Oper" }, +{ kHIDUsage_KeyboardClearOrAgain, "Clear/Again" }, +{ kHIDUsage_KeyboardCrSelOrProps, "CrSel/Props" }, +{ kHIDUsage_KeyboardExSel, "ExSel" }, +/* 0xA5-0xDF Reserved */ +{ kHIDUsage_KeyboardLeftControl, "Left Control" }, +{ kHIDUsage_KeyboardLeftShift, "Left Shift" }, +{ kHIDUsage_KeyboardLeftAlt, "Left Alt" }, +{ kHIDUsage_KeyboardLeftGUI, "Left GUI" }, +{ kHIDUsage_KeyboardRightControl, "Right Control" }, +{ kHIDUsage_KeyboardRightShift, "Right Shift" }, +{ kHIDUsage_KeyboardRightAlt, "Right Alt" }, +{ kHIDUsage_KeyboardRightGUI, "Right GUI" }, +/* 0x4E - 0xFFFF Reserved */ \ No newline at end of file diff --git a/Source/Core/InputCommon/Src/ControllerInterface/OSX/OSX.h b/Source/Core/InputCommon/Src/ControllerInterface/OSX/OSX.h index 61acd0174b..02e65bd609 100644 --- a/Source/Core/InputCommon/Src/ControllerInterface/OSX/OSX.h +++ b/Source/Core/InputCommon/Src/ControllerInterface/OSX/OSX.h @@ -11,84 +11,33 @@ namespace OSX void Init( std::vector& devices ); void DeInit(); -class KeyboardMouse : public ControllerInterface::Device +class Keyboard : public ControllerInterface::Device { friend class ControllerInterface; friend class ControllerInterface::ControlReference; protected: - struct State - { - Boolean *keyboard_keys; - }; - class Input : public ControllerInterface::Device::Input { - friend class KeyboardMouse; + friend class Keyboard; protected: - virtual ControlState GetState( const State* const state ) = 0; - }; - - class Output : public ControllerInterface::Device::Output - { - friend class KeyboardMouse; - protected: - virtual void SetState( const ControlState state, unsigned char* const state_out ) = 0; + virtual ControlState GetState() = 0; }; class Key : public Input { - friend class KeyboardMouse; + friend class Keyboard; public: std::string GetName() const; protected: Key( IOHIDElementRef key_element ); - ControlState GetState( const State* const state ); + ControlState GetState(); private: IOHIDElementRef m_key_element; std::string m_key_name; }; - class Button : public Input - { - friend class KeyboardMouse; - public: - std::string GetName() const; - protected: - Button( IOHIDElementRef button_element ); - ControlState GetState( const State* const state ); - private: - IOHIDElementRef m_button_element; - std::string m_button_name; - }; - - class Axis : public Input - { - friend class KeyboardMouse; - public: - std::string GetName() const; - protected: - Axis( IOHIDElementRef button_element ); - ControlState GetState( const State* const state ); - private: - IOHIDElementRef m_axis_element; - std::string m_axis_name; - }; - - class Light : public Output - { - friend class KeyboardMouse; - public: - std::string GetName() const; - protected: - Light( IOHIDElementRef light_element ); - void SetState( const ControlState state, unsigned char* const state_out ); - private: - IOHIDElementRef m_light_element; - std::string m_light_name; - }; - bool UpdateInput(); bool UpdateOutput(); @@ -96,17 +45,16 @@ protected: void SetOutputState( const ControllerInterface::Device::Output* const output, const ControlState state ); public: - KeyboardMouse(IOHIDDeviceRef device); + Keyboard(IOHIDDeviceRef device, int index); std::string GetName() const; std::string GetSource() const; int GetId() const; private: - State m_state_in; - unsigned char m_state_out[6]; // ugly - IOHIDDeviceRef m_device; - std::string m_device_name; + IOHIDDeviceRef m_device; + int m_device_index; + std::string m_device_name; }; } diff --git a/Source/Core/InputCommon/Src/ControllerInterface/OSX/OSX.mm b/Source/Core/InputCommon/Src/ControllerInterface/OSX/OSX.mm index cd6c533fb5..7107a314df 100644 --- a/Source/Core/InputCommon/Src/ControllerInterface/OSX/OSX.mm +++ b/Source/Core/InputCommon/Src/ControllerInterface/OSX/OSX.mm @@ -11,23 +11,12 @@ namespace ciface namespace OSX { -struct PrettyLights -{ - const uint32_t code; - const char* const name; -} named_lights[] = -{ - { kHIDUsage_LED_NumLock, "Num Lock" }, - { kHIDUsage_LED_CapsLock, "Caps Lock" }, - { kHIDUsage_LED_ScrollLock, "Scroll Lock" }, - { kHIDUsage_LED_Compose, "Compose" }, - { kHIDUsage_LED_Kana, "Kana" }, - { kHIDUsage_LED_Power, "Power" } -}; static IOHIDManagerRef HIDManager = NULL; static CFStringRef OurRunLoop = CFSTR("DolphinOSXInput"); +unsigned int KeyboardIndex = 0; + static void DeviceMatching_callback(void* inContext, IOReturn inResult, @@ -39,12 +28,21 @@ static void DeviceMatching_callback(void* inContext, // Add to the devices vector if it's of a type we want if (IOHIDDeviceConformsTo(inIOHIDDeviceRef, kHIDPage_GenericDesktop, kHIDUsage_GD_Keyboard) || - IOHIDDeviceConformsTo(inIOHIDDeviceRef, kHIDPage_GenericDesktop, kHIDUsage_GD_Keypad)/* || - IOHIDDeviceConformsTo(inIOHIDDeviceRef, kHIDPage_GenericDesktop, kHIDUsage_GD_Mouse)*/) + IOHIDDeviceConformsTo(inIOHIDDeviceRef, kHIDPage_GenericDesktop, kHIDUsage_GD_Keypad)) { std::vector *devices = (std::vector *)inContext; - devices->push_back(new KeyboardMouse(inIOHIDDeviceRef)); + devices->push_back(new Keyboard(inIOHIDDeviceRef, KeyboardIndex++)); } + /* + // One of the built-in mice devices insta-crash :( + else if (IOHIDDeviceConformsTo(inIOHIDDeviceRef, kHIDPage_GenericDesktop, kHIDUsage_GD_Mouse)) + { + } + // Probably just a lot of fiddling...but then we can kill SDL dependency (?) + else if (IOHIDDeviceConformsTo(inIOHIDDeviceRef, kHIDPage_GenericDesktop, kHIDUsage_GD_GamePad)) + { + } + */ else { // Actually, we don't want it @@ -175,165 +173,6 @@ void DeviceElementDebugPrint(const void *value, void *context) } } - -KeyboardMouse::KeyboardMouse(IOHIDDeviceRef device) - : m_device(device) -{ - m_device_name = [(NSString *)IOHIDDeviceGetProperty(m_device, CFSTR(kIOHIDProductKey)) UTF8String]; - - // Go through all the elements of the device we've been given and try to make something out of them - CFArrayRef elements = IOHIDDeviceCopyMatchingElements(m_device, NULL, kIOHIDOptionsTypeNone); - CFIndex idx = 0; - for (IOHIDElementRef e = (IOHIDElementRef)CFArrayGetValueAtIndex(elements, idx); - e; - e = (IOHIDElementRef)CFArrayGetValueAtIndex(elements, ++idx)) - { - if ((IOHIDElementGetType(e) == kIOHIDElementTypeInput_Button) && - (IOHIDElementGetUsagePage(e) == kHIDPage_KeyboardOrKeypad) && - (IOHIDElementGetLogicalMin(e) == 0) && - (IOHIDElementGetLogicalMax(e) == 1)) - { - inputs.push_back(new Key(e)); - } - else if((IOHIDElementGetType(e) == kIOHIDElementTypeOutput) && - (IOHIDElementGetUsagePage(e) == kHIDPage_LEDs) && - (IOHIDElementGetLogicalMin(e) == 0) && - (IOHIDElementGetLogicalMax(e) == 1)) - { - outputs.push_back(new Light(e)); - } - else - { -// DeviceElementDebugPrint(e, NULL); - } - - } - CFRelease(elements); -} - -ControlState KeyboardMouse::GetInputState( const ControllerInterface::Device::Input* const input ) -{ - return ((Input*)input)->GetState( &m_state_in ); -} - -void KeyboardMouse::SetOutputState( const ControllerInterface::Device::Output* const output, const ControlState state ) -{ - ((Output*)output)->SetState(state, m_state_out); -} - -bool KeyboardMouse::UpdateInput() -{ - return true; -} - -bool KeyboardMouse::UpdateOutput() -{ - return true; -} - -std::string KeyboardMouse::GetName() const -{ - return m_device_name; -} - -std::string KeyboardMouse::GetSource() const -{ - return "OSX"; -} - -int KeyboardMouse::GetId() const -{ - return 0; -} - - -KeyboardMouse::Key::Key(IOHIDElementRef key_element) - : m_key_element(key_element) -{ - std::ostringstream s; - s << IOHIDElementGetUsage(m_key_element); - m_key_name = s.str(); -} - -ControlState KeyboardMouse::Key::GetState( const State* const state ) -{ - IOHIDValueRef value; - if (IOHIDDeviceGetValue(IOHIDElementGetDevice(m_key_element), m_key_element, &value) == kIOReturnSuccess) - { - double scaled_value = IOHIDValueGetScaledValue(value, kIOHIDValueScaleTypePhysical); - //NSLog(@"element %x value %x scaled %f", IOHIDElementGetUsage(m_key_element), value, scaled_value); - return scaled_value > 0; - } - - return false; -} - -std::string KeyboardMouse::Key::GetName() const -{ - return m_key_name; -} - - -KeyboardMouse::Button::Button(IOHIDElementRef button_element) -: m_button_element(button_element) -{ - std::ostringstream s; - s << IOHIDElementGetUsage(m_button_element); - m_button_name = s.str(); -} - -ControlState KeyboardMouse::Button::GetState( const State* const state ) -{ - return false; -} - -std::string KeyboardMouse::Button::GetName() const -{ - return m_button_name; -} - - -KeyboardMouse::Axis::Axis(IOHIDElementRef axis_element) -: m_axis_element(axis_element) -{ - std::ostringstream s; - s << IOHIDElementGetUsage(m_axis_element); - m_axis_name = s.str(); -} - -ControlState KeyboardMouse::Axis::GetState( const State* const state ) -{ - return false; -} - -std::string KeyboardMouse::Axis::GetName() const -{ - return m_axis_name; -} - - -KeyboardMouse::Light::Light(IOHIDElementRef light_element) -: m_light_element(light_element) -{ - int idx = IOHIDElementGetUsage(m_light_element); - m_light_name = (idx <= 5) ? named_lights[idx].name : "UNKNOWN"; -} - -void KeyboardMouse::Light::SetState( const ControlState state, unsigned char* const state_out ) -{ - uint64_t timestamp = 0; - IOHIDValueRef value = IOHIDValueCreateWithIntegerValue(kCFAllocatorDefault, m_light_element, timestamp, (int)state); - if (IOHIDDeviceSetValue(IOHIDElementGetDevice(m_light_element), m_light_element, value) == kIOReturnSuccess) - { - NSLog(@"element %x value %x", IOHIDElementGetUsage(m_light_element), value); - } -} - -std::string KeyboardMouse::Light::GetName() const -{ - return m_light_name; -} - } } diff --git a/Source/Core/InputCommon/Src/ControllerInterface/OSX/OSXKeyboard.mm b/Source/Core/InputCommon/Src/ControllerInterface/OSX/OSXKeyboard.mm new file mode 100644 index 0000000000..febbf24fe9 --- /dev/null +++ b/Source/Core/InputCommon/Src/ControllerInterface/OSX/OSXKeyboard.mm @@ -0,0 +1,132 @@ +#include "../ControllerInterface.h" + +#ifdef CIFACE_USE_OSX + +#include "OSX.h" +#include +#include + +namespace ciface +{ +namespace OSX +{ + + +struct PrettyKeys +{ + const uint32_t code; + const char* const name; +} named_keys[] = +{ +#include "NamedKeys.h" +}; + +extern void DeviceElementDebugPrint(const void*, void*); + + +Keyboard::Keyboard(IOHIDDeviceRef device, int index) + : m_device(device) + , m_device_index(index) +{ + m_device_name = [(NSString *)IOHIDDeviceGetProperty(m_device, CFSTR(kIOHIDProductKey)) UTF8String]; + + // Go through all the elements of the device we've been given and try to make something out of them + CFArrayRef elements = IOHIDDeviceCopyMatchingElements(m_device, NULL, kIOHIDOptionsTypeNone); + CFIndex idx = 0; + for (IOHIDElementRef e = (IOHIDElementRef)CFArrayGetValueAtIndex(elements, idx); + e; + e = (IOHIDElementRef)CFArrayGetValueAtIndex(elements, ++idx)) + { + if ((IOHIDElementGetType(e) == kIOHIDElementTypeInput_Button) && + (IOHIDElementGetUsagePage(e) == kHIDPage_KeyboardOrKeypad) && + (IOHIDElementGetLogicalMin(e) == 0) && + (IOHIDElementGetLogicalMax(e) == 1)) + { + try { + inputs.push_back(new Key(e)); + } + catch (std::bad_alloc&) { + } + } + else + { + //DeviceElementDebugPrint(e, NULL); + } + } + CFRelease(elements); +} + +ControlState Keyboard::GetInputState( const ControllerInterface::Device::Input* const input ) +{ + return ((Input*)input)->GetState(); +} + +void Keyboard::SetOutputState( const ControllerInterface::Device::Output* const output, const ControlState state ) +{ +} + +bool Keyboard::UpdateInput() +{ + return true; +} + +bool Keyboard::UpdateOutput() +{ + return true; +} + +std::string Keyboard::GetName() const +{ + return m_device_name; +} + +std::string Keyboard::GetSource() const +{ + return "OSX"; +} + +int Keyboard::GetId() const +{ + return m_device_index; +} + + +Keyboard::Key::Key(IOHIDElementRef key_element) + : m_key_element(key_element) + , m_key_name("RESERVED") // for some reason HID Manager gives these to us. bad_alloc! +{ + uint32_t keycode = IOHIDElementGetUsage(m_key_element); + for (uint32_t i = 0; i < sizeof(named_keys)/sizeof(*named_keys); i++) + { + if (named_keys[i].code == keycode) + { + m_key_name = named_keys[i].name; + return; + } + } + throw std::bad_alloc(); +} + +ControlState Keyboard::Key::GetState() +{ + IOHIDValueRef value; + if (IOHIDDeviceGetValue(IOHIDElementGetDevice(m_key_element), m_key_element, &value) == kIOReturnSuccess) + { + double scaled_value = IOHIDValueGetScaledValue(value, kIOHIDValueScaleTypePhysical); + //NSLog(@"element %x value %x scaled %f", IOHIDElementGetUsage(m_key_element), value, scaled_value); + return scaled_value > 0; + } + + return false; +} + +std::string Keyboard::Key::GetName() const +{ + return m_key_name; +} + + +} +} + +#endif diff --git a/Source/Core/InputCommon/Src/SConscript b/Source/Core/InputCommon/Src/SConscript index 49e0d08703..647307f750 100644 --- a/Source/Core/InputCommon/Src/SConscript +++ b/Source/Core/InputCommon/Src/SConscript @@ -28,7 +28,8 @@ if icenv['HAVE_SDL']: if sys.platform == 'darwin': files += [ - 'ControllerInterface/OSX/OSX.mm' + 'ControllerInterface/OSX/OSX.mm', + 'ControllerInterface/OSX/OSXKeyboard.mm' ] icenv['FRAMEWORKS'] = ['IOKit'] diff --git a/Source/Dolphin.xcodeproj/project.pbxproj b/Source/Dolphin.xcodeproj/project.pbxproj index b493c695d3..7e07a8bc6b 100644 --- a/Source/Dolphin.xcodeproj/project.pbxproj +++ b/Source/Dolphin.xcodeproj/project.pbxproj @@ -955,6 +955,8 @@ 292AC59211838FD700B8790B /* pluginspecs_pad.h in Headers */ = {isa = PBXBuildFile; fileRef = 292AC1DC11838FD700B8790B /* pluginspecs_pad.h */; }; 292AC59311838FD700B8790B /* pluginspecs_video.h in Headers */ = {isa = PBXBuildFile; fileRef = 292AC1DD11838FD700B8790B /* pluginspecs_video.h */; }; 292AC59411838FD700B8790B /* pluginspecs_wiimote.h in Headers */ = {isa = PBXBuildFile; fileRef = 292AC1DE11838FD700B8790B /* pluginspecs_wiimote.h */; }; + 29D1528F118634B400CC2741 /* OSXKeyboard.mm in Sources */ = {isa = PBXBuildFile; fileRef = 29D1528E118634B400CC2741 /* OSXKeyboard.mm */; }; + 29D152AC1186461800CC2741 /* NamedKeys.h in Headers */ = {isa = PBXBuildFile; fileRef = 29D152AB1186461800CC2741 /* NamedKeys.h */; }; 5232B1F10EEB634D0093A7B1 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5232B1F00EEB634D0093A7B1 /* Cocoa.framework */; }; 5232B2820EEBE2210093A7B1 /* Cg.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5232B2810EEBE2210093A7B1 /* Cg.framework */; }; 52492CB80ED19A02008ADF7D /* libz.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 52492CB70ED19A02008ADF7D /* libz.dylib */; }; @@ -2314,6 +2316,8 @@ 292AC1DC11838FD700B8790B /* pluginspecs_pad.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = pluginspecs_pad.h; sourceTree = ""; }; 292AC1DD11838FD700B8790B /* pluginspecs_video.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = pluginspecs_video.h; sourceTree = ""; }; 292AC1DE11838FD700B8790B /* pluginspecs_wiimote.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = pluginspecs_wiimote.h; sourceTree = ""; }; + 29D1528E118634B400CC2741 /* OSXKeyboard.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = OSXKeyboard.mm; sourceTree = ""; }; + 29D152AB1186461800CC2741 /* NamedKeys.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NamedKeys.h; sourceTree = ""; }; 5048396D09E3307300765E4B /* DolphinProj.xcconfig */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = text.xcconfig; path = DolphinProj.xcconfig; sourceTree = ""; }; 5048396E09E3307300765E4B /* DolphinTarget.xcconfig */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = text.xcconfig; path = DolphinTarget.xcconfig; sourceTree = ""; }; 508344B209E5C41E0093A071 /* Dolphin.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Dolphin.app; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -3576,6 +3580,8 @@ 292AC00111838FD600B8790B /* OSX */ = { isa = PBXGroup; children = ( + 29D152AB1186461800CC2741 /* NamedKeys.h */, + 29D1528E118634B400CC2741 /* OSXKeyboard.mm */, 292AC00211838FD600B8790B /* OSX.mm */, 292AC00311838FD600B8790B /* OSX.h */, ); @@ -4843,6 +4849,7 @@ 292AC59211838FD700B8790B /* pluginspecs_pad.h in Headers */, 292AC59311838FD700B8790B /* pluginspecs_video.h in Headers */, 292AC59411838FD700B8790B /* pluginspecs_wiimote.h in Headers */, + 29D152AC1186461800CC2741 /* NamedKeys.h in Headers */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -5895,6 +5902,7 @@ 292AC58811838FD700B8790B /* Encryption.cpp in Sources */, 292AC58A11838FD700B8790B /* WiimoteEmu.cpp in Sources */, 292AC58D11838FD700B8790B /* WiimoteNew.cpp in Sources */, + 29D1528F118634B400CC2741 /* OSXKeyboard.mm in Sources */, ); runOnlyForDeploymentPostprocessing = 0; };