Guard against controller instances without any inputs.

Clean up OS X keyboard key names.


git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@6985 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
Soren Jorvang 2011-01-30 08:12:34 +00:00
parent aa410c8eea
commit f41e5b3b85
6 changed files with 121 additions and 189 deletions

View File

@ -60,7 +60,6 @@ else:
if sys.platform == 'win32': if sys.platform == 'win32':
files += [ "stdafx.cpp" ] files += [ "stdafx.cpp" ]
elif sys.platform == 'darwin': elif sys.platform == 'darwin':
libs += [ 'iconv' ]
ldflags += [ '-Wl,-force_load,' + env['libvideo'][0].path ] ldflags += [ '-Wl,-force_load,' + env['libvideo'][0].path ]
ldflags += [ '-Xarch_i386', '-Wl,-framework,QuickTime' ] ldflags += [ '-Xarch_i386', '-Wl,-framework,QuickTime' ]
ldflags += [ '-weak_framework', 'OpenCL' ] ldflags += [ '-weak_framework', 'OpenCL' ]
@ -70,6 +69,7 @@ elif sys.platform == 'darwin':
if env['HAVE_WX']: if env['HAVE_WX']:
wxlibs += env['wxconfiglibs'] wxlibs += env['wxconfiglibs']
else: else:
libs += [ 'iconv' ]
exe += 'NoGUI' exe += 'NoGUI'

View File

@ -505,6 +505,9 @@ ControllerInterface::Device::Control* ControllerInterface::InputReference::Detec
unsigned int time = 0; unsigned int time = 0;
bool* const states = new bool[device->Inputs().size()]; bool* const states = new bool[device->Inputs().size()];
if (device->Inputs().size() == 0)
return NULL;
// get starting state of all inputs, // get starting state of all inputs,
// so we can ignore those that were activated at time of Detect start // so we can ignore those that were activated at time of Detect start
std::vector<Device::Input*>::const_iterator std::vector<Device::Input*>::const_iterator

View File

@ -1,174 +0,0 @@
{ 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 Command" },
{ kHIDUsage_KeyboardRightControl, "Right Control" },
{ kHIDUsage_KeyboardRightShift, "Right Shift" },
{ kHIDUsage_KeyboardRightAlt, "Right Alt" },
{ kHIDUsage_KeyboardRightGUI, "Right Command" },
/* 0x4E - 0xFFFF Reserved */

View File

@ -10,5 +10,7 @@ namespace OSX
void Init(std::vector<ControllerInterface::Device*>& devices); void Init(std::vector<ControllerInterface::Device*>& devices);
void DeInit(); void DeInit();
void DeviceElementDebugPrint(const void *, void *);
} }
} }

View File

@ -9,7 +9,6 @@ namespace ciface
namespace OSX namespace OSX
{ {
extern void DeviceElementDebugPrint(const void*, void*);
Joystick::Joystick(IOHIDDeviceRef device, std::string name, int index) Joystick::Joystick(IOHIDDeviceRef device, std::string name, int index)
: m_device(device) : m_device(device)

View File

@ -10,17 +10,6 @@ namespace OSX
{ {
const 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, std::string name, int index) Keyboard::Keyboard(IOHIDDeviceRef device, std::string name, int index)
: m_device(device) : m_device(device)
, m_device_name(name) , m_device_name(name)
@ -93,13 +82,126 @@ int Keyboard::GetId() const
Keyboard::Key::Key(IOHIDElementRef element) Keyboard::Key::Key(IOHIDElementRef element)
: m_element(element) : m_element(element)
{ {
const struct PrettyKeys {
const uint32_t code;
const char *const name;
} named_keys[] = {
{ 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, "Backspace" },
{ kHIDUsage_KeyboardTab, "Tab" },
{ kHIDUsage_KeyboardSpacebar, "Space" },
{ kHIDUsage_KeyboardHyphen, "-" },
{ kHIDUsage_KeyboardEqualSign, "=" },
{ kHIDUsage_KeyboardOpenBracket, "[" },
{ kHIDUsage_KeyboardCloseBracket, "]" },
{ kHIDUsage_KeyboardBackslash, "\\" },
{ 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_KeyboardInsert, "Insert" },
{ kHIDUsage_KeyboardHome, "Home" },
{ kHIDUsage_KeyboardPageUp, "Page Up" },
{ kHIDUsage_KeyboardDeleteForward, "Delete" },
{ kHIDUsage_KeyboardEnd, "End" },
{ kHIDUsage_KeyboardPageDown, "Page Down" },
{ kHIDUsage_KeyboardRightArrow, "Right Arrow" },
{ kHIDUsage_KeyboardLeftArrow, "Left Arrow" },
{ kHIDUsage_KeyboardDownArrow, "Down Arrow" },
{ kHIDUsage_KeyboardUpArrow, "Up Arrow" },
{ 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, "Paragraph" },
{ kHIDUsage_KeypadEqualSign, "Keypad =" },
{ kHIDUsage_KeypadComma, "Keypad ," },
{ kHIDUsage_KeyboardLeftControl, "Left Control" },
{ kHIDUsage_KeyboardLeftShift, "Left Shift" },
{ kHIDUsage_KeyboardLeftAlt, "Left Alt" },
{ kHIDUsage_KeyboardLeftGUI, "Left Command" },
{ kHIDUsage_KeyboardRightControl, "Right Control" },
{ kHIDUsage_KeyboardRightShift, "Right Shift" },
{ kHIDUsage_KeyboardRightAlt, "Right Alt" },
{ kHIDUsage_KeyboardRightGUI, "Right Command" },
{ 184, "Eject" },
};
std::stringstream ss;
uint32_t i, keycode; uint32_t i, keycode;
m_name = "RESERVED";
keycode = IOHIDElementGetUsage(m_element); keycode = IOHIDElementGetUsage(m_element);
for (i = 0; i < sizeof named_keys / sizeof *named_keys; i++) for (i = 0; i < sizeof named_keys / sizeof *named_keys; i++)
if (named_keys[i].code == keycode) if (named_keys[i].code == keycode) {
m_name = named_keys[i].name; m_name = named_keys[i].name;
return;
}
ss << "Key " << keycode;
m_name = ss.str();
} }
ControlState Keyboard::Key::GetState(IOHIDDeviceRef device) const ControlState Keyboard::Key::GetState(IOHIDDeviceRef device) const