Fix KeyRelease event with CMD key pressed (close #381)

Solution based on pull request #401
This commit is contained in:
Marco Antognini 2013-06-27 15:22:56 +02:00
parent 513cd7e57c
commit fc63a727ce
4 changed files with 25 additions and 5 deletions

View File

@ -27,12 +27,13 @@
// Headers
////////////////////////////////////////////////////////////
#import <Foundation/Foundation.h>
#import <AppKit/AppKit.h>
////////////////////////////////////////////////////////////
/// \brief Event processing
///
////////////////////////////////////////////////////////////
@interface SFApplication : NSObject
@interface SFApplication : NSApplication
////////////////////////////////////////////////////////////
@ -42,4 +43,13 @@
+(void)processEvent;
////////////////////////////////////////////////////////////
/// \brief Dispatch events
///
/// This overload of -[NSApplication sendEvent:] is used to
/// fix KeyRelease events when the command key is down.
////////////////////////////////////////////////////////////
-(void)sendEvent:(NSEvent *)anEvent;
@end

View File

@ -27,7 +27,6 @@
// Headers
////////////////////////////////////////////////////////////
#import <SFML/Window/OSX/SFApplication.h>
#import <AppKit/AppKit.h>
////////////////////////////////////////////////////////////
@ -37,7 +36,7 @@
////////////////////////////////////////////////////////////
+(void)processEvent
{
[NSApplication sharedApplication]; // Make sure NSApp exists
[SFApplication sharedApplication]; // Make sure NSApp exists
NSEvent* event = nil;
while ((event = [NSApp nextEventMatchingMask:NSAnyEventMask
@ -49,6 +48,16 @@
}
}
- (void)sendEvent:(NSEvent *)anEvent
{
if ([anEvent type] == NSKeyUp) {
[[[self mainWindow] firstResponder] tryToPerform:@selector(keyUp:)
with:anEvent];
} else {
[super sendEvent:anEvent];
}
}
@end

View File

@ -432,7 +432,7 @@
[icon addRepresentation:bitmap];
// Set app icon.
[[NSApplication sharedApplication] setApplicationIconImage:icon];
[[SFApplication sharedApplication] setApplicationIconImage:icon];
// Free up.
[icon release];

View File

@ -34,6 +34,7 @@
#import <SFML/Window/OSX/SFViewController.h>
#import <SFML/Window/OSX/cpp_objc_conversion.h>
#import <SFML/Window/OSX/AutoreleasePoolWrapper.h>
#import <SFML/Window/OSX/SFApplication.h>
namespace sf
{
@ -136,7 +137,7 @@ void WindowImplCocoa::setUpProcess(void)
}
// Tell the application to stop bouncing in the Dock.
[[NSApplication sharedApplication] finishLaunching];
[[SFApplication sharedApplication] finishLaunching];
// NOTE : This last call won't harm anything even if SFML window was
// created with an external handle.
}