From ce421eff9d5745a2227db4150304a8ea22096a3f Mon Sep 17 00:00:00 2001 From: Egor Yusov Date: Thu, 16 May 2019 23:07:02 -0700 Subject: NativeApp: added key released event handling on MacOS --- .../Apple/Source/Classes/OSX/ViewController.mm | 26 ++++++++++++++++++---- Common/NativeApp/include/MacOS/MacOSAppBase.h | 1 + 2 files changed, 23 insertions(+), 4 deletions(-) (limited to 'Common') diff --git a/Common/NativeApp/Apple/Source/Classes/OSX/ViewController.mm b/Common/NativeApp/Apple/Source/Classes/OSX/ViewController.mm index 9559284..0df734b 100644 --- a/Common/NativeApp/Apple/Source/Classes/OSX/ViewController.mm +++ b/Common/NativeApp/Apple/Source/Classes/OSX/ViewController.mm @@ -97,7 +97,8 @@ [self mouseMove: theEvent]; } -- (void)keyDown:(NSEvent *)theEvent { +- (void)keyEvent:(NSEvent *)theEvent isKeyPressed:(bool)keyPressed +{ unichar c = [[theEvent charactersIgnoringModifiers] characterAtIndex:0]; int key = 0; switch(c){ @@ -106,18 +107,35 @@ case 0x7F: key = '\b'; break; default: key = c; } - + { auto* view = (ViewBase*)self.view; auto* theApp = [view lockApp]; if(theApp) - theApp->OnKeyPressed(key); + { + if (keyPressed) + theApp->OnKeyPressed(key); + else + theApp->OnKeyReleased(key); + } [view unlockApp]; } - +} + +- (void)keyDown:(NSEvent *)theEvent +{ + [self keyEvent:theEvent isKeyPressed:true]; + [super keyDown:theEvent]; } +- (void)keyUp:(NSEvent *)theEvent +{ + [self keyEvent:theEvent isKeyPressed:false]; + + [super keyUp:theEvent]; +} + - (BOOL)acceptsFirstResponder { return YES; } diff --git a/Common/NativeApp/include/MacOS/MacOSAppBase.h b/Common/NativeApp/include/MacOS/MacOSAppBase.h index d8df9df..2922ac9 100644 --- a/Common/NativeApp/include/MacOS/MacOSAppBase.h +++ b/Common/NativeApp/include/MacOS/MacOSAppBase.h @@ -39,6 +39,7 @@ public: virtual void OnMouseUp(int button){} virtual void OnMouseMove(int x, int y){} virtual void OnKeyPressed(int key){} + virtual void OnKeyReleased(int key){} protected: Timer timer; -- cgit v1.2.3