diff options
-rw-r--r-- | src/gui/kernel/qevent.cpp | 4 | ||||
-rw-r--r-- | src/gui/kernel/qkeymapper.cpp | 3 | ||||
-rw-r--r-- | src/gui/platform/unix/qxkbcommon.cpp | 3 | ||||
-rw-r--r-- | src/plugins/platforms/cocoa/qcocoakeymapper.mm | 6 | ||||
-rw-r--r-- | src/plugins/platforms/cocoa/qnsview_keys.mm | 22 |
5 files changed, 20 insertions, 18 deletions
diff --git a/src/gui/kernel/qevent.cpp b/src/gui/kernel/qevent.cpp index 087873d67e..38906df6cb 100644 --- a/src/gui/kernel/qevent.cpp +++ b/src/gui/kernel/qevent.cpp @@ -1663,10 +1663,6 @@ QKeyEvent::~QKeyEvent() Note: The native scan code may be 0, even if the key event contains extended information. - - Note: On \macos, this function is not useful, because there is no - way to get the scan code from the system APIs. The function always - returns 1 (or 0 in the case explained above). */ /*! diff --git a/src/gui/kernel/qkeymapper.cpp b/src/gui/kernel/qkeymapper.cpp index 89eacc944a..19b0e15279 100644 --- a/src/gui/kernel/qkeymapper.cpp +++ b/src/gui/kernel/qkeymapper.cpp @@ -83,9 +83,6 @@ static QList<int> extractKeyFromEvent(QKeyEvent *e) QList<int> QKeyMapper::possibleKeys(QKeyEvent *e) { - if (!e->nativeScanCode()) - return extractKeyFromEvent(e); - return instance()->d_func()->possibleKeys(e); } diff --git a/src/gui/platform/unix/qxkbcommon.cpp b/src/gui/platform/unix/qxkbcommon.cpp index 71f1cfd24a..02b5ab5164 100644 --- a/src/gui/platform/unix/qxkbcommon.cpp +++ b/src/gui/platform/unix/qxkbcommon.cpp @@ -621,6 +621,9 @@ QList<int> QXkbCommon::possibleKeys(xkb_state *state, const QKeyEvent *event, { QList<int> result; quint32 keycode = event->nativeScanCode(); + if (!keycode) + return result; + Qt::KeyboardModifiers modifiers = event->modifiers(); xkb_keymap *keymap = xkb_state_get_keymap(state); // turn off the modifier bits which doesn't participate in shortcuts 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; |