Re: Responder problem [flagsChanged cmd keyUp solved]
Re: Responder problem [flagsChanged cmd keyUp solved]
- Subject: Re: Responder problem [flagsChanged cmd keyUp solved]
- From: Ryan Stevens <email@hidden>
- Date: Wed, 8 Oct 2003 10:44:53 -0700
The list was in OT mode (Panther Seeds, I think it was) the day I
posted my question. Perhaps nobody had any ideas anyway* but wasting
several hours trying to find a solution for such a simple problem has
left me a little sore.
* I would've loved a reply that said, "RTF(NSApplication)M."
NSApplication: "All keyboard and mouse events go directly to the
NSWindow associated with the event. The only exception to this rule is
if the Command key is pressed when a key-down event occurs; in this
case, every NSWindow has an opportunity to respond to the event."
Notice that it doesn't say what happens to keyUp messages while the
Command key is down. So you'd think they would get sent as normal which
is obviously not the case.
Anyway, the solution:
I subclassed NSApplication and overrode sendEvent: like so..
- (void)sendEvent:(NSEvent *)anEvent
{
if ([anEvent type] == NSKeyUp) {
// should it be the keyWindow?
[[[self mainWindow] firstResponder]
tryToPerform:@selector(keyUp:) with:anEvent ];
// might as well return, it would get discarded anyway..
return;
}
[super sendEvent:anEvent];
}
It may not be very robust but it seems to work well enough for my
purposes.
On Thursday, October 2, 2003, at 08:25 AM, Ryan Stevens wrote:
My problem is that while the Command key is pressed I don't receive
keyUp messages. What's weird is that Control and Option don't seem to
do the same thing.
I thought that maybe it was getting translated into a moveToEndOfLine:
or moveToBeginningOfLine: message somewhere but my responder never
receives those.
Here's the basics...
- (void)flagsChanged:(NSEvent *)event
{
if ([event modifierFlags] == NSCommandKeyMask) {/*...*/}
[super flagsChanged:event];
}
- (void)moveLeft:(id)sender { keyDown = YES; direction = NO; }
- (void)moveRight:(id)sender { keyDown = YES; direction = YES; }
- (void)keyUp:(NSEvent *)event { keyDown = NO; [super keyUp:event]; }
- (BOOL)animates
{ // If I missed a keyUp: message I animate needlessly. ugh!
return (keyDown);
}
- (void)animateOneFrame { /* Should only get here if a key is really
down.*/ }
Any ideas are welcome, I've been at this for several hours hunting for
a solution. TIA!
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.