From ed4b26b2c8359571be0613682adf9e4c3fab7c7b Mon Sep 17 00:00:00 2001 From: David Capello Date: Mon, 11 Apr 2016 14:49:26 -0300 Subject: [PATCH] Add get_unicodechar_from_nsevent() to she/osx/view.mm --- src/she/osx/view.mm | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/she/osx/view.mm b/src/she/osx/view.mm index 1ba6f3c94..1cc771011 100644 --- a/src/she/osx/view.mm +++ b/src/she/osx/view.mm @@ -59,6 +59,19 @@ inline KeyModifiers get_modifiers_from_nsevent(NSEvent* event) return (KeyModifiers)modifiers; } +inline int get_unicodechar_from_nsevent(NSEvent* event) +{ + int chr = 0; + // TODO we should use "event.characters" for a new kind of event (Event::Char or something like that) + NSString* chars = event.charactersIgnoringModifiers; + if (chars && chars.length >= 1) { + chr = [chars characterAtIndex:0]; + if (chr < 32) + chr = 0; + } + return chr; +} + } // anonymous namespace namespace she { @@ -142,11 +155,7 @@ bool is_key_pressed(KeyScancode scancode) ev.setScancode(scancode); ev.setModifiers(get_modifiers_from_nsevent(event)); ev.setRepeat(event.ARepeat ? 1: 0); - - // TODO we should use event.characters - NSString* chars = event.charactersIgnoringModifiers; - if (chars && chars.length >= 1) - ev.setUnicodeChar([chars characterAtIndex:0]); + ev.setUnicodeChar(get_unicodechar_from_nsevent(event)); queue_event(ev); } @@ -164,11 +173,7 @@ bool is_key_pressed(KeyScancode scancode) ev.setScancode(scancode); ev.setModifiers(get_modifiers_from_nsevent(event)); ev.setRepeat(event.ARepeat ? 1: 0); - - // TODO we should use event.characters - NSString* chars = event.charactersIgnoringModifiers; - if (chars && chars.length >= 1) - ev.setUnicodeChar([chars characterAtIndex:0]); + ev.setUnicodeChar(get_unicodechar_from_nsevent(event)); queue_event(ev); }