Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

laphroaig309

macrumors newbie
Original poster
Oct 1, 2010
9
0
Hi:

I used the following CGEventRef trying to emulate the "Command-V"
key strokes, and that did not work as I wished.

Can you help me to see anything go wrong?
//Command Virtual KeyCode ==> 55
//v ==> 9

pKeyboardEvent1 = CGEventCreateKeyboardEvent(NULL, (CGKeyCode)55, YES) ;
pKeyboardEvent2 = CGEventCreateKeyboardEvent(NULL, (CGKeyCode)9, YES) ;
pKeyboardEvent3 = CGEventCreateKeyboardEvent(NULL, (CGKeyCode)9, NO) ;
pKeyboardEvent4 = CGEventCreateKeyboardEvent(NULL, (CGKeyCode)55, NO) ;

// Null pointer check ignored here for briefing...

CGEventPost( kCGHIDEventTap, pKeyboardEvent1);
CGEventPost( kCGHIDEventTap, pKeyboardEvent2);
CGEventPost( kCGHIDEventTap, pKeyboardEvent3);
CGEventPost( kCGHIDEventTap, pKeyboardEvent4);

//Below are 4 CFRelease for the above CGEventRef...

Thank you very much.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.