Re: CGEventCreateKeyboardEvent just crashes?!?
Re: CGEventCreateKeyboardEvent just crashes?!?
- Subject: Re: CGEventCreateKeyboardEvent just crashes?!?
- From: Eric Schlegel <email@hidden>
- Date: Wed, 4 Oct 2006 07:37:33 -0700
On Oct 4, 2006, at 4:56 AM, Ondra Cada wrote:
Hi all,
anybody can use CGEventCreateKeyboardEvent?
I create the simplest project possible. Call the function exactly
the way it's documented. And always got a nice small SIGBUS...
Here's my source:
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
// insert code here...
NSLog(@"Hello, Apple World! What's there with them blasted
events?!?");
CGEventRef er=CGEventCreateKeyboardEvent (NULL, (CGKeyCode)56,
true); // directly from docs
NSLog(@"actually, got event ref at %x. Bye.",er);
[pool release];
return 0;
}
The problem is that CGEventCreateKeyboardEvent is supposed to use the
default event source if you pass NULL for the first param, but a bug
in the Tiger implementation caused it to not initialize the default
source soon enough and so it crashed when attempting to use it. This
has been fixed in Leopard. The recommended workaround is to call
CFRelease(CGEventCreate(NULL)) before calling the other APIs.
-eric
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden