diff --git a/lib/matplotlib/backends/backend_qt4.py b/lib/matplotlib/backends/backend_qt4.py index a114eb88949d..f92c5f86f3df 100644 --- a/lib/matplotlib/backends/backend_qt4.py +++ b/lib/matplotlib/backends/backend_qt4.py @@ -349,6 +349,15 @@ def _get_key(self, event): # key, rather than unicode key = SPECIAL_KEYS[event_key] except KeyError: + # unicode defines code points up to 0x0010ffff + # QT will use Key_Codes larger than that for keyboard keys that are + # are not unicode characters (like multimedia keys) + # skip these + # if you really want them, you should add them to SPECIAL_KEYS + MAX_UNICODE = 0x10ffff + if event_key > MAX_UNICODE: + return None + key = unichr(event_key) # qt delivers capitalized letters. fix capitalization # note that capslock is ignored diff --git a/lib/matplotlib/tests/test_backend_qt4.py b/lib/matplotlib/tests/test_backend_qt4.py index 2f29a35eb6d5..465c8f14142b 100644 --- a/lib/matplotlib/tests/test_backend_qt4.py +++ b/lib/matplotlib/tests/test_backend_qt4.py @@ -149,3 +149,11 @@ def test_backspace_mod(): assert_correct_key(QtCore.Qt.Key_Backspace, ControlModifier, u'ctrl+backspace') + + +@cleanup +@knownfailureif(not HAS_QT) +def test_non_unicode_key(): + assert_correct_key(QtCore.Qt.Key_Play, + QtCore.Qt.NoModifier, + None)