Вы можете попробовать:
id (*eventWithCGEvent)(Class, SEL, CGEventRef) = (id (*)(Class, SEL, CGEventRef)) objc_msgSend;
Это определяет указатель функции с именем eventWithCGEvent
с тремя параметрами: получатель (так как это метод класса, он имеет тип Class
), селектор и параметр типа CGEventRef
.
В более широком контексте это может выглядеть примерно так:
#import "objc/message.h"
#import <CoreFoundation/CoreFoundation.h>
#import <CoreGraphics/CoreGraphics.h>
int main(int argc, const char * argv[]) {
...
id (*eventWithCGEvent)(Class, SEL, CGEventRef) = (id (*)(Class, SEL, CGEventRef)) objc_msgSend;
CGEventRef event_ref = CGEventCreateKeyboardEvent(NULL, (CGKeyCode)42, true);
Class NSEventClass = objc_getClass("NSEvent");
SEL eventWithCGEventSelector = sel_registerName("eventWithCGEvent:");
id event = eventWithCGEvent(NSEventClass, eventWithCGEventSelector, event_ref);
CFRelease(event_ref);
...
//do sth with event...
...
return 0;
}