From 1066caa77185c0c377858e3546fd12617fe8330b Mon Sep 17 00:00:00 2001 From: Marco Antognini Date: Sun, 3 Jul 2011 22:29:34 +0200 Subject: [PATCH] Fix annoying sound alert when escape is pressed on OS X --- src/SFML/Window/OSX/SFOpenGLView.mm | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/src/SFML/Window/OSX/SFOpenGLView.mm b/src/SFML/Window/OSX/SFOpenGLView.mm index b5f68708..87fd8df1 100644 --- a/src/SFML/Window/OSX/SFOpenGLView.mm +++ b/src/SFML/Window/OSX/SFOpenGLView.mm @@ -448,17 +448,24 @@ sf::Key::Code NonLocalizedKeys(unsigned short keycode); } } - if (myUseKeyRepeat || ![theEvent isARepeat]) { - // Let's see if its a valid text. - NSText* text = [[self window] fieldEditor:YES forObject:self]; - [text interpretKeyEvents:[NSArray arrayWithObject:theEvent]]; + if ((myUseKeyRepeat || ![theEvent isARepeat]) && [[theEvent characters] length] > 0) { - NSString* string = [text string]; - if ([string length] > 0) { - // It's a valid TextEntered event. - myRequester->TextEntered([string characterAtIndex: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)) { - [text setString:@""]; + // Let's see if its a valid text. + NSText* text = [[self window] fieldEditor:YES forObject:self]; + [text interpretKeyEvents:[NSArray arrayWithObject:theEvent]]; + + NSString* string = [text string]; + if ([string length] > 0) { + // It's a valid TextEntered event. + myRequester->TextEntered([string characterAtIndex:0]); + + [text setString:@""]; + } } } }