Problem with PyObjC and NSEvents

kle klemily097 at gmail.com
Thu Jul 25 14:30:35 EDT 2013


Hello all,

I am having a rather specialized problem involving PyObjC and receiving NSEvents, and I'm wondering whether anybody here might have any insight. 

I'm writing a Python program, using PyObjC, that runs in the background and registers whenever the user clicks the mouse, in any application.

I do this using an NSEvents global events monitor:

NSEvent.addGlobalMonitorForEventsMatchingMask_handler_(NSLeftMouseDownMask, handler)

where "handler" is the name of my handler method.

The code works fine when I run the .py file from the command line -- my handler method is called whenever I click the mouse, and everything happens as expected.

However, when I bundle it into a standalone app (using py2app) and run it, the app fails to register clicks. I have gotten it to work intermittently -- sometimes it will start working after the app has been brought to the front for the first time. But for the most part, it doesn't register the clicks at all.

Any ideas on what I might try to get it working? I am not sure whether this is an NSEvents problem or a PyObjC problem, or just a me being stupid problem. But any help or guidance would be greatly appreciated. 

Thanks,

Emily



More information about the Python-list mailing list