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 8334963
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T03:31:06+00:00 2026-06-09T03:31:06+00:00

I am using CGEventPost() to programmatically post keyboard and mouse events. Those events will

  • 0

I am using CGEventPost() to programmatically post keyboard and mouse events. Those events will end up triggering other events/actions (e.g., certain windows become active, buttons are pressed, letters are entered in text fields). In order to synchronize threads, I would like to know when all of those events that were triggered by a specific CGEvent have finished processing.

All CGEventPost()s will end up acting on a single window of a single application.

EDIT:

Nielsbot’s solution worked just fine. I ended up with a rough implementation of MCL’s event-dispatch function for CCL. This function blocks until all current events in the Cocoa run process loop have finished executing. Since all keyboard and mouse events end up triggering actions that run on this thread, this approach works just fine.

My only worry with this is that the event-dispatch gets called ‘before’ the CGEvent triggers an action in the event loop, but my tests are currently showing that this is not happening. So I’m rolling with this solution for now.

Just FYSA, it seems to take a conservative 1ms for a posted event to hit the run loop, at least on my setup.

(defun event-dispatch ()
  (with-shadow (gui::queue-for-event-process
                 (lambda (f &key at-start)
                   (declare (ignore at-start)) 
                   (funcall fun-orig f :at-start nil))) 
    (gui::call-in-event-process (lambda () ()))))
  • 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-06-09T03:31:08+00:00Added an answer on June 9, 2026 at 3:31 am

    What about inserting a custom event type queue as a marker? Wait until that event triggers some of your own code–this might give good enough indication that all previous events posted by you have been handled…

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

Sidebar

Related Questions

I'm using CGEventCreateKeyboardEvent to create and CGEventPost to post an event on the Mac.
I am trying to generate keyboard keydown and keyup events programmatically. I am currently
For an app I am working on I am using CGEventPost to post some
Using a CSS image sprite, I'm creating an 'interactive' image where hovering over certain
I've been using the following code to issue clicks programmatically on a Mac void
Using php/html, I want to retrieve email addresses (plus other information) from MySQL and
I'm trying to post a keyboard event to trigger a Space change. By default
Using restlet, I want to make a post to android's c2dm service. I have
Using the http://www.ifans.com/forums/showthread.php?t=132024 post from another question i am allowing the user to enter
I'm using the following code to simulate a click of the mouse: void PostMouseEvent(CGMouseButton

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.