#define NoSymbol 0
+// These are undocumented for unknown reasons
+const int kVK_RightCommand = 0x36;
+const int kVK_Menu = 0x6E;
+
static bool captured = false;
int cocoa_capture_display(Fl_Window *win, bool all_displays)
UInt32 mask;
// We don't see any event on release of CapsLock
- if ([nsevent keyCode] == 0x39)
+ if ([nsevent keyCode] == kVK_CapsLock)
return 1;
// These are entirely undocumented, but I cannot find any other way
// of differentiating between left and right keys
switch ([nsevent keyCode]) {
- case 0x36:
+ case kVK_RightCommand:
mask = 0x0010;
break;
- case 0x37:
+ case kVK_Command:
mask = 0x0008;
break;
- case 0x38:
+ case kVK_Shift:
mask = 0x0002;
break;
- case 0x39:
+ case kVK_CapsLock:
// We don't see any event on release of CapsLock
return 1;
- case 0x3A:
+ case kVK_Option:
mask = 0x0020;
break;
- case 0x3B:
+ case kVK_Control:
mask = 0x0001;
break;
- case 0x3C:
+ case kVK_RightShift:
mask = 0x0004;
break;
- case 0x3D:
+ case kVK_RightOption:
mask = 0x0040;
break;
- case 0x3E:
+ case kVK_RightControl:
mask = 0x2000;
break;
default:
layout = NULL;
-#if (MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5) || defined(__x86_64__)
TISInputSourceRef keyboard;
CFDataRef uchr;
return nil;
layout = (const UCKeyboardLayout*)CFDataGetBytePtr(uchr);
-#else // MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
- KeyboardLayoutRef old_layout;
- int kind;
-
- err = KLGetCurrentKeyboardLayout(&old_layout);
- if (err != noErr)
- return nil;
-
- err = KLGetKeyboardLayoutProperty(old_layout, kKLKind,
- (const void**)&kind);
- if (err != noErr)
- return nil;
-
- // Old, crufty layout format?
- if (kind == kKLKCHRKind) {
- void *kchr_layout;
-
- UInt32 chars, state;
- char buf[3];
-
- unichar result[16];
- ByteCount in_len, out_len;
-
- err = KLGetKeyboardLayoutProperty(old_layout, kKLKCHRData,
- (const void**)&kchr_layout);
- if (err != noErr)
- return nil;
-
- state = 0;
-
- keyCode &= 0x7f;
- modifierFlags &= 0xff00;
-
- chars = KeyTranslate(kchr_layout, keyCode | modifierFlags, &state);
-
- // Dead key?
- if (state != 0) {
- // We have no fool proof way of asking what dead key this is.
- // Assume we get a spacing equivalent if we press the
- // same key again, and try to deduce something from that.
- chars = KeyTranslate(kchr_layout, keyCode | modifierFlags, &state);
- }
-
- buf[0] = (chars >> 16) & 0xff;
- buf[1] = chars & 0xff;
- buf[2] = '\0';
-
- if (buf[0] == '\0') {
- buf[0] = buf[1];
- buf[1] = '\0';
- }
-
- // The data is now in some layout specific encoding. Need to convert
- // this to unicode.
-
- ScriptCode script;
- TextEncoding encoding;
- TECObjectRef converter;
-
- script = (ScriptCode)GetScriptManagerVariable(smKeyScript);
-
- err = UpgradeScriptInfoToTextEncoding(script, kTextLanguageDontCare,
- kTextRegionDontCare, NULL,
- &encoding);
- if (err != noErr)
- return nil;
-
- err = TECCreateConverter(&converter, encoding, kTextEncodingUnicodeV4_0);
- if (err != noErr)
- return nil;
-
- in_len = strlen(buf);
- out_len = sizeof(result);
-
- err = TECConvertText(converter, (ConstTextPtr)buf, in_len, &in_len,
- (TextPtr)result, out_len, &out_len);
-
- TECDisposeConverter(converter);
-
- if (err != noErr)
- return nil;
-
- return [NSString stringWithCharacters:result
- length:(out_len / sizeof(unichar))];
- }
-
- if ((kind != kKLKCHRuchrKind) && (kind != kKLuchrKind))
- return nil;
-
- err = KLGetKeyboardLayoutProperty(old_layout, kKLuchrData,
- (const void**)&layout);
- if (err != noErr)
- return nil;
-#endif // MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
-
if (layout == NULL)
return nil;
return [NSString stringWithCharacters:string length:actual_len];
}
-// FIXME: We use hard coded values here as the constants didn't appear
-// in the OS X headers until 10.5.
static const int kvk_map[][2] = {
- { 0x24, XK_Return },
- { 0x30, XK_Tab },
- { 0x31, XK_space },
- { 0x33, XK_BackSpace },
- { 0x35, XK_Escape },
- // This one is undocumented for unknown reasons
- { 0x36, XK_Super_R },
- { 0x37, XK_Super_L },
- { 0x38, XK_Shift_L },
- { 0x39, XK_Caps_Lock },
- { 0x3A, XK_Alt_L },
- { 0x3B, XK_Control_L },
- { 0x3C, XK_Shift_R },
- { 0x3D, XK_Alt_R },
- { 0x3E, XK_Control_R },
- { 0x40, XK_F17 },
- { 0x48, XF86XK_AudioRaiseVolume },
- { 0x49, XF86XK_AudioLowerVolume },
- { 0x4A, XF86XK_AudioMute },
- { 0x4F, XK_F18 },
- { 0x50, XK_F19 },
- { 0x5A, XK_F20 },
- { 0x60, XK_F5 },
- { 0x61, XK_F6 },
- { 0x62, XK_F7 },
- { 0x63, XK_F3 },
- { 0x64, XK_F8 },
- { 0x65, XK_F9 },
- { 0x67, XK_F11 },
- { 0x69, XK_F13 },
- { 0x6A, XK_F16 },
- { 0x6B, XK_F14 },
- { 0x6D, XK_F10 },
- // Also undocumented
- { 0x6E, XK_Menu },
- { 0x6F, XK_F12 },
- { 0x71, XK_F15 },
+ { kVK_Return, XK_Return },
+ { kVK_Tab, XK_Tab },
+ { kVK_Space, XK_space },
+ { kVK_Delete, XK_BackSpace },
+ { kVK_Escape, XK_Escape },
+ { kVK_RightCommand, XK_Super_R },
+ { kVK_Command, XK_Super_L },
+ { kVK_Shift, XK_Shift_L },
+ { kVK_CapsLock, XK_Caps_Lock },
+ { kVK_Option, XK_Alt_L },
+ { kVK_Control, XK_Control_L },
+ { kVK_RightShift, XK_Shift_R },
+ { kVK_RightOption, XK_Alt_R },
+ { kVK_RightControl, XK_Control_R },
+ { kVK_F17, XK_F17 },
+ { kVK_VolumeUp, XF86XK_AudioRaiseVolume },
+ { kVK_VolumeDown, XF86XK_AudioLowerVolume },
+ { kVK_Mute, XF86XK_AudioMute },
+ { kVK_F18, XK_F18 },
+ { kVK_F19, XK_F19 },
+ { kVK_F20, XK_F20 },
+ { kVK_F5, XK_F5 },
+ { kVK_F6, XK_F6 },
+ { kVK_F7, XK_F7 },
+ { kVK_F3, XK_F3 },
+ { kVK_F8, XK_F8 },
+ { kVK_F9, XK_F9 },
+ { kVK_F11, XK_F11 },
+ { kVK_F13, XK_F13 },
+ { kVK_F16, XK_F16 },
+ { kVK_F14, XK_F14 },
+ { kVK_F10, XK_F10 },
+ { kVK_Menu, XK_Menu },
+ { kVK_F12, XK_F12 },
+ { kVK_F15, XK_F15 },
// Should we send Insert here?
- { 0x72, XK_Help },
- { 0x73, XK_Home },
- { 0x74, XK_Page_Up },
- { 0x75, XK_Delete },
- { 0x76, XK_F4 },
- { 0x77, XK_End },
- { 0x78, XK_F2 },
- { 0x79, XK_Page_Down },
- { 0x7A, XK_F1 },
- { 0x7B, XK_Left },
- { 0x7C, XK_Right },
- { 0x7D, XK_Down },
- { 0x7E, XK_Up },
+ { kVK_Help, XK_Help },
+ { kVK_Home, XK_Home },
+ { kVK_PageUp, XK_Page_Up },
+ { kVK_ForwardDelete, XK_Delete },
+ { kVK_F4, XK_F4 },
+ { kVK_End, XK_End },
+ { kVK_F2, XK_F2 },
+ { kVK_PageDown, XK_Page_Down },
+ { kVK_F1, XK_F1 },
+ { kVK_LeftArrow, XK_Left },
+ { kVK_RightArrow, XK_Right },
+ { kVK_DownArrow, XK_Down },
+ { kVK_UpArrow, XK_Up },
+
// The OS X headers claim these keys are not layout independent.
// Could it be because of the state of the decimal key?
- /* { 0x41, XK_KP_Decimal }, */ // see below
- { 0x43, XK_KP_Multiply },
- { 0x45, XK_KP_Add },
+ /* { kVK_ANSI_KeypadDecimal, XK_KP_Decimal }, */ // see below
+ { kVK_ANSI_KeypadMultiply, XK_KP_Multiply },
+ { kVK_ANSI_KeypadPlus, XK_KP_Add },
// OS X doesn't have NumLock, so is this really correct?
- { 0x47, XK_Num_Lock },
- { 0x4B, XK_KP_Divide },
- { 0x4C, XK_KP_Enter },
- { 0x4E, XK_KP_Subtract },
- { 0x51, XK_KP_Equal },
- { 0x52, XK_KP_0 },
- { 0x53, XK_KP_1 },
- { 0x54, XK_KP_2 },
- { 0x55, XK_KP_3 },
- { 0x56, XK_KP_4 },
- { 0x57, XK_KP_5 },
- { 0x58, XK_KP_6 },
- { 0x59, XK_KP_7 },
- { 0x5B, XK_KP_8 },
- { 0x5C, XK_KP_9 },
+ { kVK_ANSI_KeypadClear, XK_Num_Lock },
+ { kVK_ANSI_KeypadDivide, XK_KP_Divide },
+ { kVK_ANSI_KeypadEnter, XK_KP_Enter },
+ { kVK_ANSI_KeypadMinus, XK_KP_Subtract },
+ { kVK_ANSI_KeypadEquals, XK_KP_Equal },
+ { kVK_ANSI_Keypad0, XK_KP_0 },
+ { kVK_ANSI_Keypad1, XK_KP_1 },
+ { kVK_ANSI_Keypad2, XK_KP_2 },
+ { kVK_ANSI_Keypad3, XK_KP_3 },
+ { kVK_ANSI_Keypad4, XK_KP_4 },
+ { kVK_ANSI_Keypad5, XK_KP_5 },
+ { kVK_ANSI_Keypad6, XK_KP_6 },
+ { kVK_ANSI_Keypad7, XK_KP_7 },
+ { kVK_ANSI_Keypad8, XK_KP_8 },
+ { kVK_ANSI_Keypad9, XK_KP_9 },
};
int cocoa_event_keysym(const void *event)