← Back to team overview

kicad-developers team mailing list archive

Re: Modifier keys for hotkeys

 

On Sun, 2014-12-14 at 20:04 +0100, jp charras wrote:
> Le 14/12/2014 03:02, John Beard a écrit :
> > I'm trying to get a hotkey defined as "Ctrl-Shift-D". Currently, I can
> > make it work easily in GAL mode, but not in the legacy mode.
> > ....
> > The first check will refuse to set the shift modifier unless the keycode
> > is more than 256 (so all normal letters fail this).
> > 
> Yes I know (for the shift key).
> With your changes, many symbols are no more accessible because
> many are accessible only with the shift key down many other only with
> the shift key up.
> 
> For instance keys '0' to '9'  give a different ASCII code when shifted
> and not shifted.
> (Symbols '0' to '9' are accessible on a French keyboard with the shift
> key pressed).
> 
> In other words, the key which generate '5' and '(' is the same on my
> keyboard, therefore
> I can only type 'Shift+5' and '(', but not 'Shift+(' and '5'
> 
> Only "ASCII" keys 'A' to 'Z' (or 'a' to 'z') can be used with the shift
> key up or down.

Right, that makes sense. However, the current approach of rejecting
shift unless the keycode is over 256 means that as well as rejecting
things like Ctrl-Shift-5 (in deference to Ctrl-%) on a GB keyboard
layout, Ctrl-Shift-A is squashed to Ctrl-A (which we can already have
with just "Ctrl" and "A")

Perhaps a change like the attached, which essentially allows the Shift
key to be set when the keycode represents a letter (so needs to be done
after the quirky wx Ctrl-mapping) _or_ the current > 256 check?

    /* Normalize keys code to easily handle keys from Ctrl+A to Ctrl+Z
     * They have an ascii code from 1 to 27 remapped
     * to GR_KB_CTRL + 'A' to GR_KB_CTRL + 'Z'
     */
    if( event.ControlDown() && localkey >= WXK_CONTROL_A && localkey <= WXK_CONTROL_Z )
        localkey += 'A' - 1;

    /* Disallow shift for keys that have two keycodes on them (e.g. number and
     * punctuation keys) leaving only the "letter keys" of A-Z.
     * Then, you can have, e.g. Ctrl-5 and Ctrl-% (GB layout)
     * and Ctrl-( and Ctrl-5 (FR layout).
     * Otherwise, you'd have to have to say Ctrl-Shift-5 on a FR layout
     */
    if( event.ShiftDown() && ( ( localkey >= 'A' && localkey <= 'Z' ) || localkey > 256 ) )
        localkey |= GR_KB_SHIFT;
    if( event.ControlDown() )
        localkey |= GR_KB_CTRL;
    if( event.AltDown() )
        localkey |= GR_KB_ALT;

I have quickly tested with a French layout, and this seems to produce
the correct results according to the current system: I can get Ctrl-(
and Ctrl-5 results with Shift off and on respectively. On a GB keyboard,
you get Ctrl-5 and Ctrl-% respectively.

The attached patch only applies to draw_frame.cpp - if this was done
"for real", you'd have to look at dialog_hotkey_editor, along with
maybe the GAL method in tool_dispatcher, which currently doesn't eat the
shift. A common routine shared by all to convert an EVT_CHAR event into
the KiCad "localkey" could serve all of them, although GAL uses MD_CTRL
instead of GR_KB_CTRL, so maybe not...

Cheers,

John




diff --git a/common/draw_panel.cpp b/common/draw_panel.cpp
index 919fdb1..8e57e3f 100644
--- a/common/draw_panel.cpp
+++ b/common/draw_panel.cpp
@@ -1366,20 +1366,26 @@ void EDA_DRAW_PANEL::OnKeyEvent( wxKeyEvent& event )
         break;
     }
 
-    if( event.ControlDown() )
-        localkey |= GR_KB_CTRL;
-    if( event.AltDown() )
-        localkey |= GR_KB_ALT;
-    if( event.ShiftDown() && (event.GetKeyCode() > 256) )
-        localkey |= GR_KB_SHIFT;
-
     /* Normalize keys code to easily handle keys from Ctrl+A to Ctrl+Z
      * They have an ascii code from 1 to 27 remapped
      * to GR_KB_CTRL + 'A' to GR_KB_CTRL + 'Z'
      */
-    if( (localkey > GR_KB_CTRL) && (localkey <= GR_KB_CTRL+26) )
+    if( event.ControlDown() && localkey >= WXK_CONTROL_A && localkey <= WXK_CONTROL_Z )
         localkey += 'A' - 1;
 
+    /* Disallow shift for keys that have two keycodes on them (e.g. number and
+     * punctuation keys) leaving only the "letter keys" of A-Z.
+     * Then, you can have, e.g. Ctrl-5 and Ctrl-% (GB layout)
+     * and Ctrl-( and Ctrl-5 (FR layout).
+     * Otherwise, you'd have to have to say Ctrl-Shift-5 on a FR layout
+     */
+    if( event.ShiftDown() && ( ( localkey >= 'A' && localkey <= 'Z' ) || localkey > 256 ) )
+        localkey |= GR_KB_SHIFT;
+    if( event.ControlDown() )
+        localkey |= GR_KB_CTRL;
+    if( event.AltDown() )
+        localkey |= GR_KB_ALT;
+
     INSTALL_UNBUFFERED_DC( DC, this );
 
     // Some key commands use the current mouse position: refresh it.

Follow ups

References