Re: [Pyobjc-dev] unexpected error
Brought to you by:
ronaldoussoren
|
From: Eric Le L. <ker...@us...> - 2014-10-08 15:17:29
|
Le Wed, 8 Oct 2014 08:56:29 -0500,
Ken Thomases <ke...@co...> a écrit :
> On Oct 8, 2014, at 5:48 AM, Eric Le Lay
> <ker...@us...> wrote:
>
> > tap = Quartz.CGEventTapCreate(
> > Quartz.kCGSessionEventTap,
> > Quartz.kCGHeadInsertEventTap,
> > Quartz.kCGEventTapOptionDefault,
> > # NSSystemDefined for media keys
> > Quartz.CGEventMaskBit(NSSystemDefined),
> > self.eventTap,
> > None
> > )
> > port =
> > NSMachPort.alloc().initWithMachPort_options_(CFMachPortGetPort(tap),
> > NSMachPortDeallocateNone) loop = NSRunLoop.currentRunLoop()
> > loop.addPort_forMode_(port, NSDefaultRunLoopMode)
>
> Why are you not doing what the docs for CGEventTapCreate() suggest:
> pass the CFMachPortRef returned from it to
> CFMachPortCreateRunLoopSource() and then add the resulting source to
> the run loop using CFRunLoopAddSource()?
>
Ken,
thank you for your answer.
The actual code is part of a gtk application.
It used to do as you suggest:
tap = Quartz.CGEventTapCreate(...)
runLoopSource = Quartz.CFMachPortCreateRunLoopSource(None, tap, 0)
Quartz.CFRunLoopAddSource(
Quartz.CFRunLoopGetCurrent(),
runLoopSource,
Quartz.kCFRunLoopDefaultMode
)
Quartz.CGEventTapEnable(tap, True)
The event was not processed until the main window got focus and then
the eventtap was disabled because it had not answered in time.
I stumbled upon the macrumors post about the same problem and
tried that code. It seemed to make sense and did work in objective-c
so I thought it would work just as well in python.
Now, the objective-c has the same problem + can't close the main
window or it freezes the computer. I can live with the event not being
delivered until the main window shows up. I then re-enable the
tap as I receive the disabled event.
Thanks again for your time,
Eric
|