Tastendruck per CGEventPostToPSN an andere Application senden



  • Schon seit Stunden versuche ich per CGEventPostToPSN Tastaturevents an einem anderen Programm zu senden. Leider schaffe ich es nicht die pid oder die psn per Application Name zu bestimmen. Könnte mir die Library http://code.ohloh.net/file?fid=c7Hr0hnH5M1Bp66cslebmLqrL70&cid=ufSHNfgNIoo&s=&fp=117904&mp=&projSelected=true#L0 helfen und wie binde ich die in C++ ein? Auch könnte es sein, dass sonst noch was falsch ist, da ich auch mit bestimmten psd beim Compilern den Fehler "symbol(s) not found for architecture x86_64" kriege. Kann mir irgendjemand weiterhelfen?

    #include "ApplicationServices/ApplicationServices.h"
    #include "Carbon/Carbon.h"
    
        void postKeyboardEvent()
        {
            //pid_t pid = [(NSRunningApplication*)[[NSRunningApplication runningApplicationsWithBundleIdentifier:@"com.apple.TextEdit"] objectAtIndex:0] processIdentifier];
            pid_t pid = GetPIDForProcessName("myprocess"); //Wie Libarry einbinden?
            ProcessSerialNumber psn = { 0, pid };
    
            CGEventSourceRef source = CGEventSourceCreate(kCGEventSourceStatePrivate);
                CGEventRef keyDownEvent = CGEventCreateKeyboardEvent(source, (CGKeyCode)8, true);
                CGEventSetFlags(keyDownEvent, (kCGEventFlagMaskControl | kCGEventFlagMaskCommand));
                CGEventRef keyUpEvent = CGEventCreateKeyboardEvent(source, (CGKeyCode)8, false);
                CGEventSetFlags(keyUpEvent, (kCGEventFlagMaskControl | kCGEventFlagMaskCommand));
                CFRelease(source);
    
                CGEventPostToPSN(&psn, keyDownEvent);
                CFRelease(keyDownEvent);
                CGEventPostToPSN(&psn, keyUpEvent);
                CFRelease(keyUpEvent);
        }
    


  • Du hast kein C++ Problem. Deine Frage wäre in einem OS X Forum besser aufgehoben.


Anmelden zum Antworten