I have an LSUIElement
application that displays a menubar status item. The application can display a dialog window that contains a text field.
If the u
Adrian's solution is good, but better I think to use a switch statement rather than all those string comparisons, e.g.:
uint const modifierCode = (theEvent.modifierFlags & NSDeviceIndependentModifierFlagsMask);
BOOL usingModifiers = ( modifierCode != 0 );
//BOOL const usingShiftKey = ((theEvent.modifierFlags & NSShiftKeyMask) != 0);
//BOOL const usingCommandKey = ((theEvent.modifierFlags & NSCommandKeyMask) != 0);
NSString * ch = [theEvent charactersIgnoringModifiers];
if ( ( usingModifiers ) && ( ch.length == 1 ) ) switch ( [ch characterAtIndex:0] )
{
case 'x':
if ( modifierCode == NSCommandKeyMask ) [m cut]; // <-- m = model
break;
case 'c':
if ( modifierCode == NSCommandKeyMask ) [m copy];
break;
case 'v':
if ( modifierCode == NSCommandKeyMask ) [m paste];
break;
case 'z':
if ( modifierCode == NSCommandKeyMask ) [m undo];
break;
case 'Z':
if ( modifierCode == ( NSCommandKeyMask | NSShiftKeyMask ) ) [m redo];
break;
default: // etc.
break;
}
else switch ( theEvent.keyCode ) // <-- for independent keycodes!
{
case kVK_Home:
[m moveToBeginningOfDocument:nil];
break;
case kVK_End: // etc!