From 0fd992d56e23859f25057ea2878c7e19eced294a Mon Sep 17 00:00:00 2001 From: Marco Antognini Date: Sat, 24 Sep 2011 13:34:58 +0200 Subject: [PATCH] fix OS X alert related to key event (close #98) --- src/SFML/Window/OSX/SFOpenGLView.mm | 10 ++++++---- src/SFML/Window/OSX/SFWindow.m | 18 ++++++++++++++++-- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/src/SFML/Window/OSX/SFOpenGLView.mm b/src/SFML/Window/OSX/SFOpenGLView.mm index 9686ee02..7eb45da0 100644 --- a/src/SFML/Window/OSX/SFOpenGLView.mm +++ b/src/SFML/Window/OSX/SFOpenGLView.mm @@ -520,11 +520,13 @@ NSUInteger KeepOnlyMaskFromData(NSUInteger data, NSUInteger mask); // Handle text entred event - // We create a new event without command modifiers + // We create a new event without command/ctrl modifiers // to prevent the OS from sending an alert - NSUInteger modifiers = [theEvent modifierFlags] & NSCommandKeyMask - ? [theEvent modifierFlags] & ~NSCommandKeyMask - : [theEvent modifierFlags]; + NSUInteger modifiers = [theEvent modifierFlags]; + + if (modifiers & NSCommandKeyMask) modifiers = modifiers & ~NSCommandKeyMask; + if (modifiers & NSControlKeyMask) modifiers = modifiers & ~NSControlKeyMask; + NSEvent* ev = [NSEvent keyEventWithType:NSKeyDown location:[theEvent locationInWindow] modifierFlags:modifiers diff --git a/src/SFML/Window/OSX/SFWindow.m b/src/SFML/Window/OSX/SFWindow.m index f6ba6e8a..98296aa4 100644 --- a/src/SFML/Window/OSX/SFWindow.m +++ b/src/SFML/Window/OSX/SFWindow.m @@ -32,14 +32,28 @@ @implementation SFWindow //////////////////////////////////////////////////////// --(BOOL)acceptsFirstResponder { +-(BOOL)acceptsFirstResponder +{ return YES; } //////////////////////////////////////////////////////// --(BOOL)canBecomeKeyWindow { +-(BOOL)canBecomeKeyWindow +{ return YES; } +//////////////////////////////////////////////////////// +-(void)keyDown:(NSEvent *)theEvent +{ + // Do nothing except preventing a system alert each time a key is pressed + // + // Special Consideration : + // ----------------------- + // Consider overriding NSResponder -keyDown: message in a Cocoa view/window + // that contains a SFML rendering area. Doing so will prevent a system + // alert to be thrown everytime the user presses a key. +} + @end