09-06-2021, 02:59 PM | #16 |
Sigil Developer
Posts: 7,645
Karma: 5433388
Join Date: Nov 2009
Device: many
|
In Sigil Prefs (see Sigil/src/Dialogs/PreferenceWidgets/KeyboardShortcutsWidget.cpp) when assigning key sequences we capture the QKeyEvent and the key's generated key() and text(). The key() function is supposed to be independent of modifiers included according to Qt docs.
In our routine called translateModifiers() in this file we check to see if we need/should include the Shift Modifier by looking at the unicode character groupings of the text() which should be a '!' point (part of the Other Punctuation unicode group) and so the shift modifier should *not* be added in and the Ctrl+Shift+1 should be detected as Ctrl+! and that is what should be written to the ini file. Code:
int KeyboardShortcutsWidget::translateModifiers(Qt::KeyboardModifiers state, const QString &text) { int result = 0; // The shift modifier only counts when it is not used to type a symbol // that is only reachable using the shift key anyway if ((state & Qt::ShiftModifier) && (text.size() == 0 || !text.at(0).isPrint() || text.at(0).isLetterOrNumber() || text.at(0).isSpace() ) ) { result |= Qt::SHIFT; } I would love to see what QKeyEvent 's key() and text() returns immediately after setting nextKey in KeyboardShortcutsWidget::handleKeyEvent() when Ctrl+Shift+1 is entered on impacted machines so we can see why this is not being handled properly. Thanks! Last edited by KevinH; 09-06-2021 at 03:06 PM. |
09-06-2021, 04:11 PM | #17 |
Grand Sorcerer
Posts: 27,552
Karma: 193191846
Join Date: Jan 2010
Device: Nexus 7, Kindle Fire HD
|
When I hit the Ctrl+Shift+1 keys in Sigil's Keyboard shortcuts dialog in Linux, it is Ctrl+! that actually gets registered (and appears in the .ini file) and works to successfully trigger the clip replacement.
When I do the same thing in Windows, it is Ctrl+Shift+! that gets registered (and appears in the .ini file) and FAILS to successfully trigger the clip replacement. |
Advert | |
|
09-06-2021, 04:19 PM | #18 |
Guru
Posts: 692
Karma: 2180740
Join Date: Jan 2017
Location: Poland
Device: Misc
|
Debug:
Spoiler:
|
09-06-2021, 04:39 PM | #19 |
Sigil Developer
Posts: 7,645
Karma: 5433388
Join Date: Nov 2009
Device: many
|
It is 100% backwards on Windows than what the Qt docs say.
The key() should not reflect modifiers and it should be "1" not "!". The text() should reflect all modifiers and should return "!" since Shift+1 is the "!" not "1". So these functions are reversed somehow. If it is like that for all Windows keyboards we can reverse the values for just Windows. For macOS and Linux this works as documented by Qt. How strange! |
09-06-2021, 04:53 PM | #20 |
Sigil Developer
Posts: 7,645
Karma: 5433388
Join Date: Nov 2009
Device: many
|
Actually on macOS it is different. If I click Command+Shift+1 I get Ctrl+Shift+1 and not Ctrl+! in the field in Sigil's Preferences and in the ini file.
So all platforms appear to be slightly different. KevinH ps: Here is what happens on macOS: Debug: key(): "49" '1' Debug: text(): "" Debug: modifiers: QFlags<Qt::KeyboardModifier>(ShiftModifier|Control Modifier) So here the text() call is wrong completely as it is a null string but at least the key() call returned the value WITHOUT modifiers so the code just worked. Last edited by KevinH; 09-06-2021 at 05:05 PM. |
Advert | |
|
09-06-2021, 08:02 PM | #21 | ||
Sigil Developer
Posts: 7,645
Karma: 5433388
Join Date: Nov 2009
Device: many
|
I found the following in the Qt Docs ...
Quote:
Quote:
So this is pretty much a platform specific nightmare. And it appears to be based on other things as well. On macOS here are some test cases: - entered small h: key() returns 'H', text() returns 'h', no modifiers result: H - enter Shift + H: key() returns 'H', text() returns 'H', shift modifier result: Shift+H - entered Ctrl+Shift+1: key() returns '1', text() returns '', ctrl and shift modifiers result: Ctrl+Shift+1 - entered Meta+Shift+1: key() returns '!', text returns '', shift and meta modifiers result: Meta+Shift+! (this is wrong I think!) - entered Alt+Shift+1: key() returns '!', text() returns '?', alt and shift modifiers result: Alt+! So it appears on macOS the text() value returned is either the unicode character formed, or a null string, or a "?" depending on what other modifiers are being used at the time. The bottom line is that the existing code seems to work on Linux as expected, seems to work on macOS - most of the time but text() is basically not as advertised. And on Windows it does not seem to work for at least some modifiers on at least some Windows platforms with some key combinations. I would love to see the output of key() and text() and modifiers() and the result stored for all of the test cases shown above on Linux and Windows so that I can begin to understand what it is going on and what commonalities exist so we can rewrite this. The official Qt docs are clearly worthless in this regard. BTW: To make things even worse on macOS - using the apple/command key results in the Ctrl modifier being set - using the option key results in the Alt modifier being set - using the control key results in the Meta modifier being set Thanks, KevinH Last edited by KevinH; 09-06-2021 at 08:09 PM. |
||
09-07-2021, 04:38 AM | #22 |
Guru
Posts: 692
Karma: 2180740
Join Date: Jan 2017
Location: Poland
Device: Misc
|
Debug:
Spoiler:
|
09-07-2021, 04:01 PM | #23 |
Sigil Developer
Posts: 7,645
Karma: 5433388
Join Date: Nov 2009
Device: many
|
Thanks BeckyEbook. Btw, the meta modifier is supposed to be the Windows key.
So it appears that Windows treats Ctrl + Shift plus key differently in just some cases which is just as strange as macOS. Very odd. I am going to have to really think about how to do this that will work for all keyboard layouts. |
09-08-2021, 10:44 AM | #24 |
Sigil Developer
Posts: 7,645
Karma: 5433388
Join Date: Nov 2009
Device: many
|
I have looked and looked at this. The only way that I can find to really do this properly is to know the keyboard layout being used so that we know if the key()/text() generated requires the SHIFT key or not.
For the US this is easy as the following holds true for both the QWERTY and DVORAK keyboards: Code:
shift: ! @ # $ % ^ & * ( ) _ + { } | : " < > ? ~ key: 1 2 3 4 5 6 7 8 9 0 - = [ ] \ ; ' , . / ` So there really is no way to tell when shift is pressed and a key() of '!' is returned (which violates the Qt docs since it should ignore modifiers on US style keyboard layout) and text() returns '1' (which again violates the Qt docs since a '1' was NOT the generated unicode text) that it is okay to fix it without knowing the exact keyboard layout. I did search for how to determine the keyboard layout being used in Qt but according to the search results this can not be done since it happens under the Qt layer. So I think we will have to live with this mess (of needing to fix the ini file by hand) until Qt gets off its butt and actually fixes its code to do what the docs/api says it should do. If all platforms followed the api, then detecting if the shift would be at least theoretically possible. But right now it is broken for Ctrl+Shift on Windows and broken for Meta+Shift on macOS. I have no other data for Linux as of yet other than it seems to handle Ctrl+Shift better than Windows. Last edited by KevinH; 09-08-2021 at 11:21 AM. |
09-08-2021, 11:23 AM | #25 |
Sigil Developer
Posts: 7,645
Karma: 5433388
Join Date: Nov 2009
Device: many
|
A thought ...
if I compare the key() to the text() and they fit into the QWERTY and DVORAK table above, then I assume it would be safe to fix things. If anyone has an intl keyboard, it would be interesting to see a similar table |
09-08-2021, 11:41 AM | #26 | |
Wizard
Posts: 1,542
Karma: 6613969
Join Date: Mar 2013
Location: Rosario - Santa Fe - Argentina
Device: Kindle 4 NT
|
Quote:
Spoiler:
Wouldn't be possible for us to edit the entered shortcut in the Keyboard Shortcut dialog? So, the correct input would be stored in the .ini file. Last edited by RbnJrg; 09-08-2021 at 12:27 PM. |
|
09-08-2021, 05:10 PM | #27 | |
Guru
Posts: 692
Karma: 2180740
Join Date: Jan 2017
Location: Poland
Device: Misc
|
@KevinH:
Perhaps the solution for Windows would be to use the system MAPVK_VK_TO_CHAR check? I quote from the documentation: Quote:
I did a try and I think it should work, but you would need to add a condition (Windows only) that would specify modifiers + unshifted key (if one of the modifiers is Shift) and then display that value in the Preferences window and save it to sigil.ini. Code:
#include <Windows.h> Code:
const auto unshifted_key = MapVirtualKeyA(vk, MAPVK_VK_TO_CHAR); qDebug() << "Unshifted key:" << (char)unshifted_key; Code:
Debug: Original key: ! Debug: Unshifted key: 1 Debug: Full key sequence: "Shift+!" Debug: Original key: @ Debug: Unshifted key: 2 Debug: Key sequence: "Shift+@" Debug: Original key: # Debug: Unshifted key: 3 Debug: Key sequence: "Shift+#" |
|
09-08-2021, 05:20 PM | #28 |
Sigil Developer
Posts: 7,645
Karma: 5433388
Join Date: Nov 2009
Device: many
|
Looks promising! Where is vk getting set to pass it in? Are you using event->key() for it? Or event->nativeScanCode() for it?
|
09-08-2021, 05:50 PM | #29 |
Guru
Posts: 692
Karma: 2180740
Join Date: Jan 2017
Location: Poland
Device: Misc
|
|
09-08-2021, 07:24 PM | #30 |
Sigil Developer
Posts: 7,645
Karma: 5433388
Join Date: Nov 2009
Device: many
|
I will try coding that up tomorrow in master. There are similar virtual key codes for macOS but converting them to a char is not straightforward as the Windows call approach you found.
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
[BUG] - M96 out of memory - [BUG] | Alf77 | Onyx Boox | 5 | 02-05-2015 11:47 AM |
Another bug that I wonder if others have seen | PeterT | Kobo Reader | 16 | 06-08-2013 09:48 PM |
DR800 Help, I've got a bug!! A bug on my screen!! | Franky | iRex | 4 | 06-21-2011 11:45 AM |
Embedded font bug or CSS bug in ADE | JSWolf | ePub | 10 | 06-11-2011 02:34 PM |
PRS-505 bug or eBookLib bug? | porkupan | Sony Reader | 3 | 10-07-2007 10:44 PM |