+// Callback from Create() to build the HID cookies for the internal cookie
+// array
+// ----------------------------------------------------------------------------
+void wxHIDKeyboard::BuildCookies(CFArrayRef Array)
+{
+ //Create internal cookie array
+ InitCookies(500);
+
+ //Begin recursing in array
+ DoBuildCookies(Array);
+}
+
+void wxHIDKeyboard::DoBuildCookies(CFArrayRef Array)
+{
+ //Now go through each possible cookie
+ int i,
+ nUsage;
+// bool bEOTriggered = false;
+ for (i = 0; i < CFArrayGetCount(Array); ++i)
+ {
+ const void* ref = CFDictionaryGetValue(
+ (CFDictionaryRef)CFArrayGetValueAtIndex(Array, i),
+ CFSTR(kIOHIDElementKey)
+ );
+
+ if (ref != NULL)
+ {
+ DoBuildCookies((CFArrayRef) ref);
+ }
+ else
+ {
+
+ //
+ // Get the usage #
+ //
+ CFNumberGetValue(
+ (CFNumberRef)
+ CFDictionaryGetValue((CFDictionaryRef)
+ CFArrayGetValueAtIndex(Array, i),
+ CFSTR(kIOHIDElementUsageKey)
+ ),
+ kCFNumberLongType,
+ &nUsage);
+
+ //
+ // Now translate the usage # into a wx keycode
+ //
+
+ //
+ // OK, this is strange - basically this kind of strange -
+ // Starting from 0xEO these elements (like shift) appear twice in
+ // the array! The ones at the end are bogus I guess - the funny part
+ // is that besides the fact that the ones at the front have a Unit
+ // and UnitExponent key with a value of 0 and a different cookie value,
+ // there is no discernable difference between the two...
+ //
+ // Will the real shift please stand up?
+ //
+ // Something to spend a support request on, if I had one, LOL.
+ //
+ //if(nUsage == 0xE0)
+ //{
+ // if(bEOTriggered)
+ // break;
+ // bEOTriggered = true;
+ //}
+ //Instead of that though we now just don't add duplicate keys
+
+ if (nUsage >= kHIDUsage_KeyboardA && nUsage <= kHIDUsage_KeyboardZ)
+ AddCookie(CFArrayGetValueAtIndex(Array, i), 'A' + (nUsage - kHIDUsage_KeyboardA) );
+ else if (nUsage >= kHIDUsage_Keyboard1 && nUsage <= kHIDUsage_Keyboard9)
+ AddCookie(CFArrayGetValueAtIndex(Array, i), '1' + (nUsage - kHIDUsage_Keyboard1) );
+ else if (nUsage >= kHIDUsage_KeyboardF1 && nUsage <= kHIDUsage_KeyboardF12)
+ AddCookie(CFArrayGetValueAtIndex(Array, i), WXK_F1 + (nUsage - kHIDUsage_KeyboardF1) );
+ else if (nUsage >= kHIDUsage_KeyboardF13 && nUsage <= kHIDUsage_KeyboardF24)
+ AddCookie(CFArrayGetValueAtIndex(Array, i), WXK_F13 + (nUsage - kHIDUsage_KeyboardF13) );
+ else if (nUsage >= kHIDUsage_Keypad1 && nUsage <= kHIDUsage_Keypad9)
+ AddCookie(CFArrayGetValueAtIndex(Array, i), WXK_NUMPAD1 + (nUsage - kHIDUsage_Keypad1) );
+ else switch (nUsage)
+ {
+ //0's (wx & ascii go 0-9, but HID goes 1-0)
+ case kHIDUsage_Keyboard0:
+ AddCookie(CFArrayGetValueAtIndex(Array, i), '0');
+ break;
+ case kHIDUsage_Keypad0:
+ AddCookie(CFArrayGetValueAtIndex(Array, i), WXK_NUMPAD0);
+ break;
+
+ //Basic
+ case kHIDUsage_KeyboardReturnOrEnter:
+ AddCookie(CFArrayGetValueAtIndex(Array, i), WXK_RETURN);
+ break;
+ case kHIDUsage_KeyboardEscape:
+ AddCookie(CFArrayGetValueAtIndex(Array, i), WXK_ESCAPE);
+ break;
+ case kHIDUsage_KeyboardDeleteOrBackspace:
+ AddCookie(CFArrayGetValueAtIndex(Array, i), WXK_BACK);
+ break;
+ case kHIDUsage_KeyboardTab:
+ AddCookie(CFArrayGetValueAtIndex(Array, i), WXK_TAB);
+ break;
+ case kHIDUsage_KeyboardSpacebar:
+ AddCookie(CFArrayGetValueAtIndex(Array, i), WXK_SPACE);
+ break;
+ case kHIDUsage_KeyboardPageUp:
+ AddCookie(CFArrayGetValueAtIndex(Array, i), WXK_PAGEUP);
+ break;
+ case kHIDUsage_KeyboardEnd:
+ AddCookie(CFArrayGetValueAtIndex(Array, i), WXK_END);
+ break;
+ case kHIDUsage_KeyboardPageDown:
+ AddCookie(CFArrayGetValueAtIndex(Array, i), WXK_PAGEDOWN);
+ break;
+ case kHIDUsage_KeyboardRightArrow:
+ AddCookie(CFArrayGetValueAtIndex(Array, i), WXK_RIGHT);
+ break;
+ case kHIDUsage_KeyboardLeftArrow:
+ AddCookie(CFArrayGetValueAtIndex(Array, i), WXK_LEFT);
+ break;
+ case kHIDUsage_KeyboardDownArrow:
+ AddCookie(CFArrayGetValueAtIndex(Array, i), WXK_DOWN);
+ break;
+ case kHIDUsage_KeyboardUpArrow:
+ AddCookie(CFArrayGetValueAtIndex(Array, i), WXK_UP);
+ break;
+
+ //LEDS
+ case kHIDUsage_KeyboardCapsLock:
+ AddCookie(CFArrayGetValueAtIndex(Array, i),WXK_CAPITAL);
+ break;
+ case kHIDUsage_KeypadNumLock:
+ AddCookie(CFArrayGetValueAtIndex(Array, i),WXK_NUMLOCK);
+ break;
+ case kHIDUsage_KeyboardScrollLock:
+ AddCookie(CFArrayGetValueAtIndex(Array, i),WXK_SCROLL);
+ break;
+
+ //Menu keys, Shift, other specials
+ case kHIDUsage_KeyboardLeftControl:
+ AddCookie(CFArrayGetValueAtIndex(Array, i),WXK_CONTROL);
+ break;
+ case kHIDUsage_KeyboardLeftShift:
+ AddCookie(CFArrayGetValueAtIndex(Array, i),WXK_SHIFT);
+ break;
+ case kHIDUsage_KeyboardLeftAlt:
+ AddCookie(CFArrayGetValueAtIndex(Array, i),WXK_ALT);
+ break;
+ case kHIDUsage_KeyboardLeftGUI:
+ AddCookie(CFArrayGetValueAtIndex(Array, i),WXK_MENU);
+ break;
+ case kHIDUsage_KeyboardRightControl:
+ AddCookie(CFArrayGetValueAtIndex(Array, i),WXK_RCONTROL);
+ break;
+ case kHIDUsage_KeyboardRightShift:
+ AddCookie(CFArrayGetValueAtIndex(Array, i),WXK_RSHIFT);
+ break;
+ case kHIDUsage_KeyboardRightAlt:
+ AddCookie(CFArrayGetValueAtIndex(Array, i),WXK_RALT);
+ break;
+ case kHIDUsage_KeyboardRightGUI:
+ AddCookie(CFArrayGetValueAtIndex(Array, i),WXK_RMENU);
+ break;
+
+ //Default
+ default:
+ //not in wx keycodes - do nothing....
+ break;
+ } //end mightly long switch
+ } //end if the current element is not an array...
+ } //end for loop for Array
+}//end buildcookies