Returning NULL in CGEventCallback function does not kill mouse events
| Originator: | peter.kamb | ||
| Number: | rdar://14123633 | Date Originated: | |
| Status: | Behaves Correctly | Resolved: | |
| Product: | OS X | Product Version: | |
| Classification: | Reproducible: |
Summary:
I use CGEventTapCreate to create an active event tap. In the CGEventCallback function, I want to either allow (return the event, unmodified), or kill (return NULL) the mouse events.
The Apple docs say:
https://developer.apple.com/library/mac/#documentation/Carbon/Reference/QuartzEventServicesRef/Reference/reference.html
> return NULL if the event passed in is to be deleted.
In my event I do return NULL. However, the mouse event is not deleted.
Steps to Reproduce:
Create an event tap with the code below:
eventTap = CGEventTapCreate(kCGHIDEventTap, kCGHeadInsertEventTap, kCGEventTapOptionDefault, kCGEventMaskForAllEvents, myCGEventCallback, NULL);
...
CGEventRef myCGEventCallback(CGEventTapProxy proxy, CGEventType type, CGEventRef event, void *refcon)
{
if (type == kCGEventKeyDown || type == kCGEventKeyUp) {
//Kill key events (works perfectly)
return NULL;
}
else if (type == kCGEventMouseMoved)
{
//Kill mouse movement events (does not work)
return NULL;
}
else
{
// Allow other events to go through
return event;
}
}
Expected Results:
The Quartz Event Services docs say:
> return NULL if the event passed in is to be deleted.
I would thus expect all intercepted mouse events (where in the callback I returned NULL) to be deleted.
The keypress events above *are* killed when we return NULL. Mouse events are not.
Actual Results:
Mouse continues to work, and all mouse movement events continue to be shown on screen.
Some things, such as Mission Control hotcorners, *are* prevented when we return NULL. However, the main mouse movements are not prevented.
Notes:
I am killing mouse movements in the aim of accessibility. I realize that mouse hooks can be made to be malicious or annoying. However they are very important for accessibility purposes, which Apple takes great pride in promoting.
Keyboard events can be killed just fine by returning NULL. But mouse events cannot.
Comments
Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!