How to make keyboard layout independent shortcuts

Michael Jansen kde at michael-jansen.biz
Wed Oct 22 22:24:17 BST 2008


On Wednesday 22 October 2008 10:06:13 Robin Pedersen wrote:
> In kate the default shortcut for code folding (Ctrl+Shift+'+') is
> impossible on US English and several other keyboard layouts, because the
> character '+' is assigned to Shift+'=' on these layouts [1][3].
>
> I tried to get around this problem by using the shortcuts Ctrl+Shift+'['
> and Ctrl+Shift+']' for collapsing and expanding. This was not possible to
> configure in the Configure Shortcuts dialog, because Shift+'[' is actually
> '{', and the shortcut is stored as Ctrl+Shift+'{'. [2]
>
> In an attempt to fix the shortcut dialog, I created a patch that caused it
> so store the shortcut as Ctrl+'{'. This worked fine for this shortcut in
> particular, but caused problems for other key combinations involving
> letters (e.g. Ctrl+Shift+'A').
>
> I didn't realize this until now, and I don't know if this has been
> discussed here before, but this is actually quite a difficult problem. If
> we take a second, and forget about all Qt/KDE specific issues, what would
> be the correct behavior? Should we use Ctrl+Shift+'[' or Ctrl+'{' ? Should
> keyboard shortcuts be defined with respect to _keys_ or _characters_? In
> this case, '{' being the character, which happens to be mapped to the same
> key as '['.
>
> On my particular keyboard layout, there's no difference between the two.
> However, I regularly switch between English and Norwegian layouts. With a
> Norwegian layout Ctrl+Shift+'[' and Ctrl+'{' are actually two different
> things, because '[' is AltGr+'8' and '{' as AltGr+'7'.
>
> If shortcuts where defined with respect to _characters_ instead of _keys_,
> then it's guaranteed that the combination Ctrl+x is possible on any
> keyboard layout as long as:
> 1.1 - The character x is available
> 1.2 - The modifier key Ctrl never changes the character
>
> I think (hope) point 1.2 is universally true. The Shift key, on the other
> hand _does_ change the character, as seen above ('=' becomes '+' and '['
> becomes '{'). That is exactly why we have these problems. The "bug" in Qt
> is that `QKeyEvent::key()` returns the _character_ and not the _key_,
> which I now think is not a bug, but how it must be to behave well with
> different keyboard layouts.
>
> There are some exceptions where the Shift key doesn't change the
> character. One is all the regular letters, because the shortcuts seem to
> be case insensitive, which is why combinations like Ctrl+Shift+'A' does
> work. The function keys are also an exception.
>
> Another issue is that we tend to use shortcuts that are "logical" (e.g.
> '+' and '-' for increase and decrease), to make them easy to remember. On
> a German layout, I think Shift+'+' is actually '*' and Shift+'-' is '_',
> which doesn't have the same meaning as '+' and '-'. Many such logical
> "errors" may arise when shortcuts are defined without having other layouts
> in mind.
>
> My suggestion is to change the shortcuts dialog, and default shortcuts, so
> that all shortcuts are defined with respect to a _character_, and the only
> modifiers allowed are those that are guaranteed not to change the
> characters. This means:
> 2.1 - The modifier Shift is only allowed in combination with regular
> letters and function keys
> 2.2 - Ctrl and Alt are allowed with all characters
> 2.3 - The character is whatever is returned by `QKeyEvent::key()`

I had that on my todo list. Until now the only conclusion i had was to remove 
the *extra* code in shortcutseditor to handle the shift key as a modifier. Qt 
doesn't do that and explicitly states it's a bad idea. I'm currently 
investigating why that code is there. 

By the way you forgot meta( or super? ). But i would not limit that. Whatever 
qt supports as modifier is allowed.

> I created a second patch that allows Shift to be used as a modifier only
> with certain characters [2]. What do you think?

I will have a look. But it could take some time. So if anyone else steps up.

> [1] https://bugs.kde.org/show_bug.cgi?id=124672 Bug 124672: impossible
> default shortcut for code folding
> [2] https://bugs.kde.org/show_bug.cgi?id=173246 Bug 173246: Configure
> Shortcuts dialog doesn't work with some Ctrl+Shift combinations
> [3] http://en.wikipedia.org/wiki/Keyboard_layout


-- 
Michael Jansen

http://www.michael-jansen.biz




More information about the kde-core-devel mailing list