Re: Trouble with event taps...
Re: Trouble with event taps...
- Subject: Re: Trouble with event taps...
- From: Nat Burke <email@hidden>
- Date: Tue, 11 Aug 2009 10:08:15 -0700
Hey all,
Ok, I have figured it out. Running as root did the trick. After this
worked, I wondered if I had left the enable assistive devices checkbox off
from a prior experiment, and behold it was off! My bad on that (and I even
said it was on in my original post).
I went back and read the API documentation much more carefully this time
and it says (bold added by me):
Discussion
Event taps receive *key up and key down* events if one of the following
conditions is true:
-
The current process is running as the root user.
-
Access for assistive devices is enabled. In Mac OS X v10.4, you can
enable this feature using System Preferences, Universal Access panel,
Keyboard view.
I guess when I read that the first time, I just skimmed and figured you
would not receive ANY events without the conditions listed. Reading deeper
it does mean what it says, so hopefully my error can help others in the
future. Thanks again,
-Nat
On Mon, Aug 10, 2009 at 12:28 PM, Nat Burke <email@hidden> wrote:
> Thanks all for some tips. I'm going to try the following ideas and I'll
> let you know how it goes:
> - Run as root
> - Try just trapping on keyboard events
> - Append my event tap to the tail, and try annotated.
>
>
>
> On Mon, Aug 10, 2009 at 9:37 AM, James W. Walker <email@hidden> wrote:
>
>>
>> On Aug 9, 2009, at 3:15 PM, Nat Burke wrote:
>>
>> I have posted my event tap creation code below - I've searched all over
>>> the mailing list and the net to see if I could find a solution, but I am
>>> genuinely stuck. Any help is greatly appreciated!
>>>
>>>
>>> // Create an event tap.
>>> eventMask = CGEventMaskBit(kCGEventRightMouseDown) |
>>> CGEventMaskBit(kCGEventRightMouseUp) |
>>> CGEventMaskBit(kCGEventRightMouseDragged) |
>>> CGEventMaskBit(kCGEventMouseMoved) |
>>> CGEventMaskBit(kCGEventScrollWheel) |
>>> CGEventMaskBit(kCGEventFlagsChanged) |
>>> CGEventMaskBit(kCGEventKeyDown) |
>>> CGEventMaskBit(kCGEventKeyUp);
>>>
>>> DebugLog(@"Event before: %x", eventMask);
>>>
>>> eventTap = CGEventTapCreate(kCGSessionEventTap, kCGHeadInsertEventTap,
>>> kCGEventTapOptionDefault, eventMask, MouseCallback, self);
>>>
>>> DebugLog(@"Event after: %x", eventMask);
>>>
>>> if (!eventTap) {
>>> fprintf(stderr, "Failed to create event tap\n");
>>> exit(1);
>>> }
>>>
>>> // Create a run loop source.
>>> runLoopSource =
>>> CFMachPortCreateRunLoopSource(/*kCFAllocatorDefault*/NULL, eventTap, 0);
>>>
>>> CFRelease(eventTap);
>>>
>>> // Add to the current run loop.
>>> CFRunLoopAddSource([[NSRunLoop currentRunLoop] getCFRunLoop],
>>> runLoopSource, kCFRunLoopCommonModes);
>>>
>>> // Enable the event tap.
>>> CGEventTapEnable(eventTap, true);
>>>
>>> CFRelease(runLoopSource);
>>>
>>
>>
>> I compared your code to the code that I use that gets key down
>> successfully. One difference is that I don't immediately CFRelease the
>> event tap and source, I keep them around as long as I use the tap. Another
>> is that the first 2 parameters I pass to CGEventTapCreate are
>> kCGAnnotatedSessionEventTap and kCGTailAppendEventTap.
>>
>>
>>
>
_______________________________________________
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