Источник для Jumpcut (который я никогда не использовал) доступен, так что вы можете изменить fakeCommandV
в AppController.m
чтобы определить, когда он вставляется в Emacs. Я очень легко проверил следующее. Мне также пришлось внести несколько несвязанных, но незначительных изменений, чтобы заставить его скомпилироваться на моем компьютере (10.6).
-(void)fakeCommandV
/*" +fakeCommandV synthesizes keyboard events for Cmd-v Paste
shortcut. "*/
// Code from a Mark Mason post to Cocoadev-l
// What are the flaws in this approach?
// We don't know whether we can really accept the paste
// We have no way of judging whether it's gone through
// Simulating keypresses could have oddball consequences (for instance, if something else was trapping control v)
// Not all apps may take Command-V as a paste command (xemacs, for instance?)
// Some sort of AE-based (or System Events-based, or service-based) paste would be preferable in many circumstances.
// On the other hand, this doesn't require scripting support, should work for Carbon, etc.
// Ideally, in the future, we will be able to tell from what environment JC was passed the trigger
// and have different behavior from each.
{
NSString* app = [[[NSWorkspace sharedWorkspace] activeApplication]
objectForKey:@"NSApplicationName"];
NSLog(@"Current application: %@",app);
if ( [app isEqual:@"Emacs"] ) {
NSNumber *keyCode = [srTransformer reverseTransformedValue:@"Y"];
CGKeyCode yCode = (CGKeyCode)[keyCode intValue];
CGPostKeyboardEvent( (CGCharCode)0, (CGKeyCode)59, true ); // Control down
CGPostKeyboardEvent( (CGCharCode)'y', yCode, true ); // Y down
CGPostKeyboardEvent( (CGCharCode)'y', yCode, false ); // Y up
CGPostKeyboardEvent( (CGCharCode)0, (CGKeyCode)59, false ); // Control up
} else {
NSNumber *keyCode = [srTransformer reverseTransformedValue:@"V"];
CGKeyCode veeCode = (CGKeyCode)[keyCode intValue];
CGPostKeyboardEvent( (CGCharCode)0, (CGKeyCode)55, true ); // Command down
CGPostKeyboardEvent( (CGCharCode)'v', veeCode, true ); // V down
CGPostKeyboardEvent( (CGCharCode)'v', veeCode, false ); // V up
CGPostKeyboardEvent( (CGCharCode)0, (CGKeyCode)55, false ); // Command up
}
}