Re: NSevent handling in panther
Re: NSevent handling in panther
- Subject: Re: NSevent handling in panther
- From: glenn andreas <email@hidden>
- Date: Sun, 27 Feb 2005 12:30:50 -0600
On Feb 27, 2005, at 11:25 AM, Dingcai Cao wrote:
Dear all,
Currently I encountered a very strange situation. I developed some objective-C codes for gamepad event handling long time ago in Jaguar's project builder, which worked very well. Now I tried to run the same codes in Panther's Xcode. There was no problem to recompile the program, but I could not run it. The warning message looked like this:
2005-02-26 22:12:04.724 CFF[934] *** Assertion failure in -[NSEvent keyCode], AppKit.subproj/NSEvent.m:871
2005-02-26 22:12:04.729 CFF[934] Invalid message sent to event "NSEvent: type=SysDefined loc=(682,505) time=16551.7 flags=0x100 win=0 winNum=0 ctxt=0xc2a7 subtype=7 data1=1 data2=0"
Note CFF is the name of my project. I understand the message indicates run-time errors. But I have no idea why the same code was OK in Jaguar but not in Panther. Can anyone tell me what is going on? I highly appreciate your help. Here are my codes.
Dingcai Cao
@implementation GamePad
-(void) setEvent {
distantPast= [[NSDate distantPast] retain];
event = [NSApp
nextEventMatchingMask: NSAnyEventMask
untilDate: distantPast
inMode: NSDefaultRunLoopMode
dequeue: YES ];
So you grab any random possible event...
eventKey = [event performSelector:@selector(keyCode)];
... and you send have it execute "keyCode".
The problem is that the event is:
NSEvent: type=SysDefined loc=(682,505) time=16551.7 flags=0x100 win=0 winNum=0 ctxt=0xc2a7 subtype=7 data1=1 data2=0"
which means that this is some sort of "system defined" event which doesn't respond to keyCode. (and since this is some sort of system specific undocumented event, it's quite reasonable that there would be different behavior between Jaguar and Panther), and according to the headers:
/* this message is valid for keyup, keydown and flagschanged events */
- (unsigned short)keyCode; /* device-independent key number */
The fix is simple, don't call 'keyCode' unless you know that you've got an NSKeyDown. (so move that down into your NSKeyDown case).
Glenn Andreas email@hidden
<http://www.gandreas.com/> oh my!
Mad, Bad, and Dangerous to Know
_______________________________________________
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