From ae489fa5d0ef74d3f428fa89c15f06c6a4fe8c07 Mon Sep 17 00:00:00 2001 From: Marco Antognini Date: Tue, 19 Jul 2011 15:06:52 +0200 Subject: [PATCH] Prevent Mac OS from sending a sound/visual alert when command is pressed with another key --- src/SFML/Window/OSX/SFOpenGLView.mm | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/SFML/Window/OSX/SFOpenGLView.mm b/src/SFML/Window/OSX/SFOpenGLView.mm index f666753f..a1ac49c1 100644 --- a/src/SFML/Window/OSX/SFOpenGLView.mm +++ b/src/SFML/Window/OSX/SFOpenGLView.mm @@ -484,16 +484,32 @@ NSUInteger KeepOnlyMaskFromData(NSUInteger data, NSUInteger mask); // Handle text entred event - if ((myUseKeyRepeat || ![theEvent isARepeat]) && [[theEvent characters] length] > 0) { + // We create a new event without command modifiers + // to prevent the OS from sending an alert + NSUInteger modifiers = [theEvent modifierFlags] & NSCommandKeyMask + ? [theEvent modifierFlags] & ~NSCommandKeyMask + : [theEvent modifierFlags]; + NSEvent* ev = [NSEvent keyEventWithType:NSKeyDown + location:[theEvent locationInWindow] + modifierFlags:modifiers + timestamp:[theEvent timestamp] + windowNumber:[theEvent windowNumber] + context:[theEvent context] + characters:[theEvent characters] + charactersIgnoringModifiers:[theEvent charactersIgnoringModifiers] + isARepeat:[theEvent isARepeat] + keyCode:[theEvent keyCode]]; + + if ((myUseKeyRepeat || ![ev isARepeat]) && [[ev characters] length] > 0) { // Ignore escape key and non text keycode. (See NSEvent.h) // They produce a sound alert. - unichar code = [[theEvent characters] characterAtIndex:0]; - if ([theEvent keyCode] != 0x35 && (code < 0xF700 || code > 0xF8FF)) { + unichar code = [[ev characters] characterAtIndex:0]; + if ([ev keyCode] != 0x35 && (code < 0xF700 || code > 0xF8FF)) { // Let's see if its a valid text. NSText* text = [[self window] fieldEditor:YES forObject:self]; - [text interpretKeyEvents:[NSArray arrayWithObject:theEvent]]; + [text interpretKeyEvents:[NSArray arrayWithObject:ev]]; NSString* string = [text string]; if ([string length] > 0) {