From 19a6c50061ec2feb86895c6ffee500bf58c14809 Mon Sep 17 00:00:00 2001 From: "Bradley T. Hughes" Date: Tue, 22 May 2012 13:41:50 +0200 Subject: Cocoa: Handle keyboard dead keys correctly MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Some keyboard layouts have physical dead keys (like the ¨ key on a Norwegian keyboard). These do not send any text, so we should not use [NSString characterAtIndex:0] if the string is empty. When encountering an empty [NSEvent character] string, use Qt::Key_unknown and QChar::ReplacementCharacter. Change-Id: I7281aa9ea6005341c0dcfa5900bfe601e4eac6a9 Reviewed-by: Morten Johan Sørvig --- src/plugins/platforms/cocoa/qnsview.mm | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/plugins/platforms/cocoa/qnsview.mm b/src/plugins/platforms/cocoa/qnsview.mm index 09ba1c50ae..e0fc678656 100644 --- a/src/plugins/platforms/cocoa/qnsview.mm +++ b/src/plugins/platforms/cocoa/qnsview.mm @@ -612,8 +612,18 @@ static QTouchDevice *touchDevice = 0; ulong timestamp = [nsevent timestamp] * 1000; Qt::KeyboardModifiers modifiers = [self convertKeyModifiers:[nsevent modifierFlags]]; NSString *charactersIgnoringModifiers = [nsevent charactersIgnoringModifiers]; - QChar ch([charactersIgnoringModifiers characterAtIndex:0]); - int keyCode = [self convertKeyCode:ch]; + + QChar ch; + int keyCode; + if ([charactersIgnoringModifiers length] > 0) { + // convert the first character into a key code + ch = QChar([charactersIgnoringModifiers characterAtIndex:0]); + keyCode = [self convertKeyCode:ch]; + } else { + // might be a dead key + ch = QChar::ReplacementCharacter; + keyCode = Qt::Key_unknown; + } // we will send a key event unless the input method sets m_sendKeyEvent to false m_sendKeyEvent = true; -- cgit v1.2.3