summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/platforms')
-rw-r--r--src/plugins/platforms/cocoa/qcocoakeymapper.mm6
-rw-r--r--src/plugins/platforms/cocoa/qnsview_keys.mm22
2 files changed, 17 insertions, 11 deletions
diff --git a/src/plugins/platforms/cocoa/qcocoakeymapper.mm b/src/plugins/platforms/cocoa/qcocoakeymapper.mm
index 3b699e3237..dca7b576f6 100644
--- a/src/plugins/platforms/cocoa/qcocoakeymapper.mm
+++ b/src/plugins/platforms/cocoa/qcocoakeymapper.mm
@@ -513,7 +513,11 @@ QList<int> QCocoaKeyMapper::possibleKeys(const QKeyEvent *event) const
{
QList<int> ret;
- auto keyMap = keyMapForKey(event->nativeVirtualKey(), QChar(event->key()));
+ const auto nativeVirtualKey = event->nativeVirtualKey();
+ if (!nativeVirtualKey)
+ return ret;
+
+ auto keyMap = keyMapForKey(nativeVirtualKey, QChar(event->key()));
auto unmodifiedKey = keyMap[Qt::NoModifier];
Q_ASSERT(unmodifiedKey != Qt::Key_unknown);
diff --git a/src/plugins/platforms/cocoa/qnsview_keys.mm b/src/plugins/platforms/cocoa/qnsview_keys.mm
index f6599edb81..09d78485f4 100644
--- a/src/plugins/platforms/cocoa/qnsview_keys.mm
+++ b/src/plugins/platforms/cocoa/qnsview_keys.mm
@@ -53,11 +53,12 @@
m_inputSource = [characters retain];
}
- // There is no way to get the scan code from carbon/cocoa. But we cannot
- // use the value 0, since it indicates that the event originates from somewhere
- // else than the keyboard.
- quint32 nativeScanCode = 1;
- quint32 nativeVirtualKey = [nsevent keyCode];
+ // Scan codes are hardware dependent codes for each key. There is no way to get these
+ // from Carbon or Cocoa, so leave it 0, as documented in QKeyEvent::nativeScanCode().
+ const quint32 nativeScanCode = 0;
+
+ // Virtual keys on the other hand are mapped to be the same keys on any system
+ const quint32 nativeVirtualKey = nsevent.keyCode;
QChar ch = QChar::ReplacementCharacter;
int keyCode = Qt::Key_unknown;
@@ -195,11 +196,12 @@
ulong nativeModifiers = [nsevent modifierFlags];
Qt::KeyboardModifiers modifiers = QCocoaKeyMapper::fromCocoaModifiers(nativeModifiers);
- // There is no way to get the scan code from carbon/cocoa. But we cannot
- // use the value 0, since it indicates that the event originates from somewhere
- // else than the keyboard.
- quint32 nativeScanCode = 1;
- quint32 nativeVirtualKey = [nsevent keyCode];
+ // Scan codes are hardware dependent codes for each key. There is no way to get these
+ // from Carbon or Cocoa, so leave it 0, as documented in QKeyEvent::nativeScanCode().
+ const quint32 nativeScanCode = 0;
+
+ // Virtual keys on the other hand are mapped to be the same keys on any system
+ const quint32 nativeVirtualKey = nsevent.keyCode;
// calculate the delta and remember the current modifiers for next time
static ulong m_lastKnownModifiers;