Sending a paste event to another app?
Sending a paste event to another app?
- Subject: Sending a paste event to another app?
- From: Steve Moon <email@hidden>
- Date: Mon, 17 Dec 2001 08:39:02 -0800
Hi
my AppKit application need to automatically paste some data from its
pasteboard to another application. In fact it is required that my app
paste the data contents automatically : basically my app need to execute
the equivalent of the keyboard shortcut CMD-V to any app.
Is there an easy way for doing that ?? I was thinking that by using some
AppleScript I can probably send the event ID kAEPaste to the final
application but I can't find any example that explain how to proceed.
Right now my code looks like :
[... code to activat the final application + some wait time...]
// frontProcess below is initialize using : GetFrontProcess() from Carbon
myErr = AECreateDesc(typeProcessSerialNumber, &frontProcess,
sizeof(ProcessSerialNumber), &addr);
myErr = AECreateAppleEvent(kAEMiscStandards, eventID, &addr,
kAutoGenerateReturnID, kAnyTransactionID, &actionEvent);
myErr = AESendMessage(&actionEvent, NULL, kAENoReply, kNoTimeOut);
But this code does nothing... it does not crash but nothing happen. And
yes my pasteboard is correctly set since by doing a CMD-V in the final
app I got the right data pasted in the app.
Steve
Note: my app do not know in advance what is the final application where
the Paste event should occur; this is something that the user can define
at will : it could be a Cocoa app (like TextEdit), a Carbon app (like
Internet Explorer), ... and so I can not add my custom code in this
final app for handling this case : my app need so to activate first the
final app and send the Paste event.