Aquí es un ejemplo, modificada ligeramente de aplicación de ejemplo ModKeyTest de Matt Gemmell. Crea una aplicación básica Cocoa con un botón y conecta el botón a un IBAction como este. Luego pruebe la combinación de teclas que desee. Los documentos son un poco confusos, pero el ejemplo de Matt es muy claro y presenta todo lo que necesita para aprovechar esto más allá de los documentos.
- (IBAction)myAction:(id)sender {
NSUInteger flags = [[NSApp currentEvent] modifierFlags];
if ((flags & NSCommandKeyMask) && (flags & NSAlternateKeyMask) && (flags & NSControlKeyMask)) {
NSBeginInformationalAlertSheet(@"Modifier keys Command Option Control detected", nil, nil, nil, [NSApp mainWindow], self, nil, nil, nil,
@"You sneaky thing!");
}
if ((flags & NSCommandKeyMask) && (flags & NSShiftKeyMask)) {
NSBeginInformationalAlertSheet(@"Modifier keys Command Shift detected", nil, nil, nil, [NSApp mainWindow], self, nil, nil, nil,
@"You sneaky thing!");
}
if ((flags & NSAlphaShiftKeyMask)) {
NSBeginInformationalAlertSheet(@"Modifier keys Caps Lock detected", nil, nil, nil, [NSApp mainWindow], self, nil, nil, nil,
@"You sneaky thing!");
}
if ((flags & NSFunctionKeyMask)) {
NSBeginInformationalAlertSheet(@"Modifier keys fn detected", nil, nil, nil, [NSApp mainWindow], self, nil, nil, nil,
@"You sneaky thing!");
}
Suena como lo que quería, lo intentaré. – zneak