From e3cf87bb754b10eae4c6d852d912d1b107ee03ed Mon Sep 17 00:00:00 2001 From: Shawn Rutledge Date: Wed, 26 Jun 2013 10:22:54 +0200 Subject: Mac OSX: get the correct key code when the control key is pressed The control key results in modifiers having Qt::MetaModifier, and then the correct character is found in charactersIgnoringModifiers. The rest of the time, [nsevent characters] seems to be correct. If we use charactersIgnoringModifiers too much of the time, then the keycode will be wrong in some cases even though typing is still possible. Task-number: QTBUG-29005 Task-number: QTBUG-31811 Task-number: QTBUG-31977 Change-Id: Ib23b89f03bc9a61fe6d177320fa603c05649e979 Reviewed-by: Eike Ziller Reviewed-by: Frederik Gladhorn --- src/plugins/platforms/cocoa/qnsview.mm | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/plugins/platforms/cocoa/qnsview.mm b/src/plugins/platforms/cocoa/qnsview.mm index ab3f495a60..94b414a882 100644 --- a/src/plugins/platforms/cocoa/qnsview.mm +++ b/src/plugins/platforms/cocoa/qnsview.mm @@ -914,6 +914,7 @@ static QTouchDevice *touchDevice = 0; ulong timestamp = [nsevent timestamp] * 1000; ulong nativeModifiers = [nsevent modifierFlags]; Qt::KeyboardModifiers modifiers = [QNSView convertKeyModifiers: nativeModifiers]; + NSString *charactersIgnoringModifiers = [nsevent charactersIgnoringModifiers]; NSString *characters = [nsevent characters]; // [from Qt 4 impl] There is no way to get the scan code from carbon. But we cannot @@ -928,7 +929,10 @@ static QTouchDevice *touchDevice = 0; QChar ch = QChar::ReplacementCharacter; int keyCode = Qt::Key_unknown; if ([characters length] != 0) { - ch = QChar([characters characterAtIndex:0]); + if ((modifiers & Qt::MetaModifier) && ([charactersIgnoringModifiers length] != 0)) + ch = QChar([charactersIgnoringModifiers characterAtIndex:0]); + else + ch = QChar([characters characterAtIndex:0]); keyCode = [self convertKeyCode:ch]; } -- cgit v1.2.3