Re: How to create secondary Thread that listens to event taps?
Re: How to create secondary Thread that listens to event taps?
- Subject: Re: How to create secondary Thread that listens to event taps?
- From: Rainer Brockerhoff <email@hidden>
- Date: Sun, 17 Oct 2010 17:48:40 -0200
At 12:01 -0700 17/10/10, email@hidden wrote:
>From: eveningnick eveningnick <email@hidden>
>Date: Sun, 17 Oct 2010 20:25:02 +0300
>Message-ID: <email@hidden>
>
>So, i decided to do the following - i will execute the "long action"
>in a main thread, and create an "Esc-listening thread" that will
>install a system-wide keyboard EventTap (which watches ESC presses,
>and if it gets any, it rises the cancellation flag - this flag is
>periodically checked in the main thread's "long alhorithm").
>
>The thing i can't understand - is how to make that secondary thread to
>have a run loop, and how to make it not to finish as soon as i have
>created it - but to watch its own run loop for "event taps"'s events.
You create the secondary thread, install the event tap in it as usual - that is, create a run loop source for the tap and add the source to the current run loop returned by CFRunLoopGetCurrent() - and then, erhm, run the run loop in a loop :-)
Something like (warning: typed in Eudora):
while (someCondition) {
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
SInt32 result = CFRunLoopRunInMode(kCFRunLoopDefaultMode,0.5,YES);
[pool drain];
if (result==kCFRunLoopRunStopped)) {
return;
}
}
should work.
HTH,
--
Rainer Brockerhoff <email@hidden>
Belo Horizonte, Brazil
"In the affairs of others even fools are wise
In their own business even sages err."
Blog: http://brockerhoff.net/blog
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden