CGEventRef with function key

0 views
Skip to first unread message

Joe Turner

unread,
Jul 21, 2011, 5:22:07 PM7/21/11
to Cocoa-Dev Mail Cocoa-Dev
Hey,

So I've been having some issues with posting a CGEvent with a function key as a modifier (or flag). If I call CGEventSetFlags(eventDown, kCGEventFlagMaskSecondaryFn), and then post the event, all I get is the keyCode posting (as in maybe the left arrow is pressed), but the function key is not virtually pressed. As far as I can tell kCGEventFlagMaskSecondaryFn is for the function key modifier, so I'm not sure why this isn't working. Any help would be appreciated!

Thanks,

Joe Turner
_______________________________________________

Cocoa-dev mailing list (Coco...@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/cocoa-dev-garchive-98506%40googlegroups.com

This email sent to cocoa-dev-ga...@googlegroups.com

Bill Cheeseman

unread,
Jul 21, 2011, 6:12:47 PM7/21/11
to Cocoa-Dev Mail Cocoa-Dev

On Jul 21, 2011, at 5:22 PM, Joe Turner wrote:

> So I've been having some issues with posting a CGEvent with a function key as a modifier (or flag). If I call CGEventSetFlags(eventDown, kCGEventFlagMaskSecondaryFn), and then post the event, all I get is the keyCode posting (as in maybe the left arrow is pressed), but the function key is not virtually pressed. As far as I can tell kCGEventFlagMaskSecondaryFn is for the function key modifier, so I'm not sure why this isn't working. Any help would be appreciated!


The Mac responds to sequences of keyboard events, such as key-down followed by key-up, or modifier-key-down followed by key-down followed by key-up followed by modifier-key-up. So you have to post all of the relevant key-down and key-up events before you can expect the target application to respond. As I recall, the set flags command isn't meant to be used as part of that sequence; instead, you need to send key-down and key-up events for the specified modifier key. I believe there are examples of how to do this somewhere in the Quartz Event Services Reference document.

You might also find it useful to experiment with my free Event Taps Testbench utility at <http://pfiddlesoft.com/eventtapstestbench>.

You will get more focused responses to inquiries about this on Apple's accessibility-dev mailing list, where Apple's accessibility engineers hang out.

--

Bill Cheeseman - bi...@cheeseman.name

Joe Turner

unread,
Jul 21, 2011, 11:59:16 PM7/21/11
to coco...@lists.apple.com
Hey,

I understand how events are supposed to be posted, but for command, option, control and shift, you can easily used the CGEventFlags to specify that part (and it works). So what you're saying is that for function, you do have to do it separately? I just don't understand why they would make it any different for Fn.

Thanks,

Joe

Reply all
Reply to author
Forward
0 new messages