• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Using AppleEvents to copy and past text from any application
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

References: 
 >Re: Using AppleEvents to copy and past text from any application (From: has <email@hidden>)
 >Re: Using AppleEvents to copy and past text from any application (From: Jesse Grosjean <email@hidden>)
 >Re: Using AppleEvents to copy and past text from any application (From: has <email@hidden>)

  • Prev by Date: Re: NSDate without time portion
  • Next by Date: What gets automatically localized?
  • Previous by thread: Re: Using AppleEvents to copy and past text from any application
  • Next by thread: NSSavePanel with accessory view and file types popup
  • Index(es):
    • Date
    • Thread