Re: Using AppleEvents to copy and past text from any application
Re: Using AppleEvents to copy and past text from any application
- Subject: Re: Using AppleEvents to copy and past text from any application
- From: Dave DeLong <email@hidden>
- Date: Tue, 05 Jan 2010 15:01:13 -0700
Yep:
CGEventSourceRef source = CGEventSourceCreate(kCGEventSourceStateCombinedSessionState);
CGEventRef pasteCommandDown = CGEventCreateKeyboardEvent(source, (CGKeyCode)9, YES);
CGEventSetFlags(pasteCommandDown, kCGEventFlagMaskCommand);
CGEventRef pasteCommandUp = CGEventCreateKeyboardEvent(source, (CGKeyCode)9, NO);
CGEventPost(kCGAnnotatedSessionEventTap, pasteCommandDown);
CGEventPost(kCGAnnotatedSessionEventTap, pasteCommandUp);
CFRelease(pasteCommandUp);
CFRelease(pasteCommandDown);
CFRelease(source);
(CGKeyCode)9 is the code for the letter 'v', so this is the way to invoke a cmd-v (paste) operation.
Beware of international keyboard layouts.
Cheers,
Dave
On Jan 5, 2010, at 2:58 PM, has wrote:
>
> On 5 Jan 2010, at 21:41, Jesse Grosjean wrote:
>
>> Last, how would I go about sending Cmd-C/Cmd-V keystrokes directoy to
>> another application?
>
> Haven't done it myself, but I would guess CGEventCreateKeyboardEvent() and friends would be simplest.
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden