diff --git a/src/SFML/Window/OSX/SFApplication.m b/src/SFML/Window/OSX/SFApplication.m index c46aadbdc..d7b350a9c 100644 --- a/src/SFML/Window/OSX/SFApplication.m +++ b/src/SFML/Window/OSX/SFApplication.m @@ -42,7 +42,7 @@ while ((event = [NSApp nextEventMatchingMask:NSAnyEventMask untilDate:[NSDate distantPast] inMode:NSDefaultRunLoopMode - dequeue:YES])) // Remove the event from the dequeue + dequeue:YES])) // Remove the event from the queue { [NSApp sendEvent:event]; } @@ -50,9 +50,13 @@ -(void)sendEvent:(NSEvent *)anEvent { - if ([anEvent type] == NSKeyUp) { - [[[self mainWindow] firstResponder] tryToPerform:@selector(keyUp:) - with:anEvent]; + // Fullscreen windows have a strange behaviour with key up. To make + // sure the user gets an event we call (if possible) sfKeyUp on our + // custom OpenGL view. See -[SFOpenGLView sfKeyUp:] for more details. + + id firstResponder = [[anEvent window] firstResponder]; + if ([anEvent type] == NSKeyUp && [firstResponder respondsToSelector:@selector(sfKeyUp:)]) { + [firstResponder sfKeyUp:anEvent]; } else { [super sendEvent:anEvent]; } diff --git a/src/SFML/Window/OSX/SFOpenGLView.mm b/src/SFML/Window/OSX/SFOpenGLView.mm index 4f4ba4c27..bf53059c6 100644 --- a/src/SFML/Window/OSX/SFOpenGLView.mm +++ b/src/SFML/Window/OSX/SFOpenGLView.mm @@ -619,8 +619,15 @@ BOOL isValidTextUnicode(NSEvent* event); //////////////////////////////////////////////////////// --(void)keyUp:(NSEvent *)theEvent +-(void)sfKeyUp:(NSEvent *)theEvent { + // For some mystic reasons, key released events don't work the same way + // as key pressed events... We somewhat hijack the event chain of response + // in -[SFApplication sendEvent:] and resume this chain with the next + // responder. + // This is workaround to make sure key released events are fired in + // fullscreen window too. + // Transmit to non-SFML responder [[self nextResponder] keyUp:theEvent];