From bdc5554ca985f7ab3a0d3bf1db97de4bc087c6c3 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 27 Oct 2020 07:57:40 +0530 Subject: [PATCH] Viewer: Fix keyboard shortcuts using ctrl+alt+letter key not working on windows. Fixes #1900946 [E-book viewer: the "Create a new bookmark" shortcut only works after removing and recreating](https://bugs.launchpad.net/calibre/+bug/1900946) --- src/pyj/read_book/shortcuts.pyj | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/src/pyj/read_book/shortcuts.pyj b/src/pyj/read_book/shortcuts.pyj index 34659e6601..3e5d29c5f9 100644 --- a/src/pyj/read_book/shortcuts.pyj +++ b/src/pyj/read_book/shortcuts.pyj @@ -45,22 +45,17 @@ def shortcut_differs(a, b): return not (a.key is b.key and a.altKey is b.altKey and a.ctrlKey is b.ctrlKey and a.metaKey is b.metaKey and a.shiftKey is b.shiftKey) +capital_letters = {x: True for x in 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'} + + def get_key_text(evt): key = evt.key if key: - cc = key.charCodeAt(0) - # on windows in webengine pressing ctrl+ascii char gives us an ascii - # control code - # see https://bugreports.qt.io/browse/QTBUG-81783 - if (0 < cc < 32 or key is 'Enter' or key is 'Tab') and evt.ctrlKey and not evt.metaKey and not evt.altKey: - if key is 'Enter': - if evt.code and evt.code is not 'Enter': - key = 'm' - elif key is 'Tab': - if evt.code and evt.code is not 'Tab': - key = 'i' - else: - key = chr(96 + cc) + # on Windows pressing ctrl+alt+ascii char gives capital letters. On all + # platforms shift+key gives capital letters # we define shortcuts using + # lowercase letters, so lowercase them here. + if evt.code and key.toLowerCase() is not key and evt.code.startsWith('Key') and capital_letters[key]: + key = key.toLowerCase() return key @@ -191,7 +186,7 @@ def shortcuts_definition(): ), 'copy_to_clipboard': desc( - 'Ctrl+C', + 'Ctrl+c', 'ui', _('Copy to clipboard'), ),