Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7701519
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T23:00:23+00:00 2026-05-31T23:00:23+00:00

I have a global app that prevents the mouse from moving into areas of

  • 0

I have a global app that prevents the mouse from moving into areas of the screen. Must work with all apps, while my app in the background, etc.

I have set up a CGEventTap hook that has a callback for mouse movements.

The user’s mouse movement continues to pass through the hook, no matter how I attempt to modify/kill the movement. That mirrors the experiences of others: https://stackoverflow.com/a/5831573/106761

- (CGEventRef) mouseMovedEvent:(CGEventRef) newUserMouseMovement
{ 
    //Attempt to modify the mouse movement
    CGEventSetDoubleValueField(newUserMouseMovement, kCGMouseEventDeltaX, 0);
    CGEventSetDoubleValueField(newUserMouseMovement, kCGMouseEventDeltaY, 0);
    CGEventSetDoubleValueField(newUserMouseMovement, kCGMouseEventDeltaX, 0.0);

    //Attempt to kill the event
    return NULL;
}
//Mouse movement still works normally.

I am able to use CGDisplayMoveCursorToPoint or CGWarpMouseCursorPosition to reposition the cursor back to the original position.

This works fine, although I would rather just kill the event altogether.

The problem is that the original user mouse movement shows the cursor visual at that point for a split second, before I am able to move the cursor.

I’m using:

CGSetLocalEventsSuppressionInterval(0.0);

to increase the frequency at which the Mouse movement fires. But that also makes the “real” cursor, before I move it, flash in the “forbidden area” if the user holds the mouse against the area in which I don’t want the mouse to go.

I will potentially use: Globally hiding cursor (from background app) but I doubt that would be Mac App Store legal.

Any ideas?

EDIT: How I create the event tap:

eventTap = CGEventTapCreate(kCGHIDEventTap, kCGHeadInsertEventTap, kCGEventTapOptionDefault, kCGEventMaskForAllEvents, myCGEventCallback, NULL);

…

    CGEventRef myCGEventCallback(CGEventTapProxy proxy, CGEventType type, CGEventRef event, void *refcon)
{
    if (type == kCGEventMouseMoved) {
        event = [refToSelf mouseMovedEvent:event];
    }

    ...

    return event;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T23:00:24+00:00Added an answer on May 31, 2026 at 11:00 pm

    You’re trying to modify events at the kCGHIDEventTap location, which

    Specifies that an event tap is placed at the point where HID system events enter the window server.

    Unfortunately, the CGEventTapCreate() doc says:

    Only processes running as the root user may locate an event tap at the point where HID events enter the window server; for other users, this function returns NULL.

    I suspect this is strongly related to your difficulty, although the docs don’t seem to match up with exactly what’s happening (they are more than four years old).

    Perhaps you can spin this functionality off into a separate process that has super-user permissions, leaving the rest of your app in normal user mode? I believe there’s also a way to request root permissions for just a specific action taken by your program.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an iPhone app that will incorporate liking / +1 with a global
I would like to have a global variable in my django app that stores
Background I have an app that I recently updated to Rails 3.2.1 (from Rails
So I have this app that receives packages from cell phones including gps time
I have a Help mode in my app that tells all the buttons to
I want to have a global array/variable in an iPhone app that uses storyboard.
I have put one global tabBarController in iphone app that I have been working
I have some settings in my app.config which I intend to be 'global' -
If i have global variable in A.dll, that depends on global variable in B.dll
I'd like to build an app that does not have a menubar, a dock

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.