From 4af909c207cac35c27256005e1f525e0b29ff7ad Mon Sep 17 00:00:00 2001 From: ceylo Date: Sun, 14 Jun 2009 14:36:11 +0000 Subject: [PATCH] Fixed issue with beep produced by Esc and functions keys. git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/trunk@1142 4e206d99-4929-0410-ac5d-dfc041789085 --- src/SFML/Window/Cocoa/GLKit.mm | 9 ++++-- src/SFML/Window/Cocoa/WindowImplCocoa.hpp | 4 +++ src/SFML/Window/Cocoa/WindowImplCocoa.mm | 38 +++++++++++------------ 3 files changed, 29 insertions(+), 22 deletions(-) diff --git a/src/SFML/Window/Cocoa/GLKit.mm b/src/SFML/Window/Cocoa/GLKit.mm index a570f44bc..08215f723 100644 --- a/src/SFML/Window/Cocoa/GLKit.mm +++ b/src/SFML/Window/Cocoa/GLKit.mm @@ -287,9 +287,12 @@ static GLContext *sharedCtx = nil; { assert(myDelegate != NULL); - NSText *field = [[self window] fieldEditor:YES forObject:nil]; - [field interpretKeyEvents:[NSArray arrayWithObject:theEvent]]; - [field setString:@""]; + if (sf::priv::WindowImplCocoa::IsTextEvent((void *)theEvent)) + { + NSText *field = [[self window] fieldEditor:YES forObject:nil]; + [field interpretKeyEvents:[NSArray arrayWithObject:theEvent]]; + [field setString:@""]; + } myDelegate->HandleKeyDown(theEvent); } diff --git a/src/SFML/Window/Cocoa/WindowImplCocoa.hpp b/src/SFML/Window/Cocoa/WindowImplCocoa.hpp index bc93d54ce..23ca1397b 100644 --- a/src/SFML/Window/Cocoa/WindowImplCocoa.hpp +++ b/src/SFML/Window/Cocoa/WindowImplCocoa.hpp @@ -108,6 +108,10 @@ public : void HandleMouseMove(void *eventRef); void HandleMouseWheel(void *eventRef); + //////////////////////////////////////////////////////////// + /// Return whether 'ev' must be considered as a TextEntered event + //////////////////////////////////////////////////////////// + static bool IsTextEvent(void *event); private : //////////////////////////////////////////////////////////// diff --git a/src/SFML/Window/Cocoa/WindowImplCocoa.mm b/src/SFML/Window/Cocoa/WindowImplCocoa.mm index 3b66bbcce..4f9055355 100644 --- a/src/SFML/Window/Cocoa/WindowImplCocoa.mm +++ b/src/SFML/Window/Cocoa/WindowImplCocoa.mm @@ -511,6 +511,25 @@ void WindowImplCocoa::HandleMouseWheel(void *eventRef) } } +//////////////////////////////////////////////////////////// +/// Return whether 'ev' must be considered as a TextEntered event +//////////////////////////////////////////////////////////// +bool WindowImplCocoa::IsTextEvent(void *eventRef) +{ + NSEvent *event = (NSEvent *)eventRef; + bool res = false; + + if (event && [event type] == NSKeyDown && [[event characters] length]) { + unichar code = [[event characters] characterAtIndex:0]; + + // Codes from 0xF700 to 0xF8FF are non text keys (see NSEvent.h) + // 0x35 is the Escape key + if ([event keyCode] != 0x35 && (code < 0xF700 || code > 0xF8FF)) + res = true; + } + + return res; +} //////////////////////////////////////////////////////////// /// /see sfWindowImpl::Display @@ -797,25 +816,6 @@ static Key::Code KeyForUnicode(unsigned short uniCode) } -//////////////////////////////////////////////////////////// -/// Return whether 'ev' must be considered as a TextEntered event -//////////////////////////////////////////////////////////// -static bool IsTextEvent(NSEvent *event) -{ - bool res = false; - - if (event && [event type] == NSKeyDown && [[event characters] length]) { - unichar code = [[event characters] characterAtIndex:0]; - - // Codes from 0xF700 to 0xF8FF are non text keys (see NSEvent.h) - if (code < 0xF700 || code > 0xF8FF) - res = true; - } - - return res; -} - - } // namespace priv } // namespace sf